CachedMessageQueue

Message queue that caches received messages in memory to allow peek operations that may not be supported by the undelying queue.

Implements: [ICleanable](../../../components/run/icleanable, MessageQueue

Description

The CachedMessageQueue class allows you to create message queues that cache received messages in memory, to allow peek operations that may not be supported by the undelying queue.

Important points

  • This queue is used as a base implementation for other queues.

Constructors

Creates a new instance of the persistence component.

CachedMessageQueue(name: str = None, capabilities: MessagingCapabilities = None)

  • name: str - (optional) queue name
  • capabilities: MessagingCapabilities - (optional) capabilities of the message queue

Fields

_auto_subscribe

Boolean variable indicating whether a message queue auto-subscribes or not.

_auto_subscribe: bool

_lock

Thread lock.

_lock: threading.Lock

_event

Thread event.

_event: threading.Event t

_messages

List of messages in a queue.

_messages: MessageEnvelope[]

_receiver

Message receiver.

_receiver: IMessageReceiver

Abstract methods

subscribe

Subscribes to the message broker.

abstractmethod subscribe(context: Optional[IContext])

  • context: IContext - (optional) a context to trace execution through a call chain.

unsubscribe

Unsubscribes from the message broker.

abstractmethod unsubscribe(context: Optional[IContext])

  • context: IContext - (optional) a context to trace execution through a call chain.

Instance methods

clear

Clears component state.

clear(context: Optional[IContext])

  • context: IContext - (optional) a context to trace execution through a call chain.

configure

Configures a component by passing its configuration parameters.

configure(config: ConfigParams)

  • config: ConfigParams - configuration parameters to be set.

end_listen

Ends listening for incoming messages. When this method is called, listen unblocks the thread and execution continues.

end_listen(context: Optional[IContext])

  • context: IContext - (optional) a context to trace execution through a call chainn.

listen

Listens for incoming messages and blocks the current thread until the queue is closed. See IMessageReceiver, receive

listen(context: Optional[IContext], receiver: IMessageReceiver)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • receiver: IMessageReceiver - receiver used to receive incoming messages.

open

Opens the component.

open(context: Optional[IContext])

  • context: IContext - (optional) a context to trace execution through a call chain.

peek

Peeks a single incoming message from the queue without removing it. If there are no messages available in the queue it returns None.

peek(context: Optional[IContext]): MessageEnvelope

  • context: IContext - (optional) a context to trace execution through a call chain.
  • returns: MessageEnvelope - peeked message or None.

peek_batch

Peeks multiple incoming messages from the queue without removing them. If there are no messages available in the queue it returns an empty list.

Important: This method is not supported by MQTT.

peek_batch(context: Optional[IContext], message_count: int):List[MessageEnvelope]

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message_count: int - maximum number of messages to peek.
  • returns: List[MessageEnvelope] - list with peeked messages.

read_message_count

Reads the current number of messages in the queue to be delivered.

read_message_count(): int

  • returns: int - number of messages in the queue.

receive

Receives an incoming message and removes it from the queue.

receive(context: Optional[IContext], wait_timeout: int): MessageEnvelope

  • context: IContext - (optional) a context to trace execution through a call chainn.
  • wait_timeout: int - timeout in milliseconds to wait for a message to come.
  • returns: MessageEnvelope - received message or None.

_send_message_to_receiver

Sends a message to a receiver.

_send_message_to_receiver(receiver: IMessageReceiver, message: MessageEnvelope)

See also