Skip to main content

Definition

Assembly: CloudNimble.SimpleMessageBus.Core.dll Namespace: CloudNimble.SimpleMessageBus.Core Inheritance: System.Object

Syntax

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 the IMessage) constructor instead.

.ctor

Initializes a new instance of the MessageEnvelope class for a given IMessage.

Syntax

Parameters

Exceptions

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 object

Syntax

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

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 typed GetMessage``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 object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

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

Exceptions

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 object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ToString Override

Syntax

Returns

Type: string

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?