diff --git a/nvflare/fuel/utils/pipe/pipe.py b/nvflare/fuel/utils/pipe/pipe.py index b928b01b5b..c6b0c6f16c 100644 --- a/nvflare/fuel/utils/pipe/pipe.py +++ b/nvflare/fuel/utils/pipe/pipe.py @@ -38,7 +38,7 @@ class Message: def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=None): check_str("msg_type", msg_type) if msg_type not in [Message.REPLY, Message.REQUEST]: - raise ValueError(f"invalid note_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}") + raise ValueError(f"invalid msg_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}") self.msg_type = msg_type check_str("topic", topic) @@ -61,10 +61,46 @@ def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=Non @staticmethod def new_request(topic: str, data: Any, msg_id=None): + """Creates a new request message. + + This static method creates a new `Message` object representing a request. + + Args: + topic (str): The topic of the request message. + This is a string that identifies the subject or category of the request. + data (Any): The data associated with the request message. + This can be any type of data that is relevant to the request. + msg_id (Optional[Any]): An optional identifier for the message. + If provided, this ID is used to uniquely identify the message. + If not provided, a UUID will be generated to uniquely identify the message. + + Returns: + Message: A `Message` object with the type set to `Message.REQUEST`, + and the provided `topic`, `data`, and `msg_id`. + + """ return Message(Message.REQUEST, topic, data, msg_id) @staticmethod def new_reply(topic: str, data: Any, req_msg_id, msg_id=None): + """Creates a new reply message in response to a request. + + This static method creates a new `Message` object representing a reply to a previous request. + + Args: + topic (str): The topic of the reply message. + This is a string that identifies the subject or category of the reply. + data (Any): The data associated with the reply message. This can be any type of data relevant to the reply. + req_msg_id (int): The identifier of the request message that this reply is responding to. + This ID links the reply to the original request. + msg_id (Optional[int]): An optional identifier for the reply message. + If provided, this ID is used to uniquely identify the message. + If not provided, a UUID will be generated to uniquely identify the message. + + Returns: + Message: A `Message` object with the type set to `Message.REPLY`, + and the provided `topic`, `data`, `msg_id`, and `req_msg_id`. + """ return Message(Message.REPLY, topic, data, msg_id, req_id=req_msg_id) def __str__(self):