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
Using a custom correlation id
In NServiceBus version 6, custom correlation IDs for outgoing messages should be set using the new Send
/Reply
or Publish
options instead of being passed into bus.
.
WinIdName header removed
The WinIdName
existed to enable the Principal Replacement feature (RunHandlersUnderIncomingPrincipal
in NServiceBus version 4 and ImpersonateSender
in version 3).
See the appending username using headers sample for usage of this API.
This feature was removed in version 5 and the WinIdName
header will no longer be added to outgoing messages.
To re-add this header to outgoing messages a mutator can be used.
public class WinIdNameMutator :
IMutateOutgoingTransportMessages
{
public Task MutateOutgoing(MutateOutgoingTransportMessageContext context)
{
var currentIdentity = Thread.CurrentPrincipal.Identity;
context.OutgoingHeaders["WinIdName"] = currentIdentity.Name;
return Task.CompletedTask;
}
}
Another option is to use a custom header as illustrated in the appending username using headers sample.
Throttling
Requirements for throttling mechanisms are very different. While some third-party services (e.g. GitHub, Twitter, Google) enforce rate limits on certain time periods, other services may have entirely different usage limitations. The throttling API in NServiceBus version 5 offers a limited, messages-per-second-based throttling mechanism which works for very few scenarios. Therefore, the throttling API has been removed with version 6 without a built-in alternative.
The MaximumMessageThroughputPerSecond
on the TransportConfig
class has been marked as obsolete. Using a configuration-based approach, the endpoint will fail to start when using the MaximumMessageThroughputPerSecond
attribute on the
element.
Immediate dispatch
Using a suppressed transaction scope to request sends to be dispatched immediately is still supported. However it is recommended to switch to the new explicit API for immediate dispatch.
Batched dispatch
NServiceBus version 6 introduced the concept of batched dispatch which means that outgoing operations won't dispatch to the transport until all the handlers of the current message have completed successfully. This helps reduce inconsistencies, in the form of "ghost" messages being emitted due to exceptions during processing.
Deprecated address
NServiceBus version 5 represents addresses with an Address
class. The Address
class maintains addresses in the queue@host format. This format was originally developed for the MSMQ transport but does not meet the needs of other transports. In version 6, addresses are represented as opaque strings.
Any usages of Address
should be replaced by string
.
Native sends via MSMQ
MsmqMessageSender
and MsmqSettings
are no longer available. Refer to native sends for other ways of sending raw messages via MSMQ.
Delayed delivery
With the deprecation of IBus
, message delivery can no longer be delayed with bus.
. To delay a message, use the DelayDeliveryWith(TimeSpan)
and DoNotDeliverBefore(DateTime)
methods on SendOptions
passed into Send()
.
// For NServiceBus version 6.x
var sendOptions = new SendOptions();
sendOptions.DelayDeliveryWith(TimeSpan.FromMinutes(30));
// OR
sendOptions.DoNotDeliverBefore(new DateTime(2016, 12, 25));
await handlerContext.Send(message, sendOptions);
// For NServiceBus version 5.x
bus.Defer(TimeSpan.FromMinutes(30), message);
// OR
bus.Defer(new DateTime(2016, 12, 25), message);
Message forwarding
Forwarded messages no longer contain additional auditing headers, such as processing start and end times, processing host id and name, and processing endpoint.
Audit InvokedSagas header
In NServiceBus version 5, the InvokedSagas
header is added to audited messages and populated with the name of the saga classes invoked along with their unique identifiers.
This functionality has been moved from the NServiceBus core to the SagaAudit plugin compatible with version 6.