Definition
Assembly: CloudNimble.SimpleMessageBus.Core.dll Namespace: CloudNimble.SimpleMessageBus.CoreSyntax
Summary
Defines the functionality required for all IMessage processing handlers.Remarks
Message handlers are the core processing units in SimpleMessageBus. They receive messages from queues, process them according to business logic, and handle any errors that occur during processing. Handlers can process multiple message types and are responsible for declaring which types they support.Examples
Methods
GetHandledMessageTypes Abstract
Specifies which IMessage types are handled by this IMessageHandler.Syntax
Returns
Type:System.Collections.Generic.IEnumerable<System.Type>
An IEnumerable`1 containing all of the IMessage types this
IMessageHandler supports. The types must implement IMessage.
Examples
Remarks
This method is called during handler registration to determine message routing. Return all message types that this handler can process. The framework will ensure that only messages of these types are delivered to this handler’sMessageEnvelope) method.
OnErrorAsync Abstract
Specifies what this handler should do when an error occurs during processing.Syntax
Parameters
Returns
Type:System.Threading.Tasks.Task
A Task reference for the asynchronous function.
Examples
Remarks
This method is called when an exception is thrown during message processing. Use this method to implement custom error handling logic such as logging, alerting, or compensating transactions. Note that after this method completes, the message will typically be moved to a poison queue unless retry policies dictate otherwise.OnNextAsync Abstract
Specifies what this handler should do when it is time to process the MessageEnvelope.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
messageEnvelope | CloudNimble.SimpleMessageBus.Core.MessageEnvelope | The MessageEnvelope to process. |
Returns
Type:System.Threading.Tasks.Task
A Task reference for the asynchronous function.
Examples
Remarks
This is the main processing method for messages. The framework calls this method when a message of a supported type (as declared by IMessageHandler.GetHandledMessageTypes) is received from the queue. The message is pre-deserialized and available in the MessageEnvelope.Message property. Any unhandled exceptions thrown from this method will trigger a call toException).