1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-03-17 20:28:06 +02:00
Jerry 93ba8cd0df
continue fix pre version go get bug that unknown v3.5.1 (#2188)
* 1.fix plugins go get bug.
2.update all mode.
3.add tidy tools

* continue fix pre version go get bug that unknown v3.5.1
2021-06-30 09:24:00 +01:00
..
2021-06-30 07:21:03 +01:00
2021-01-20 21:01:10 +00:00
2020-12-26 15:32:45 +00:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00: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 (
	"github.com/asim/go-micro/v3"
	"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()),
)