mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
优化
This commit is contained in:
@@ -16,7 +16,9 @@ const (
|
||||
TelemetryGatewayTopic = "v1/gateway/telemetry"
|
||||
ConnectGatewayTopic = "v1/gateway/connect"
|
||||
|
||||
RpcReq = `v1/devices/me/rpc/request/(.*?)$`
|
||||
RpcReq = `v1/devices/me/rpc/(.*?)/(.*?)$`
|
||||
|
||||
EventReq = `v1/devices/event/(.*?)$`
|
||||
)
|
||||
|
||||
var IotHubTopic = NewIotHubTopic()
|
||||
@@ -39,8 +41,11 @@ func (iht TopicMeg) GetMessageType(topic string) string {
|
||||
if meg, ok := iht[topic]; ok {
|
||||
return meg
|
||||
}
|
||||
if strings.Contains(topic, "v1/devices/me/rpc/request") {
|
||||
if strings.Contains(topic, "v1/devices/me/rpc/request") || strings.Contains(topic, "v1/devices/me/rpc/response") {
|
||||
return message.RpcRequestFromDevice
|
||||
}
|
||||
if strings.Contains(topic, "v1/devices/event") {
|
||||
return message.UpEventMes
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func (s *HookGrpcService) OnClientConnected(ctx context.Context, in *exhook2.Cli
|
||||
}
|
||||
//添加连接ID
|
||||
mqttclient.Session.Store(etoken.DeviceId, in.Clientinfo.Clientid)
|
||||
data := netbase.CreateConnectionInfo(message.ConnectMes, "mqtt", in.Clientinfo.Clientid, in.Clientinfo.Peerhost, etoken)
|
||||
data := netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("设备%s通过MQTT协议连接", etoken.Name), etoken)
|
||||
go s.HookService.Queue.Queue(data)
|
||||
return &exhook2.EmptySuccess{}, nil
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (s *HookGrpcService) OnClientDisconnected(ctx context.Context, in *exhook2.
|
||||
}
|
||||
//删除连接ID
|
||||
mqttclient.Session.Delete(etoken.DeviceId)
|
||||
data := netbase.CreateConnectionInfo(message.DisConnectMes, "mqtt", in.Clientinfo.Clientid, in.Clientinfo.Peerhost, etoken)
|
||||
data := netbase.CreateEvent(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
go s.HookService.Queue.Queue(data)
|
||||
return &exhook2.EmptySuccess{}, nil
|
||||
}
|
||||
@@ -243,10 +243,10 @@ func (s *HookGrpcService) OnMessagePublish(ctx context.Context, in *exhook2.Mess
|
||||
if in.Message.Topic == ConnectGatewayTopic {
|
||||
if val, ok := value.(string); ok {
|
||||
if val == "online" {
|
||||
data = netbase.CreateConnectionInfo(message.ConnectMes, "mqtt", in.Message.From, in.Message.Headers["peerhost"], auth)
|
||||
data = netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("子设备%s通过网关连接", etoken.Name), auth)
|
||||
}
|
||||
if val == "offline" {
|
||||
data = netbase.CreateConnectionInfo(message.DisConnectMes, "mqtt", in.Message.From, in.Message.Headers["peerhost"], auth)
|
||||
data = netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("子设备设备%s通过网关连接", etoken.Name), auth)
|
||||
}
|
||||
// 子设备发送到队列里
|
||||
go s.HookService.Queue.Queue(data)
|
||||
@@ -281,6 +281,10 @@ func (s *HookGrpcService) OnMessagePublish(ctx context.Context, in *exhook2.Mess
|
||||
// 获取请求id
|
||||
id := netbase.GetRequestIdFromTopic(RpcReq, in.Message.Topic)
|
||||
data.RequestId = id
|
||||
case message.UpEventMes:
|
||||
data.Type = message.UpEventMes
|
||||
identifier := netbase.GetEventFromTopic(EventReq, in.Message.Topic)
|
||||
data.Identifier = identifier
|
||||
}
|
||||
//将数据放到队列中
|
||||
go s.HookService.Queue.Queue(data)
|
||||
|
||||
Reference in New Issue
Block a user