Documentation ¶
Index ¶
- type MqttClient
- func (p *MqttClient) Publish(topic string, qos byte, data []byte) error
- func (p *MqttClient) PublishTimeout(topic string, qos byte, data []byte, timeout time.Duration) (bool, error)
- func (p *MqttClient) Subscribe(topic string, qos byte, subCallback mqtt.MessageHandler) error
- func (p *MqttClient) SubscribeMultiple(filters map[string]byte, subCallback mqtt.MessageHandler) error
- func (p *MqttClient) Unsubscribe(topics []string) error
- type MqttConf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MqttClient ¶
type MqttClient struct {
// contains filtered or unexported fields
}
func NewMqtt ¶
func NewMqtt(config *MqttConf) (*MqttClient, error)
func (*MqttClient) Publish ¶
func (p *MqttClient) Publish(topic string, qos byte, data []byte) error
func (*MqttClient) PublishTimeout ¶
func (*MqttClient) Subscribe ¶
func (p *MqttClient) Subscribe(topic string, qos byte, subCallback mqtt.MessageHandler) error
订阅单个主题
func (*MqttClient) SubscribeMultiple ¶
func (p *MqttClient) SubscribeMultiple(filters map[string]byte, subCallback mqtt.MessageHandler) error
订阅多个主题,同一个回调处理函数
func (*MqttClient) Unsubscribe ¶
func (p *MqttClient) Unsubscribe(topics []string) error
type MqttConf ¶
type MqttConf struct { Uri string // 格式"tcp://[ip]:[port]" Username string // 用户名 Password string // 密码 ConnectedFunc mqtt.OnConnectHandler // 连接成功回调函数 LostConnFunc mqtt.ConnectionLostHandler // 断开连接回调函数 DefaultPublishFunc mqtt.MessageHandler // 默认订阅回调函数 ClientId string // 客户端id(客户端唯一标识) AutoAckDisabled bool // 禁用自动ack AutoReconnect bool ConnectTimeout time.Duration }
func DefaultMqttConf ¶
func DefaultMqttConf() *MqttConf
Click to show internal directories.
Click to hide internal directories.