publish.go 689 Bytes
Newer Older
Lei Li's avatar
Lei Li committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package plugin

import (
	"context"

	"agent/cmd/agent/global"
	"linkfog.com/pluginx/pluginrpc"
	"linkfog.com/public/lib/l"
)

func chatWithPlugin(client *pluginrpc.PluginGrpcClient, pluginName string, topicName string) {
	req := pluginrpc.NewReq(AgentSelfPlugin, pluginName, "", []byte{})
	chatClient, err := client.Chat(context.Background(), req)
	if err != nil {
		l.Error("ChatClient err:", err)
		return
	}
	for {
		res, err := chatClient.Recv()
		if err != nil {
			l.Error("ChatClient receive err:", err)
			return
		}
		l.Infof("receive message: %v", res)
		global.HostInfoTail.MQTTInfo.PublishChan <- &global.Message{
			Key:     topicName,
			Payload: string(res.Data),
		}
	}
}