Getting Started
Architecture
NServiceBus
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

MSMQ Transport Upgrade Version 1 to 2

Component: MSMQ Transport

Configuring the MSMQ transport

To use the MSMQ transport for NServiceBus, create a new instance of MsmqTransport and pass it to EndpointConfiguration.UseTransport.

Instead of:

var transport = endpointConfiguration.UseTransport<MsmqTransport>();
transport.ConnectionString(connectionString);

Use:

var transport = new MsmqTransport();
endpointConfiguration.UseTransport(transport);

Delayed delivery

Version 2 supports delayed delivery of messages by persisting them in a delayed message store. There is a built-in SQL Server-based store and an extension point for custom stores.

In version 2, explicit configuration is required to enable delayed message delivery. For example:

2.x NServiceBus.Transport.Msmq
var messageStore = new SqlServerDelayedMessageStore(
    connectionString: "database=(local); initial catalog=my_catalog; integrated security=true",
    schema: "my_schema", //optional, defaults to dbo
    tableName: "my_delayed_messages"); //optional, defaults to endpoint name with '.delayed' suffix

var transport = new MsmqTransport
{
    DelayedDelivery = new DelayedDeliverySettings(messageStore)
    {
        NumberOfRetries = 7,
        MaximumRecoveryFailuresPerSecond = 2,
        TimeToTriggerStoreCircuitBreaker = TimeSpan.FromSeconds(20),
        TimeToTriggerDispatchCircuitBreaker = TimeSpan.FromSeconds(15),
        TimeToTriggerFetchCircuitBreaker = TimeSpan.FromSeconds(45)
    }
};
endpointConfiguration.UseTransport(transport);
1.2 NServiceBus.Transport.Msmq
var messageStore = new SqlServerDelayedMessageStore(
    connectionString: "database=(local); initial catalog=my_catalog; integrated security=true",
    schema: "my_schema", //optional, defaults to dbo
    tableName: "my_delayed_messages"); //optional, defaults to endpoint name with '.delayed' suffix

var transport = endpointConfiguration.UseTransport<MsmqTransport>();
var delayedDeliverySettings = transport.NativeDelayedDelivery(messageStore);

delayedDeliverySettings.NumberOfRetries = 7;
delayedDeliverySettings.MaximumRecoveryFailuresPerSecond = 2;
delayedDeliverySettings.TimeToTriggerStoreCircuitBreaker = TimeSpan.FromSeconds(20);
delayedDeliverySettings.TimeToTriggerDispatchCircuitBreaker = TimeSpan.FromSeconds(15);
delayedDeliverySettings.TimeToTriggerFetchCircuitBreaker = TimeSpan.FromSeconds(45);

endpointConfiguration.DisableFeature<TimeoutManager>();

When upgrading from version 1 to 2, all the existing delayed messages must be migrated using the timeout migration tool.

Configuration options

The MSMQ transport configuration options have been moved to the MsmqTransport class. See the following table for further information:

Version 1 configuration optionVersion 2 configuration option
ApplyLabelToMessagesApplyCustomLabelToOutgoingMessages
TransactionScopeOptionsConfigureTransactionScope
UseDeadLetterQueueForMessagesWithTimeToBeReceivedUseDeadLetterQueueForMessagesWithTimeToBeReceived
DisableInstallerCreateQueues
DisableDeadLetterQueueingUseDeadLetterQueue
DisableConnectionCachingForSendsUseConnectionCache
UseNonTransactionalQueuesUseTransactionalQueues
EnableJournalingUseJournalQueue
TimeToReachQueueTimeToReachQueue
DisableNativeTimeToBeReceivedInTransactionsUseNonNativeTimeToBeReceivedInTransactions
IgnoreIncomingTimeToBeReceivedHeadersIgnoreIncomingTimeToBeReceivedHeaders

Related Articles

  • MSMQ Transport
    MSMQ is a solid durable communications technology but does not dynamically detect network interfaces.
  • Upgrade Version 7 to 8
    Instructions on how to upgrade NServiceBus from version 7 to version 8.