emq5

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 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 added in v1.2.43

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

Publish 发布消息

func (*MQTT) Use added in v1.2.42

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 added in v1.5.2

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