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.
public
CachedMessageQueue(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 abstract
Task SubscribeAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
UnsubscribeAsync
Unsubscribes from the message broker.
protected abstract
Task UnsubscribeAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
Instance methods
Clear
Clears component state.
public override
Task ClearAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
Configure
Configures a component by passing its configuration parameters.
public override
Configure(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 override
void EndListen(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
ListenAsync
Listens for incoming messages and blocks the current thread until the queue is closed. See IMessageReceiver, Receive
public override
Task ListenAsync(IContext context, IMessageReceiver receiver)
- context: IContext - (optional) a context to trace execution through a call chain.
- receiver: IMessageReceiver - receiver used to receive incoming messages.
OpenAsync
Opens the component.
public override
Task OpenAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a 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 override
Task<MessageEnvelope> PeekAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a 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 override
Task<List<MessageEnvelope>> PeekBatchAsync(IContext context, int messageCount)
- context: IContext - (optional) a context to trace execution through a 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 override
Task<long> ReadMessageCountAsync()
- returns: Task<long> - number of messages in the queue.
ReceiveAsync
Receives an incoming message and removes it from the queue.
public override
Task<MessageEnvelope> ReceiveAsync(IContext context, long waitTimeout)
- context: IContext - (optional) a context to trace execution through a call chain.
- waitTimeout: long - timeout in milliseconds to wait for a message to come.
- returns: Task<MessageEnvelope> - received message or null.