Inherits: MessageQueue, ICleanable
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.
publicCachedMessageQueue(string name = null, MessagingCapabilities capabilities = null)
- name: string - (optional) queue name
- capabilities: MessagingCapabilities - (optional) capabilities of the message queue
Fields
Abstract methods
SubscribeAsync
Subscribes to the message broker.
protected abstractTask SubscribeAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
UnsubscribeAsync
Unsubscribes from the message broker.
protected abstractTask UnsubscribeAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
Instance methods
Clear
Clears component state.
public overrideTask ClearAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
Configure
Configures a component by passing its configuration parameters.
public overrideConfigure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
EndListen
Ends listening for incoming messages. When this method is called, listen unblocks the thread and execution continues.
public overridevoid EndListen(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
ListenAsync
Listens for incoming messages and blocks the current thread until the queue is closed. See IMessageReceiver, Receive
public overrideTask ListenAsync(string correlationId, IMessageReceiver receiver)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- receiver: IMessageReceiver - receiver used to receive incoming messages.
OpenAsync
Opens the component.
public overrideTask OpenAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
PeekAsync
Peeks a single incoming message from the queue without removing it. If there are no messages available in the queue, it returns null.
public overrideTask<MessageEnvelope> PeekAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- returns: Task<MessageEnvelope> - peeked message or null.
PeekBatchAsync
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.
public overrideTask<List<MessageEnvelope>> PeekBatchAsync(string correlationId, int messageCount)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- messageCount: int - maximum number of messages to peek.
- returns: Task<List<MessageEnvelope>> - list with peeked messages.
ReadMessageCountAsync
Reads the current number of messages in the queue to be delivered.
public overrideTask<long> ReadMessageCountAsync()
- returns: Task<long> - number of messages in the queue.
ReceiveAsync
Receives an incoming message and removes it from the queue.
public overrideTask<MessageEnvelope> ReceiveAsync(string correlationId, long waitTimeout)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- waitTimeout: long - timeout in milliseconds to wait for a message to come.
- returns: Task<MessageEnvelope> - received message or null.