Native Go MQTT Library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples TLS support Feb 9, 2019
.gitignore Ignore coverage.txt file Jan 8, 2018 Add CoC and contribution guide Jan 21, 2019 Add CoC and contribution guide Jan 21, 2019
LICENSE Refactor library to release it as open source in project Jan 2, 2018 TLS support Feb 9, 2019 Update roadmap Feb 9, 2019
backoff.go Migrate to Jan 24, 2019
backoff_test.go Migrate to Jan 24, 2019
client.go TLS support Feb 9, 2019
client_test.go Update test to support new address scheme Feb 9, 2019
codeship-services.yml Add Codeship / Codecov support Jan 5, 2018
codeship-steps.yml Fix a few go vet / other linter issues (#8) Jan 8, 2018
codeship.env.encrypted update codecov tokens Jan 24, 2019
control_packets.go Keep track of client subscription state Feb 8, 2019
encoding.go Better error management Feb 7, 2019
go.mod Add support for Go modules Feb 7, 2019
keepalive.go Migrate to Jan 24, 2019

Native Go MQTT Library

Codeship Status for FluuxIO/mqtt GoDoc GoReportCard codecov

Fluux MQTT is a MQTT v3.1.1 client library written in Go.

The library has been tested with the following MQTT servers:


  • MQTT v3.1.1, QOS 0
  • Client manager to support auto-reconnect with exponential backoff.
  • TLS Support

Short term tasks

Implement support for QOS 1 and 2 (with storage backend interface and default backends).

Running tests

You can launch unit tests with:

go test ./...

Testing with Fluux public MQTT server

We encourage you to experiment and test on a public Fluux test server. It is available on (on ports 1883 for cleartext and 8883 for TLS).

Here is example code for a simple client:

package main

import (


func main() {
	client := mqtt.NewClient("tls://")
	client.ClientID = "MQTT-Sub"
	log.Printf("Connecting on: %s\n", client.Address)

	messages := make(chan mqtt.Message)
	client.Messages = messages

	postConnect := func(c *mqtt.Client) {
		name := "/mremond/test-topic-1"
		topic := mqtt.Topic{Name: name, QOS: 0}

	cm := mqtt.NewClientManager(client, postConnect)

	for m := range messages {
		log.Printf("Received message from MQTT server on topic %s: %+v\n", m.Topic, m.Payload)

Setting Mosquitto on OSX for testing

If you want to test Go MQTT library locally, you can install Mosquitto.

Mosquitto can be installed from homebrew:

brew install mosquitto
mosquitto has been installed with a default configuration file.
You can make changes to the configuration by editing:

To have launchd start mosquitto at login:
  ln -sfv /usr/local/opt/mosquitto/*.plist ~/Library/LaunchAgents
Then to load mosquitto now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
Or, if you don't want/need launchctl, you can just run:
  mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf

Default config file can be customized in /usr/local/etc/mosquitto/mosquitto.conf. However, default config file should be ok for testing

You can launch Mosquitto broker with command:

/usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf

The following command can be use to subscribe a client:

mosquitto_sub -v -t 'test/topic'

You can publish a payload payload on a topic with:

mosquitto_pub -t "test/topic" -m "message payload" -q 1

Setting Mosquitto for testing on Windows 10

After you have install official Mosquitto build from main site, you can run the broker with command:

.\mosquitto.exe -v -c .\mosquitto.conf

You can subscribe with:

.\mosquitto_sub.exe -h -v -t 'test/topic'

You can test publish with:

.\mosquitto_pub.exe -h -t "test/topic" -m "message payload" -q 1