pip_services3_messaging.queues.CachedMessageQueue module

class pip_services3_messaging.queues.CachedMessageQueue.CachedMessageQueue(name: str = None, capabilities: pip_services3_messaging.queues.MessagingCapabilities.MessagingCapabilities = None)

Bases: pip_services3_messaging.queues.MessageQueue.MessageQueue, pip_services3_commons.run.ICleanable.ICleanable

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

This queue is users as a base implementation for other queues

clear(correlation_id: Optional[str])

Clears component state.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

close(correlation_id: Optional[str])

Closes component and frees used resources.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

end_listen(correlation_id: Optional[str])

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

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

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

Listens for incoming messages and blocks the current thread until queue is closed.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • receiver – a receiver to receive incoming messages.

open(correlation_id: Optional[str])

Opens the component.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

peek(correlation_id: Optional[str])pip_services3_messaging.queues.MessageEnvelope.MessageEnvelope

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

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

Returns

a peeked message or <code>null</code>.

peek_batch(correlation_id: Optional[str], message_count: int) → List[pip_services3_messaging.queues.MessageEnvelope.MessageEnvelope]

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.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • message_count – a maximum number of messages to peek.

Returns

a list with peeked messages.

read_message_count()int

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

Returns

a number of messages in the queue.

receive(correlation_id: Optional[str], wait_timeout: int)pip_services3_messaging.queues.MessageEnvelope.MessageEnvelope

Receives an incoming message and removes it from the queue.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • wait_timeout – a timeout in milliseconds to wait for a message to come.

Returns

a received message or None.