Message¶
- class Message(content: RecordDict, dst_node_id: int, message_type: str, *, ttl: float | None = None, group_id: str | None = None)[source]¶
- class Message(content: RecordDict, *, reply_to: Message, ttl: float | None = None)
- class Message(error: Error, *, reply_to: Message, ttl: float | None = None)
Bases:
object
Represents a message exchanged between ClientApp and ServerApp.
This class encapsulates the payload and metadata necessary for communication between a ClientApp and a ServerApp.
- Parameters:
content (Optional[RecordDict] (default: None)) – Holds records either sent by another entity (e.g. sent by the server-side logic to a client, or vice-versa) or that will be sent to it.
error (Optional[Error] (default: None)) – A dataclass that captures information about an error that took place when processing another message.
dst_node_id (Optional[int] (default: None)) – An identifier for the node receiving this message.
message_type (Optional[str] (default: None)) – A string that encodes the action to be executed on the receiving end.
ttl (Optional[float] (default: None)) – Time-to-live (TTL) for this message in seconds. If None (default), the TTL is set to 43,200 seconds (12 hours).
group_id (Optional[str] (default: None)) – An identifier for grouping messages. In some settings, this is used as the FL round.
reply_to (Optional[Message] (default: None)) – The instruction message to which this message is a reply. This message does not retain the original message’s content but derives its metadata from it.
Methods
create_error_reply
(error[, ttl])Construct a reply message indicating an error happened.
create_reply
(content[, ttl])Create a reply to this message with specified content and TTL.
Return True if message has content, else False.
Return True if message has an error, else False.
Attributes
The content of this message.
Error captured by this message.
A dataclass including information about the message to be executed.
- property content: RecordDict¶
The content of this message.
- create_error_reply(error: Error, ttl: float | None = None) Message [source]¶
Construct a reply message indicating an error happened.
- Parameters:
error (Error) – The error that was encountered.
ttl (Optional[float] (default: None)) –
Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:
ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)
- Returns:
message – A Message containing only the relevant error and metadata.
- Return type:
- create_reply(content: RecordDict, ttl: float | None = None) Message [source]¶
Create a reply to this message with specified content and TTL.
The method generates a new Message as a reply to this message. It inherits ‘run_id’, ‘src_node_id’, ‘dst_node_id’, and ‘message_type’ from this message and sets ‘reply_to_message_id’ to the ID of this message.
- Parameters:
content (RecordDict) – The content for the reply message.
ttl (Optional[float] (default: None)) –
Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:
ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)
- Returns:
A new Message instance representing the reply.
- Return type: