emq5

package module
v0.0.0-...-2e3374b Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	*Options
	Topic      string
	TopicLen   int
	Wildcard   bool
	Shared     bool
	ShareGroup string
	Qos        int
}

func (*Engine) Register

func (e *Engine) Register(url string, handler Handler)

Register 注册方法到前缀树

func (*Engine) WithShare

func (e *Engine) WithShare(group string)

WithShare 注册共享订阅

type Handler

type Handler func(ctx context.Context, publish *paho.Publish) interface{}

type MQTT

type MQTT struct {
	*Options
	// contains filtered or unexported fields
}

func GetConnect

func GetConnect() *MQTT

func InitClient

func InitClient(opt *Options) *MQTT

InitClient 请异步执行该方法,确保不会因为连接失败阻塞进程

func (*MQTT) Connect

func (m *MQTT) Connect() error

func (*MQTT) Publish

func (m *MQTT) Publish(ctx context.Context, publish *paho.Publish) (*paho.PublishResponse, error)

Publish 发布消息

func (*MQTT) Use

func (m *MQTT) Use(middlewares ...Middleware)

Use 注册中间件

type Middleware

type Middleware func(Handler) Handler

func Chain

func Chain(m ...Middleware) Middleware

Chain returns a Middleware that specifies the chained handler for endpoint.

type Options

type Options struct {
	Addr           string
	ID             string
	Username       string
	Password       string
	KeepAlive      time.Duration
	SetPingTimeout time.Duration
	Engine         []*Engine

	OnServerDisconnect func(*paho.Disconnect)
	OnClientError      func(error)
	Logger             logger.Interface
	// contains filtered or unexported fields
}

func Default

func Default(addr, id, username, password string) *Options

func (*Options) NewEngine

func (o *Options) NewEngine(topic string, wildcard bool, qos int) (eng *Engine)

func (*Options) NewSingleEngine

func (o *Options) NewSingleEngine(topic string, wildcard bool, qos int, handler Handler)

func (*Options) SetLogger

func (o *Options) SetLogger(logger logger.Logger)

SetLogger 设置日志

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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