Process Worker API
This provides a message interface for background process workers.
Implements a client for the Django Message Broker within a process
- class django_message_broker.process_client.ProcessClient(expiry=60, group_expiry=86400, ip_address='127.0.0.1', port=5556, **kwargs)
Implements a process client.
- async new_channel(prefix: str = 'specific') str
Returns a new channel name that can be used by something in our process as a specific channel.
- Parameters
prefix (str, optional) – Prefix to channel name. Defaults to “specific”.
- Returns
Process specific channel name.
- Return type
str
- async send(channel: str, message: Dict) None
Send a message onto a (general or specific) channel.
- Parameters
channel (str) – Channel name
message (Dict) – Message to send
- async receive(channel: str) Dict
Receive the first message that arrives on the channel. If more than one coroutine waits on the same channel, a random one of the waiting coroutines will get the result. Subscribe to the channel first to ensure that the Channels client receive messages from the server.
- Parameters
channel (str) – Channel name
- Returns
Received message.
- Return type
Dict
- async group_add(group: str, channel: str) None
Adds the channel to a group. If the group doesn’t exist then it is created. A subscription request is also sent to the server to ensure that messages are delivered locally.
- Parameters
group (str) – Name of the group to join.
channel (str) – Channel joining the group.
- async group_discard(group: str, channel: str) None
Removes a channel from a group
- Parameters
group (str) – Group name
channel (str) – Channel name
- async group_send(group: str, message: dict) None
Sends a message to a group
- Parameters
group (str) – Group name
message (str) – Message