This sample demonstrates how to use the Windows Azure Service Bus duplicate message detection with queues. See the Service Bus documentation for more information about the Service Bus before exploring the samples.

This sample creates two queues, one with duplicate detection enabled and other one without duplicate detection.

Prerequisites

If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure account and how to configure your environment.

Sample Flow

The sample flows in the following manner:

  1. Sample creates a queue called “DefaultQueue” without duplicate detection enabled:
    1. Sends a message with MessageId “MessageId123”;
    2. Sends another message with the same MessageId i.e. a duplicate message
    3. Receives the messages. It receives both the messages as the queue does not detect duplicate messages.
  2. Sample creates another queue called “RemoveDuplicatesQueue” with duplicate detection enabled:
    1. Sends a message with MessageId “MessageId123”;
    2. Sends another message with the same MessageId i.e. a duplicate message
    3. Receives the messages. This time it receives only one message since the duplicate messages are detected and dropped by the queue itself.
  3. Sample deletes both the queues

Running the Sample

To run the sample:

  1. Build the solution in Visual Studio and run the sample project.
  2. When prompted enter following information:
    1. ServiceBus namespace;
    2. ServiceBus issuer name;
    3. ServiceBus issuer secret.

Expected Output

ServiceBus Namespace: <enter service namespace>
ServiceBus Issuer Name: <enter issuer name>
ServiceBus Issuer Secret: <enter issuer secret>
 
Creating DefaultQueue ...
Created DefaultQueue
        Sending messages to DefaultQueue ...
        => Sent a message with messageId ABC123
        => Sent a duplicate message with messageId ABC123
 
        Waiting for messages from DefaultQueue ...
        <= Received a message with messageId ABC123
        <= Received a message with messageId ABC123
                RECEIVED a DUPLICATE MESSAGE
        Done receiving messages from DefaultQueue
 
Creating RemoveDuplicatesQueue ...
Created RemoveDuplicatesQueue
        Sending messages to RemoveDuplicatesQueue ...
        => Sent a message with messageId ABC123
        => Sent a duplicate message with messageId ABC123
 
        Waiting for messages from RemoveDuplicatesQueue ...
        <= Received a message with messageId ABC123
        Done receiving messages from RemoveDuplicatesQueue
 
Press [Enter] to exit.
                    

Did you find this information useful? Please send your suggestions and comments about the documentation.