Coder Social home page Coder Social logo

mqtt's Introduction

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:

Features

  • 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 mqtt.fluux.io (on ports 1883 for cleartext and 8883 for TLS).

Here is example code for a simple client:

package main

import (
	"log"
	"time"

	"gosrc.io/mqtt"
)

func main() {
	client := mqtt.NewClient("tls://mqtt.fluux.io:8883")
	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) {
		log.Println("Connected")
		name := "/mremond/test-topic-1"
		topic := mqtt.Topic{Name: name, QOS: 0}
		c.Subscribe(topic)
	}

	cm := mqtt.NewClientManager(client, postConnect)
	cm.Start()

	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:
    /usr/local/etc/mosquitto/mosquitto.conf

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 127.0.0.1 -v -t 'test/topic'

You can test publish with:

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

mqtt's People

Contributors

ardan-bkennedy avatar mremond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqtt's Issues

TLS support

We should likely use URL scheme to define connection to server: tcp:// tls://

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.