Class DefaultMessageManager
Instances of IMessageManager manage the lifecycle of a message being processed.
public class DefaultMessageManager : IMessageManager
- Inheritance
-
DefaultMessageManager
- Implements
Remarks
Responsibilities:
- Start the async work of processing messages and add the task to collection of active tasks
- Monitor the active processing message's task
- If a task completes with success status code delete message
- While the message tasks are working periodically inform the source the message is still being processed.
Constructors
DefaultMessageManager(ISQSMessageCommunication, IHandlerInvoker, ILogger<DefaultMessageManager>, MessageManagerConfiguration)
Constructs an instance of DefaultMessageManager
public DefaultMessageManager(ISQSMessageCommunication sqsMessageCommunication, IHandlerInvoker handlerInvoker, ILogger<DefaultMessageManager> logger, MessageManagerConfiguration configuration)
Parameters
sqsMessageCommunication
ISQSMessageCommunicationProvides APIs to communicate back to SQS and the associated Queue for incoming messages.
handlerInvoker
IHandlerInvokerUsed to look up and invoke the correct handler for each message
logger
ILogger<DefaultMessageManager>Logger for debugging information
configuration
MessageManagerConfigurationThe configuration for the message manager
Properties
ActiveMessageCount
The number of active messages being processed.
public int ActiveMessageCount { get; }
Property Value
Methods
ProcessMessageAsync(MessageEnvelope, SubscriberMapping, CancellationToken)
Start the async processing of a message.
public Task ProcessMessageAsync(MessageEnvelope messageEnvelope, SubscriberMapping subscriberMapping, CancellationToken token = default)
Parameters
messageEnvelope
MessageEnvelopeThe message to start processing
subscriberMapping
SubscriberMappingThe mapping between the message's type and its handler
token
CancellationTokenOptional token to cancel the message processing
Returns
ProcessMessageGroupAsync(List<ConvertToEnvelopeResult>, string, CancellationToken)
Starts the async processing of messages within an ordered group. These messages are processed sequentially in the order in which they appear.
public Task ProcessMessageGroupAsync(List<ConvertToEnvelopeResult> messageGroup, string groupId, CancellationToken token = default)
Parameters
messageGroup
List<ConvertToEnvelopeResult>The ordered list of messages that will be processed sequentially
groupId
stringThe ID that uniquely identifies a message group
token
CancellationTokenOptional token to cancel the message processing
Returns
WaitAsync(TimeSpan)
Allows a poller to wait for when ActiveMessageCount is next decremented or when the timeout elapses
public Task WaitAsync(TimeSpan timeout)
Parameters
timeout
TimeSpanMaximum amount of time to wait