Django Channels API
This provides an implementation of the Django Channels layers API.
Channels installable channel backend using Django Message Broker
- class django_message_broker.layer.ChannelsServerLayer(expiry=60, group_expiry=86400, capacity=100, channel_capacity=None, ip_address='127.0.0.1', port=5556, **kwargs)
Django Message Broker channel layer backend.
- property channels: List[bytes]
Return list of channel names.
- Returns
List of channel names.
- Return type
List[bytes]
- 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 flush() None
Resets the server by flushing all messages from the message store, and groups from the group store.
- async close() None
Closes the client connection.
It’s not clear what the purpose of this function should be? Perhaps it is intended to trigger removal of channel from messages store? But would only make sense if process specific.
- 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[str, Any]) None
Sends a message to a group
- Parameters
group (str) – Group name
message (str) – Message