Skip to main content
Version: v0.2.0

Azure Service Bus Features

We provide several additional features related to message creation and message/context discoverability.

Installation

This features requires to install our NuGet package:

PM > Install-Package Arcus.Messaging.ServiceBus.Core

Simplify Creating Service Bus Messages

Starting from the message body, we provide an extension to quickly wrap the content in a valid Azure Service Bus Message type that can be send.

using Microsoft.Azure.ServiceBus;

string rawString = "Some raw content";
Message stringMessage = rawString.AsServiceBusMessage();

Order order = new Order("some order id");
Message orderMessage = order.AsServiceBusMessage();

We also provide additional, optional parameters during the creation:

using Microsoft.Azure.ServiceBus;

byte[] rawBytes = new [] { 0x54, 0x12 };
Message = byteMessage = rawBytes.AsServiceBusMessage(
operationId: Guid.NewGuid().ToString(),
transactionId: Guid.NewGuid().ToString(),
encoding: Encoding.UTF8);

Simplify Message Information Discovery

On receive, the Azure Service Bus message contains a set of .UserProperties with additional information ie. correlation. This information can be accessed in a more simplified way:

using Arcus.Messaging.Abstractions;
using Microsoft.Azure.ServiceBus;

Message message = ...

// Extracted all correlation information from the `.UserProperties` and wrapped inside a valid correlation type.
MessageCorrelationInfo correlationInfo = message.GetCorrelationInfo();

// Extract only the transaction identifier from the correlation information.
string transactionId = message.GetTransactionId();

// Extract a user property in a typed manner.
string myCustomPropertyValue = message.GetUserProperty<string>("my-custom-property-key");

Simplify Message Context Information Discovery

On receive, the context in which the message is received contains a set of .Properties with additional information ie. encoding. This information can be access in a more simplified way:

using Arcus.Messaging.Abstractions;

// Extract the encoding information from the `.UserProperties` and wrapped inside a valid `Encoding` type.
MessageContext messageContext = ...
Encoding encoding = messageContext.GetMessageEncodingProperty();

← back