This is part of the NServiceBus Upgrade Guide from Version 5 to 6, which also includes the following individual upgrade guides for specific components:
Feature Details
- Assembly Scanning Changes in NServiceBus Version 6
- No Async Suffix
- Dependency Injection Changes in NServiceBus Version 6
- Deprecated TransportMessage in NServiceBus Version 6
- Endpoint API changes in NServiceBus Version 6
- Extension Seam Changes in NServiceBus Version 6
- Migrate handlers and sagas to Version 6
- Header API changes in NServiceBus Version 6
- Messaging Changes in NServiceBus Version 6
- Moving away from IBus in Version 6
- Recoverability Changes in Version 6
- Serialization Changes in NServiceBus Version 6
- Subscription Changes in NServiceBus Version 6
- Transaction Configuration Changes in NServiceBus Version 6
Transports
- Azure Service Bus Transport (Legacy) Upgrade Version 6 to 7
- RabbitMQ Transport Upgrade Version 3 to 4
- SQL Server Transport Upgrade Version 2 to 3
- SQL Server Transport Upgrade - Supporting Unicode in Headers
Persistence
- Upgrade from NServiceBus Azure Version 6
- NHibernate Persistence Upgrade Version 6 to 7
- NHibernate Persistence - Resolving incorrect timeout table indexes
- RavenDB Persistence Upgrade from 3 to 4
Hosting
Other
- Moving to the DataBus AzureBlobStorage Package
- Azure Cloud Services Host Upgrade Version 6 to 7
- NServiceBus.Azure package deprecated
- Gateway Upgrade Version 1 to 2
- NServiceBus Testing Upgrade Version 5 to 6
- Callback Changes in NServiceBus Version 6
- Migrating the distributor to use sender-side distribution
- Tool and Helper Changes in NServiceBus Version 6
Previous versions used TransportMessage
as a generic holder both for outgoing and incoming messages. For a better separation of concerns that class has been split into IncomingMessage
and OutgoingMessage
. All code paths related to outgoing messages use OutgoingMessage
and all code paths related to incoming messages use IncomingMessage
. The class TransportMessage
has been deprecated entirely. Here are a few common scenarios related to TransportMessage
and how they can be addressed with either IncomingMessage
or OutgoingMessage
.
Body
Both IncomingMessage
and OutgoingMessage
provide a byte array to access the underlying payload of the property Body
.
When setting the body, raw sending is the most likely scenario. See Raw sending below.
Headers
Both IncomingMessage
and OutgoingMessage
provide a dictionary to get or set headers of the property Headers
.
ID
Both IncomingMessage
and OutgoingMessage
provide a message ID of the property MessageId
.
CorrelationId
The correlation ID is no longer a strongly-typed property exposed. To get access to the correlation ID of a message use the Headers.
key.
ReplyAddress
The ReplyAddress
can only be accessed on an incoming message. Use the extension method GetReplyAddress
on IncomingMessage
to acquire the reply address.
MessageIntent
The MessageIntent
can only be accessed on an incoming message. Use the extension method GetMessageIntent
on IncomingMessage
to acquire the message intent.
TimeToBeReceived
From the perspective of an outgoing message, the TimeToBeReceived
is a delivery concern and must be specified over the newly introduced DeliveryConstraint
.
Set the TimeToBeReceived
var timeToBeReceived = TimeSpan.FromSeconds(25);
var deliveryConstraint = new DiscardIfNotReceivedBefore(timeToBeReceived);
context.Extensions.AddDeliveryConstraint(deliveryConstraint);
Read the TimeToBeReceived
context.Extensions.TryGetDeliveryConstraint(out DiscardIfNotReceivedBefore constraint);
timeToBeReceived = constraint.MaxTime;
From the perspective of an incoming message, the TimeToBeReceived
can be acquired by using the Headers.
on the IncomingMessage.
dictionary.
Recoverable
From the perspective of an outgoing message, the Recoverable
flag is a delivery concern and must be specified over the newly introduced DeliveryConstraint
.
Set the Recoverable
context.Extensions.AddDeliveryConstraint(new NonDurableDelivery());
Read the Recoverable
context.Extensions.TryGetDeliveryConstraint(out NonDurableDelivery constraint);
From the perspective of an incoming message, the Recoverable
flag can be acquired by using the Headers.
on the IncomingMessage.
dictionary.
Raw sending
In NServiceBus version 5, it was possible to use ISendMessages
to do raw sends. In version 6 IDispatchMessages
was introduced. The following snippet shows an example of how to send raw messages:
var headers = new Dictionary<string, string>();
var outgoingMessage = new OutgoingMessage("MessageId", headers, new byte[]
{
});
var constraints = new List<DeliveryConstraint>
{
new NonDurableDelivery()
};
var address = new UnicastAddressTag("Destination");
var operation = new TransportOperation(
message: outgoingMessage,
addressTag: address,
requiredDispatchConsistency: DispatchConsistency.Default,
deliveryConstraints: constraints);
var operations = new TransportOperations(operation);
await dispatcher.Dispatch(operations, new TransportTransaction(), new ContextBag());