CachedMessageQueue

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

Implements: 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(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.

unsubscribe

Unsubscribes from the message broker.

abstractmethod unsubscribe(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.

Instance methods

clear

Clears component state.

clear(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the 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(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.

listen

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

listen(correlation_id: Optional[str], receiver: IMessageReceiver)

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.
  • receiver: IMessageReceiver - receiver used to receive incoming messages.

open

Opens the component.

open(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the 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(correlation_id: Optional[str]): MessageEnvelope

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the 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(correlation_id: Optional[str], message_count: int):List[MessageEnvelope]

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the 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(correlation_id: Optional[str], wait_timeout: int): MessageEnvelope

  • correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.
  • 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