mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【fix】修复设备rpc调用,仅支持mqtt
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"pandax/iothub/client/mqttclient"
|
"pandax/iothub/client/mqttclient"
|
||||||
"pandax/pkg/rule_engine/message"
|
"pandax/pkg/rule_engine/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rpcRequestNode struct {
|
type rpcRequestNode struct {
|
||||||
bareNode
|
bareNode
|
||||||
Timeout int `json:"timeout"`
|
RequestId int `json:"requestId"`
|
||||||
Payload mqttclient.RpcPayload `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type rpcRequestNodeFactory struct{}
|
type rpcRequestNodeFactory struct{}
|
||||||
@@ -26,10 +26,20 @@ func (f rpcRequestNodeFactory) Create(id string, meta Metadata) (Node, error) {
|
|||||||
func (n *rpcRequestNode) Handle(msg *message.Message) error {
|
func (n *rpcRequestNode) Handle(msg *message.Message) error {
|
||||||
successLableNode := n.GetLinkedNode("Success")
|
successLableNode := n.GetLinkedNode("Success")
|
||||||
failureLableNode := n.GetLinkedNode("Failure")
|
failureLableNode := n.GetLinkedNode("Failure")
|
||||||
|
RequestId := n.RequestId
|
||||||
var rpc = &mqttclient.RpcRequest{Client: mqttclient.MqttClient, Mode: "double", Timeout: n.Timeout}
|
if RequestId == 0 {
|
||||||
|
RequestId = int(msg.Metadata.GetValue("requestId").(float64))
|
||||||
|
}
|
||||||
|
if msg.Msg.GetValue("method") == nil || msg.Msg.GetValue("params") == nil {
|
||||||
|
return errors.New("请求响应格式不正确")
|
||||||
|
}
|
||||||
|
var datas = mqttclient.RpcPayload{
|
||||||
|
Method: msg.Msg.GetValue("method").(string),
|
||||||
|
Params: msg.Msg.GetValue("params"),
|
||||||
|
}
|
||||||
|
var rpc = &mqttclient.RpcRequest{Client: mqttclient.MqttClient, Mode: "single"}
|
||||||
rpc.GetRequestId()
|
rpc.GetRequestId()
|
||||||
err := rpc.RespondTpc(n.Payload)
|
err := rpc.RespondTpc(datas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if failureLableNode != nil {
|
if failureLableNode != nil {
|
||||||
return failureLableNode.Handle(msg)
|
return failureLableNode.Handle(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user