starter

package module
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 4 Imported by: 0

README

yomo-rcvr-mqtt-starter

支持为YoMo-Edge进行Receiver的开发,在通过MQTT Broker对IoT发送的消息进行消费时,可以利用本组件方便对消息进行处理。

使用外部Broker
1. 使用场景

yomo-rcvr-mqtt-starter-v0.1c

2. 例子代码

执行Sub(func(topic string, payload []byte){})

func CreateServer(addr string, writer io.Writer) {
	starter.NewBroker(&starter.BrokerConf{
		Addr:   addr,
		Topics: []string{"test"},
	}).Sub(func(topic string, payload []byte) {
		_, _ = writer.Write(starter.Pack(payload))
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnd added in v0.1.2

func GetEnd() byte

func Pack added in v0.1.2

func Pack(payload []byte) []byte

func RemoveEnd added in v0.1.10

func RemoveEnd(buf []byte) []byte

func Tail added in v0.1.2

func Tail() []byte

Types

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

func NewBroker

func NewBroker(conf *BrokerConf) Broker

func (Broker) Sub added in v0.1.2

func (b Broker) Sub(handle func(topic string, payload []byte))

type BrokerConf

type BrokerConf struct {
	Addr           string
	Topics         []string
	Username       string
	Password       string
	ConnectTimeout int

	FailureTimes int
}
var DefaultConfig *BrokerConf = &BrokerConf{
	Addr:           "tcp://localhost:1883",
	Topics:         []string{"test"},
	Username:       "admin",
	Password:       "public",
	ConnectTimeout: 0,

	FailureTimes: 5,
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL