Documentation
¶
Index ¶
- func SetMqttSetOnConnectHandler(f func(cli mqtt.Client))
- type EmqGetClientsData
- type EmqGetClientsMeta
- type EmqGetClientsResp
- type EmqResp
- type GetOnlineClientsFilter
- type MqttClient
- func (m MqttClient) GetClientSub(ctx context.Context, clientID string) ([]string, error)
- func (m MqttClient) GetOnlineClients(ctx context.Context, f GetOnlineClientsFilter, page *PageInfo) ([]*devices.DevConn, int64, error)
- func (m MqttClient) Publish(topic string, qos byte, retained bool, payload interface{}) error
- func (m MqttClient) SetClientMutSub(ctx context.Context, clientID string, topics []string, qos int) error
- func (m MqttClient) SetClientMutUnSub(ctx context.Context, clientID string, topics []string) error
- func (m MqttClient) Subscribe(cli mqtt.Client, topic string, qos byte, callback mqtt.MessageHandler) error
- type MutSubReq
- type OnlineClientsInfo
- type PageInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EmqGetClientsData ¶ added in v1.4.36
type EmqGetClientsData struct {
CreatedAt time.Time `json:"created_at"`
Connected bool `json:"connected"`
IpAddress string `json:"ip_address"`
ProtoVer int `json:"proto_ver"`
Mountpoint string `json:"mountpoint"`
ProtoName string `json:"proto_name"`
Port int `json:"port"`
ConnectedAt time.Time `json:"connected_at"`
ExpiryInterval int `json:"expiry_interval"`
Username *string `json:"username"`
Keepalive int `json:"keepalive"`
Clientid string `json:"clientid"`
}
// https://www.emqx.io/docs/zh/v5.5/admin/api-docs.html#tag/Clients/paths/~1clients~1%7Bclientid%7D/get
func (m MqttClient) CheckIsOnline(ctx context.Context, clientID string) (bool, error) {
if m.cfg.OpenApi == nil {
return false, errors.System.AddMsg("没有配置秘钥")
}
oa := m.cfg.OpenApi
greq := gorequest.New().Retry(1, time.Second*2)
greq.SetBasicAuth(oa.ApiKey, oa.SecretKey)
var ret EmqResp
resp, rets, errs := greq.Get(fmt.Sprintf("%s/api/v5/clients/%s", oa.Host, url.QueryEscape(clientID))).EndStruct(&ret)
if errs != nil {
return false, errors.System.AddDetail(errs)
}
if resp.StatusCode != http.StatusOK {
return false, errors.System.AddDetail(string(rets))
}
if ret.Code == "" {
return true, nil
}
return false, nil
}
type EmqGetClientsMeta ¶ added in v1.4.36
type EmqGetClientsResp ¶
type EmqGetClientsResp struct {
Data []EmqGetClientsData `json:"data"`
Meta EmqGetClientsMeta `json:"meta"`
}
type GetOnlineClientsFilter ¶
type GetOnlineClientsFilter struct {
UserName string
}
type MqttClient ¶
type MqttClient struct {
// contains filtered or unexported fields
}
func NewMqttClient ¶
func NewMqttClient(conf *conf.MqttConf) (mcs *MqttClient, err error)
func (MqttClient) GetClientSub ¶
func (MqttClient) GetOnlineClients ¶
func (m MqttClient) GetOnlineClients(ctx context.Context, f GetOnlineClientsFilter, page *PageInfo) ([]*devices.DevConn, int64, error)
func (MqttClient) Publish ¶
func (m MqttClient) Publish(topic string, qos byte, retained bool, payload interface{}) error
func (MqttClient) SetClientMutSub ¶
func (MqttClient) SetClientMutUnSub ¶
func (MqttClient) Subscribe ¶
func (m MqttClient) Subscribe(cli mqtt.Client, topic string, qos byte, callback mqtt.MessageHandler) error
type OnlineClientsInfo ¶
Click to show internal directories.
Click to hide internal directories.