MemoryMessageQueue

Message queue that sends and receives messages within the same process by using shared memory.

Inherits: MessageQueue

Description

The MemoryMessageQueue class is used to create message queues that send and receive messages within the same process by using shared memory.

Important points

  • This queue is typically used for testing to mock real queues.

Configuration parameters

  • name: name of the message queue

References

  • *:logger:*:*:1.0 - (optional) [ILogger](../../../observability/log/ilogger components to pass log messages
  • *:counters:*:*:1.0 - (optional) ICounters components to pass collected measurements

Constructors

Creates a new instance of the message queue.
See also MessagingCapabilities

public MemoryMessageQueue(string name = null)

  • name: string - (optional) a queue name.

Instance methods

Abandon

Returns a message into the queue and makes it available for all subscribers to receive it again. This method is usually used to return a message that could not be processed at the moment to repeat the attempt. Messages that cause unrecoverable errors shall be removed permanently or/and sent to dead letter queue.

public override Task AbandonAsync(MessageEnvelope message)

ClearAsync

Clears the component’s state.

public override Task ClearAsync(IContext context)

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

CloseAsync

Closes the component and frees used resources.

public override Task CloseAsync(IContext context)

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

CompleteAsync

Permanently removes a message from the queue. This method is usually used to remove the message after successful processing.

public override Task CompleteAsync(MessageEnvelope message)

EndListen

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

public override void EndListen(IContext context)

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

IsOpen

Checks if the component is open.

public override bool IsOpen()

  • returns: bool - true if the component is open and false otherwise.

ListenAsync

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

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.

Peek

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.

PeekBatch

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

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.

ReadMessageCount

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.

RenewLock

Renews a lock on a message that makes it invisible from other receivers in the queue. This method is usually used to extend the message processing time.

public override Task RenewLockAsync(MessageEnvelope message, long lockTimeout)

  • message: MessageEnvelope - message to extend its lock.
  • lockTimeout: long - locking timeout in milliseconds.

SendAsync

Sends a message into the queue.

public override Task SendAsync(IContext context, MessageEnvelope message)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • envelope: MessageEnvelope - message envelop to be sent.

Examples

var queue = new MessageQueue("myqueue");

queue.SendAsync("123", new MessageEnvelop(null, "mymessage", "ABC"));

queue.ReceiveAsync("123", 0);

See also