Definition
Assembly: CloudNimble.SimpleMessageBus.Core.dll Namespace: CloudNimble.SimpleMessageBus.Core Inheritance: System.ObjectSyntax
Summary
Represents a wrapper for an IMessage that will be published to the SimpleMessageBus Queue.Remarks
The MessageEnvelope provides the transport container for messages within the SimpleMessageBus system. It wraps the actual message with metadata needed for processing, error handling, and tracking. The envelope handles message serialization/deserialization and provides processing context for handlers. Key responsibilities include:- Serializing messages for storage in queues
- Tracking processing attempts and timestamps
- Providing handler context through service scope and logging
- Managing message state during processing pipeline
- Facilitating message deserialization for handlers
Examples
Constructors
.ctor
Initializes a new instance of the MessageEnvelope class.Syntax
Remarks
This parameterless constructor should only be used for deserializing the MessageEnvelope from storage. For creating new envelopes to wrap messages, use theIMessage) constructor instead.
.ctor
Initializes a new instance of the MessageEnvelope class for a given IMessage.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
message | CloudNimble.SimpleMessageBus.Core.IMessage | The IMessage instance that will be wrapped in a MessageEnvelope to be posted to the SimpleMessageBus. |
Exceptions
| Exception | Description |
|---|---|
ArgumentNullException | Thrown when message is null. |
Examples
Remarks
This constructor automatically serializes the message to JSON, generates a unique envelope ID, sets the publish timestamp to the current UTC time, and extracts the message type information for later deserialization. The resulting envelope is ready to be published to any queue provider..ctor Inherited
Inherited from
objectSyntax
Properties
AttemptsCount
The number of times the system has previously attempted to process this message.Syntax
Property Value
Type:long
DatePublished
The UTC date and time that this nessage was published to the queue.Syntax
Property Value
Type:System.DateTimeOffset
Id
A Guid uniquely identifying this message on the queue. Helps when looking at logs or correlating from telemetry.Syntax
Property Value
Type:System.Guid
Message
Gets the deserialized message instance.Syntax
Property Value
Type:CloudNimble.SimpleMessageBus.Core.IMessage
The IMessage instance deserialized from MessageEnvelope.MessageContent using the type specified
in MessageEnvelope.MessageType. This property provides convenient access to the message without requiring
explicit type specification in handlers.
Exceptions
| Exception | Description |
|---|---|
InvalidOperationException | Thrown when the message type cannot be resolved or deserialization fails. |
Examples
Remarks
This property deserializes the message on each access. For performance-critical scenarios where the message is accessed multiple times, consider caching the result or using the typedGetMessage``1 method.
The deserialization uses the MessageEnvelope.MessageType to determine the target type and deserializes
the MessageEnvelope.MessageContent JSON string into the appropriate message instance.
MessageContent
The serialized content of the IMessage.Syntax
Property Value
Type:string
MessageState
A container to help track the state of a message as it flows between IMessageHandlerIMessageHandlers</see>. This value is ignored by the serializer and will not be persisted between failed message runs.Syntax
Property Value
Type:dynamic
MessageType
A string representing the type name of the message. Defaults to IMessage.GetType().AssemblyQualifiedName”.Syntax
Property Value
Type:string
ProcessLog
The processing log for this particular message across all MessageHandlers.Syntax
Property Value
Type:Microsoft.Extensions.Logging.ILogger
ServiceScope
The processing log for this particular message across all MessageHandlers.Syntax
Property Value
Type:Microsoft.Extensions.DependencyInjection.IServiceScope
Methods
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
obj | object? | - |
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetMessage
Retrieves the MessageEnvelope.MessageContent deserialized into an IMessage of the specified type.Syntax
Returns
Type:T
A concrete T instance populated with the data from the MessageEnvelope.MessageContent.
Type Parameters
T- The IMessage type represented by the MessageEnvelope.MessageContent.
Exceptions
| Exception | Description |
|---|---|
JsonException | Thrown when the MessageEnvelope.MessageContent cannot be deserialized to type T. |
ArgumentNullException | Thrown when MessageEnvelope.MessageContent is null. |
Examples
Remarks
This method provides type-safe deserialization when you know the exact message type at compile time. It directly deserializes the JSON content without using the MessageEnvelope.MessageType property for type resolution. This can be more performant than the MessageEnvelope.Message property for known types, but requires explicit type specification.GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
ToString Override
Syntax
Returns
Type:string
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?