Documentation ¶
Index ¶
- type Client
- func (c *Client) Close()
- func (c *Client) DefaultOnConnectFunc(cli mqtt.Client)
- func (c *Client) OnConnectListener(fun mqtt.OnConnectHandler) (mc *Client)
- func (c *Client) OnConnectLostListener(fun mqtt.ConnectionLostHandler) (mc *Client)
- func (c *Client) Publish(topic string, qos QosType, payload any) error
- func (c *Client) RegisterConsumers(consumers []*Consumer)
- func (c *Client) StartAndConnect() (err error)
- func (c *Client) Subscribe(topic string, qos QosType, callback mqtt.MessageHandler) error
- func (c *Client) UnSubscribe(topics ...string) error
- type Config
- type Consumer
- type QosType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Ops *mqtt.ClientOptions Timeout time.Duration // connection、subscribe、publish Timeout time, default 10s Mqtt mqtt.Client Topics []string SubFunc smap.Map[string, mqtt.MessageHandler] // key:topic#qos, value: callback func // contains filtered or unexported fields }
func (*Client) DefaultOnConnectFunc ¶
func (c *Client) DefaultOnConnectFunc(cli mqtt.Client)
func (*Client) OnConnectListener ¶
OnConnectListener 2、设置链接监听
func (*Client) OnConnectLostListener ¶
OnConnectLostListener 3、设置断开链接监听
func (*Client) RegisterConsumers ¶
RegisterConsumers 批量注册消费者
func (*Client) StartAndConnect ¶
StartAndConnect 4、真实创建Client并连接mqtt
func (*Client) UnSubscribe ¶
UnSubscribe 取消订阅topic
type Config ¶
type Config struct { Broker string `json:"broker" yaml:"broker" toml:"broker"` TcpPort int `json:"tcp_port" yaml:"tcp_port" toml:"tcp_port"` ClientId string `json:"client_id" yaml:"client_id" toml:"client_id"` Uname string `json:"uname" yaml:"uname" toml:"uname"` Password string `json:"password" yaml:"password" toml:"password"` KeepAlive xtime.Duration `json:"keep_alive" yaml:"keep_alive" toml:"keep_alive"` // 单位秒 Timeout xtime.Duration `json:"Timeout" yaml:"Timeout" toml:"Timeout"` CleanSession bool `json:"clean_session" yaml:"clean_session" toml:"clean_session"` }
Click to show internal directories.
Click to hide internal directories.