Non Durable messaging on MSMQ

Component: MSMQ Transport
NuGet Package NServiceBus (7-pre)
This page targets a pre-release version and is subject to change prior to the final release.

Code walk-through

This sample shows the use the Non-Durable Messaging feature of NServiceBus to send non-durable messages via MSMQ.

The project contains three projects:

  • Sender: Sends the express message
  • Receiver: receives the express message
  • Shared: Common functionality shared between both endpoints including the message definition.

Required actions for non-durable messages to function

The are several configuration options that must be set for express message to

Non-transactional Endpoints

The endpoints must be configured to be non-transactional.

var endpointConfiguration = new EndpointConfiguration("Samples.MessageDurability.Sender");
var transport = endpointConfiguration.UseTransport<MsmqTransport>();
transport.Transactions(TransportTransactionMode.None);

MSMQ configured to be non-transactional

To ensure MSMQ is used in a setup and used non-durable way the NServiceBus/Transport connection string must contain useTransactionalQueues=false.

<configuration>
  <connectionStrings>
    <add name="NServiceBus/Transport" connectionString="useTransactionalQueues=false"/>
  </connectionStrings>
</configuration>

Express Attribute

Messages must have an [ExpressAttribute].

[Express]
public class MyMessage :
    IMessage
{
}

Running the solution

Run the solution with both projects as startup project and not the output that the handler in Receiver successfully processes the message

Look at the queue

View the properties of the queues and notice they set to be non-transactional. This is required for non-durable messaging in MSMQ since only non-transactional queues support Express Mode.

Viewing the message

Start the Sender project on it own it will send a message to the Samples.MessageDurability.Receiver queue. Open this message and notice the Recoverable property is false.

Related Articles


Last modified