In VOLTTRON, how to use VIP to get agents talk across remote platform instances?

时光怂恿深爱的人放手 提交于 2019-12-02 15:51:47

问题


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?

Thanks.


回答1:


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

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.

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

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)


来源:https://stackoverflow.com/questions/39212536/in-volttron-how-to-use-vip-to-get-agents-talk-across-remote-platform-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!