1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/plugins/broker/mqtt
Asim Aslam 62801c3d68 update
2021-10-13 13:31:23 +01:00
..
go.mod update 2021-10-13 13:31:23 +01:00
go.sum update 2021-10-13 13:31:23 +01:00
mqtt_handler.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
mqtt_mock.go add all the plugins 2020-12-26 15:32:45 +00:00
mqtt_test.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
mqtt.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
README.md go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00

MQTT Broker

The MQTT broker is useful for IoT based applications

Usage

Drop in import

import _ "github.com/asim/go-micro/plugins/broker/mqtt"

Flag on command line

go run main.go --broker=mqtt

Alternatively use directly

import (
	"go-micro.dev/v4"
	"github.com/asim/go-micro/plugins/broker/mqtt"
)


func main() {
	service := micro.NewService(
		micro.Name("my.service"),
		micro.Broker(mqtt.NewBroker()),
	)
}

Encoding

Because MQTT does not support message headers the plugin encodes messages using JSON. If you prefer to send and receive the mqtt payload uninterpreted use the noop codec.

Example

import (
    "github.com/micro/broker"
    "github.com/micro/broker/codec/noop"
    "github.com/asim/go-micro/plugins/broker/mqtt"
)

b := mqtt.NewBroker(
    broker.Codec(noop.NewCodec()),
)