implemented neighboring agent discovery and agent to agent communication#114
implemented neighboring agent discovery and agent to agent communication#114
Conversation
|
|
||
| self.app_id = agent_config['app_id'] | ||
| self.description = agent_config['description'] | ||
| self.agent_id = str(uuid.uuid4()) |
There was a problem hiding this comment.
Do we really want a random id or do we want something sudo random so we can tell it's a distributed agent?
There was a problem hiding this comment.
Changed to 'da_[app_id]_[timestamp]'. Similar to instance id for centralized apps and services.
| def subscribe_to_measurement(self): | ||
| if self.simulation_id is None: | ||
| self.downstream_message_bus.subscribe(f"fieldbus/{self.downstream_message_bus.id}", self.on_measurement) | ||
| self.downstream_message_bus.subscribe(f"/topic/goss.gridappsd.field.output.{self.downstream_message_bus.id}", self.on_measurement) |
There was a problem hiding this comment.
This should use the topics t to build this topic rather than hard coding here.
There was a problem hiding this comment.
Updated to be imported from topics.
| def on_request(self, message_bus, headers:Dict, message): | ||
| raise NotImplementedError(f"{self.__class__.__name__} must be overriden in child class") | ||
|
|
||
| def get_registration_details(self): |
There was a problem hiding this comment.
Registration details should be a dataclass that can be returned/serialized as json rather than a dictionary.
There was a problem hiding this comment.
AgentRegitrationDetails dataclass added.
|
|
||
| @abstractmethod | ||
| def publish(self, data, topic: str = None): | ||
| def send(self, topic, data): |
There was a problem hiding this comment.
elsewhere we use topic message....which should it be?
There was a problem hiding this comment.
Changed to message.
|
|
||
| @abstractmethod | ||
| def publish(self, data, topic: str = None): | ||
| def get_agent_response(self, agent_id, message, timeout): |
There was a problem hiding this comment.
abstractmethods don't have implementation....
There was a problem hiding this comment.
Removed abstract.
| :return: | ||
| """ | ||
| assert message_bus_id, "message_bus_id cannot be empty" | ||
| return "{}.{}.{}.{}".format(BASE_FIELD_TOPIC, message_bus_id, app_id, agent_id) |
There was a problem hiding this comment.
use f-string formatting...it is much easier to read.
There was a problem hiding this comment.
return f"{BASE_FIELD_TOPIC}.{message_bus_id}.{app_id}.{agent_id}"
or use ".".join([BASE_FIELD_TOPIC, message_bus_id, app_id, agent_id])
Make sure the arguments are strings though or the above will fail.
There was a problem hiding this comment.
Changed. We do the same in all other functions so may have to change all . Will create another issue if needed.
Documentation to test in the distributed sample app PR: GRIDAPPSD/gridappsd-sample-distributed-app#6