Client Queue
Implements a message queue, used within the client for the Django Message Broker.
- class django_message_broker.server.client_queue.ClientQueue(channel_name: bytes = b'', time_to_live: Optional[float] = None)
Client message queue.
When the client receives messages they are automatically appended to the channel queue by the receive data callback. Client functions are then able to wait on the queue until a message is available.
- stop()
Stop periodic callbacks and remove future tasks from the event queue. This should be called prior to deleting the object.
- _set_messages_available() None
Set (or clear) asyncio event if there are message in the queue.
- push(message: django_message_broker.server.data_message.DataMessage) None
Pushes a message onto the key.
The message may arrive with an expiry time already set, this time should not be modified. If an expiry time has not been set, and a time to live is defined, then the expiry time for the message is determined and appended to the message.
- Parameters
message (DataMessage) – Data message.
- async pull() Optional[django_message_broker.server.data_message.DataMessage]
Pull a message from the queue.
Waits for a message to become available and then returns the first message received by the queue.
If the queue is terminated without a message (because it has been flushed due to inactivity) then return None.
- Returns
Data message
- Return type
Optional[DataMessage]
- property is_empty: bool
Returns true if the queue is empty
- Returns
Returns True if the queue is empty.
- Return type
bool
- property clients_waiting: bool
Returns true if there are clients waiting to receive a message.
- Returns
True if clients waiting for a message.
- Return type
bool
- property can_be_flushed: bool
True if the channel can be flushed from the message store.
A channel can be flushed when there are no messages and no subscribers to the queue, and the expiry date has been passed.
- Returns
True if the channel can be flushed.
- Return type
bool
- _flush_messages() None
Remove expired messages from the queue.
Periodic callback to remove expired messages from the queue.