Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

The mqtt-nats bridge enables MQTT devices to publish and subscribe to the NATS communication system.

Project status

Currently under development.

Getting started

Obtaining and running the bridge

You can install the binary using go get

go get

If you just start using the command mqtt-nats it will create an MQTT server on port 1883 that will attempt to connect to a NATS server using the default URL "nats://". Use:

mqtt-nats -help

to get a list of all configurable options.

Run the tests

The test utilities within this code-base are tagged with the special build tag "citest". This flag is required for most of the tests to build and run. I.e. to run all tests, use:

go test -tags citest ./...

Current limitations:

  • Only MQTT 3.1.1 is supported
  • Only QoS levels 0 (at most once) and 1 (at least once)
  • The bridge has no way of knowing when new subscriptions are added in the NATS network and hence, cannot send retained messages in response to such subscriptions.

Solutions and workarounds

QoS level 1 is accomplished using the NATS reply-to subject.

When the bridge receives an MQTT publish with QoS = 1 from a client, it forwards that to NATS with a reply-to subject. A PUBACK is sent to the MQTT client when the reply arrives. Similarly, if an MQTT client subscribes using desired QoS = 1, then a NATS publish with a reply-to will be considered in need of a PUBACK from the MQTT client.

Retain request from NATS

An MQTT client that subscribes to a topic will immediately receive all retained messages for that topic. The same is not true for a NATS client simply because the bridge has no way of knowing when a NATS client subscribes to a topic. To mitigate this, the bridge subscribes to a specific "retained request" topic (configurable option). A NATS client that publishes to this topic with a subscription string as the payload and a reply-to inbox, will get a JSON encoded reply containing all messages that matches the subcription string.


The mqtt-nats bridge enables MQTT devices to publish and subscribe to the NATS communication system.







No releases published


No packages published