clients

package
v1.5.73 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetMqttSetOnConnectHandler

func SetMqttSetOnConnectHandler(f func(cli mqtt.Client))

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 EmqGetClientsMeta struct {
	Count int64 `json:"count"`
	Limit int   `json:"limit"`
	Page  int   `json:"page"`
}

type EmqGetClientsResp

type EmqGetClientsResp struct {
	Data []EmqGetClientsData `json:"data"`
	Meta EmqGetClientsMeta   `json:"meta"`
}

type EmqResp

type EmqResp struct {
	Code    string `json:"code"` //如果不在线返回: CLIENTID_NOT_FOUND
	Message string `json:"message"`
}

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 (m MqttClient) GetClientSub(ctx context.Context, clientID string) ([]string, error)

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 (m MqttClient) SetClientMutSub(ctx context.Context, clientID string, topics []string, qos int) error

func (MqttClient) SetClientMutUnSub

func (m MqttClient) SetClientMutUnSub(ctx context.Context, clientID string, topics []string) error

func (MqttClient) Subscribe

func (m MqttClient) Subscribe(cli mqtt.Client, topic string, qos byte, callback mqtt.MessageHandler) error

type MutSubReq

type MutSubReq struct {
	Topic string `json:"topic"`
	Qos   int    `json:"qos"`
	Nl    int    `json:"nl"`
	Rap   int    `json:"rap"`
	Rh    int    `json:"rh"`
}

type OnlineClientsInfo

type OnlineClientsInfo struct {
	ClientID    string
	UserName    string
	ConnectedAt time.Time
}

type PageInfo

type PageInfo struct {
	Page int64 `json:"page" form:"page"`         // 页码
	Size int64 `json:"pageSize" form:"pageSize"` // 每页大小
}

Jump to

Keyboard shortcuts

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