Signalling Message
Implements a signalling message as a structured dataclass. Used to pass signaling message between the Django Message Broker clients and server.
- class django_message_broker.server.signalling_message.SignallingMessageCommands
Valid message commands for signalling messages.
Client to server
GROUP_ADD (b”GROUPADD”) - Add a channel to a group.
GROUP_DISCARD (b”GROUPDIS”) - Remove a channel from a group.
FLUSH (b”FLUSHXXX”) - Remove all groups, subscriptions and messages from the server.
PRINT (b”PRINTXXX”) - Print contents of message store and group store to terminal.
PERFORMANCE (b”PERFMNCE”) - Request performance report
Server to client
COMPLETE (b”COMPLETE”) - Command complete
EXCEPTION (b”EXCEPTON”) - Command raised an exception.
PERFORMANCE_REPORT (b”PERFRPRT”) - Transmit performance report
FLUSH_CLIENT (b”FLUSHCXX”) - Flush client message store.
Both ways
KEEPALIVE (b”HARTBEAT”) - Intermittent message confirming client/server alive.
- class django_message_broker.server.signalling_message.SignallingMessage(endpoints: typing.List = <factory>, id: bytes = <factory>, command: bytes = b'XXXXXXXX', properties: typing.Dict = <factory>)
Message is formatted on wire as n + 1 + 3 frames. Where n is the number of routing_ids added to the front of a message on zmq.DEALER to zmq.ROUTER messages; 1 is the null frame to separate routing_ids from the message; and 3 is the number of frames in the message.
frame -1:-n: Routing IDs (list of zmq.DEALER identities)
frame 0: b”” blank frame
frame 1: id - Unique universal identifier for tracking commands
frame 2: command - Message type (publish to channel, to group, subscribe to channel)
frame 3: properties - Properties appended to message
- __getitem__(key: Union[int, str]) Any
Returns values stored in the properties frame of the message.
- Parameters
key (Union[int, str]) – Property key
- Returns
Value stored in the property.
- Return type
Optional[Any]
- Raises
KeyError – If the key doesn’t exist.
- get(key: Union[int, str], default: Optional[Any] = None) Optional[Any]
Returns values stored in the properties frame of the message.
- Parameters
key (Union[int, str]) – Property key.
default (Any, optional) – Default value if key doesn’t exist.
- Returns
Property value if key exists, default or None if it doesn’t.
- Return type
Optional[Any]
- __setitem__(key: Union[int, str], value: Any) None
Sets the value of a property in the properties frame of the message.
- Parameters
key (Union[int, str]) – Property key
value (Any) – Value of the property (must be serialisable by msgspec)
- __repr__() str
Returns a printable string of signalling message contents.
Returns:
Endpoint list
Unique message id
Command
Properties
- Returns
Signalling message contents.
- Return type
str
- async send(socket: Union[zmq.sugar.socket.Socket, zmq.eventloop.zmqstream.ZMQStream]) None
Sends a message on the defined socket or stream.
- Parameters
socket (Union[zmq.Socket, ZMQStream]) – Socket or stream on which message sent.
- Raises
MessageTooLarge – The body of the message exceeds the maximum permissible.
ChannelsSocketClosed – Socket or stream closed.
MessageFormatException – Error occurred sending the message.
- classmethod recv(socket: zmq.sugar.socket.Socket) django_message_broker.server.signalling_message.SignallingMessage
Reads message from socket, returns new message instance.
- classmethod from_msg(multipart_message: Union[_asyncio.Future, List]) django_message_broker.server.signalling_message.SignallingMessage
Returns a new message instance from zmq multipart message frames.
- Args:
multipart_message (Union[Future, List]): A list (or list in a Future) of zmq multipart frames.
- Raises
MessageFormatException – If the number of frames in the multipart message doesn’t match the schema.
- Returns
New instance of the message.
- Return type