在 VOLTTRON 中,如何使用 VIP 使代理跨远程平台实例交谈? [英] In VOLTTRON, how to use VIP to get agents talk across remote platform instances?

查看:67
本文介绍了在 VOLTTRON 中,如何使用 VIP 使代理跨远程平台实例交谈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让代理跨远程平台实例相互交谈.例如,在机器 1 (192.168.1.10) 上运行的代理 1 想要与机器 2 (192.168.1.11) 上运行的代理 2 对话,并使用 VOLTTRON 环境.我认为 VOLTTRON 互连协议 (VIP) 可能是实现这一点的不错选择,但如何设置呢?谁能给我举个例子?

I am trying to get agents talk to each other across remote platform instances. For example, Agent1 running on machine1 (192.168.1.10) wants to talk to Agent2 running on machine2 (192.168.1.11) with VOLTTRON environment. I think VOLTTRON Interconnect Protocol (VIP) may be a good choice to implement that, but how to set it? Can anyone show me an example?

谢谢.

推荐答案

您是想让两个代理直接对话还是目标是让他们将消息发布到远程总线以供其他代理查看?如果是后者,你可以在 ForwardHistorian 中看到一个例子:https://github.com/VOLTTRON/volttron/blob/develop/services/core/ForwardHistorian/forwarder/agent.py

Are you trying to have two agents talk directly or is the goal for them to publish messages to a remote bus for the other agent to see? If it's the latter, you can see an example in the ForwardHistorian: https://github.com/VOLTTRON/volttron/blob/develop/services/core/ForwardHistorian/forwarder/agent.py

默认情况下,代理可以与本地消息总线通信,为了与远程消息总线通信,他们需要设置此连接(其中destination_vip"是远程 VOLTTRON 的 vip 地址,包括服务器密钥):

By default, agents can talk to their local message bus, in order to talk to a remote one they need to setup this connection (where "destination_vip" is the vip address of the remote VOLTTRON including the serverkey):

    agent = Agent(address=destination_vip)
    event = gevent.event.Event()
    agent.core.onstart.connect(lambda *a, **kw: event.set(), event)
    gevent.spawn(agent.core.run)
    event.wait()

然后他们可以使用它来发布或订阅该总线:

Then later they can use it to publish or subscribe to that bus:

self._target_platform.vip.pubsub.publish(peer='pubsub',
                                    topic="MyTopic",
                                    message="Some message").get()

使用这些方法,代理可以发布和订阅远程消息总线,并以与本地总线相同的方式与其交互.

Using these methods agents can publish and subscribe to a remote message bus and interact with it in the same way they could with their local bus.

如果您正在寻找如何直接调用另一个代理,那么与 ActuatorAgent 交互的 SchedulerExample 提供了一个示例:https://github.com/VOLTTRON/volttron/blob/develop/examples/SchedulerExample/schedule_example/agent.py

If you are looking for how to call another agent directly, then the SchedulerExample interacting with the ActuatorAgent provides an example: https://github.com/VOLTTRON/volttron/blob/develop/examples/SchedulerExample/schedule_example/agent.py

调用与上面的 pub/sub 示例类似,只是它使用了 rpc 子系统.调用代理使用目标代理的 VIP 身份、它要调用的方法和参数.ActuatorAgent 有一个设置 vip 标识,使其更容易调用,并且它在set_point"方法上有@RPC.export"装饰器.

The call is similar to the above pub/sub example except that it uses the rpc subsystem. The calling agent uses the target agent's VIP identity, the method it wants to call, and the parameters. The ActuatorAgent has a set vip identity making it easier to call and it has the "@RPC.export" decorator over the "set_point" method.

            result =  self._target_platform.vip.rpc.call(
                                   'platform.actuator', 
                                   'set_point',
                                   agent_id, 
                                   'campus/building/unit3/some_point',
                                   '0.0').get(timeout=10)

这篇关于在 VOLTTRON 中,如何使用 VIP 使代理跨远程平台实例交谈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆