This commit is contained in:
PandaX
2023-11-08 09:21:08 +08:00
parent 6bdc4b1dd6
commit 85c5741b90
3 changed files with 10 additions and 8 deletions

View File

@@ -61,7 +61,8 @@ taos:
config: "" config: ""
mqtt: mqtt:
broker: http://127.0.0.1:18083/api broker: tcp://127.0.0.1:1883
httpBroker: http://127.0.0.1:18083/api
qos: 1 qos: 1
username: dbda318b31319d49 username: dbda318b31319d49
password: wwqPbYu9BCsIFgW3m0aICmRrvxUHcIi44AQuG24wQARE password: wwqPbYu9BCsIFgW3m0aICmRrvxUHcIi44AQuG24wQARE

View File

@@ -20,9 +20,9 @@ const SubscribeTopicsInfo string = "subscribe"
func GetEmqInfo(infoType string) ([]map[string]interface{}, error) { func GetEmqInfo(infoType string) ([]map[string]interface{}, error) {
var url string var url string
if infoType == ClientsInfo { if infoType == ClientsInfo {
url = fmt.Sprintf("%s/v5/clients?_page=1&_limit=100000", global.Conf.Mqtt.Broker) url = fmt.Sprintf("%s/v5/clients?_page=1&_limit=100000", global.Conf.Mqtt.HttpBroker)
} else if infoType == SubscribeTopicsInfo { } else if infoType == SubscribeTopicsInfo {
url = fmt.Sprintf("%s/v5/subscriptions?_page=1&_limit=100000", global.Conf.Mqtt.Broker) url = fmt.Sprintf("%s/v5/subscriptions?_page=1&_limit=100000", global.Conf.Mqtt.HttpBroker)
} else { } else {
return nil, errors.New("invalid infoType") return nil, errors.New("invalid infoType")
} }
@@ -67,7 +67,7 @@ func Publish(topic, clientId string, payload interface{}) error {
return errors.New("未获取到MQTT连接") return errors.New("未获取到MQTT连接")
} }
global.Log.Debugf("send data to clientId: %s, topic:%s, payload: %v", clientId, topic, payload) global.Log.Debugf("send data to clientId: %s, topic:%s, payload: %v", clientId, topic, payload)
url := fmt.Sprintf("%s/v5/publish", global.Conf.Mqtt.Broker) url := fmt.Sprintf("%s/v5/publish", global.Conf.Mqtt.HttpBroker)
pubData := map[string]interface{}{ pubData := map[string]interface{}{
"topic": topic, "topic": topic,
"payload": payload, "payload": payload,

View File

@@ -1,8 +1,9 @@
package config package config
type Mqtt struct { type Mqtt struct {
Broker string `mapstructure:"broker" json:"broker" yaml:"broker"` Broker string `mapstructure:"broker" json:"broker" yaml:"broker"`
Qos int `mapstructure:"qos" json:"qos" yaml:"qos"` HttpBroker string `mapstructure:"httpBroker" json:"httpBroker" yaml:"httpBroker"`
Username string `mapstructure:"username" json:"username" yaml:"username"` Qos int `mapstructure:"qos" json:"qos" yaml:"qos"`
Password string `mapstructure:"password" json:"password" yaml:"password"` Username string `mapstructure:"username" json:"username" yaml:"username"`
Password string `mapstructure:"password" json:"password" yaml:"password"`
} }