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:
- Sample creates a queue called “DefaultQueue” without duplicate detection enabled:
- Sends a message with MessageId “MessageId123”;
- Sends another message with the same MessageId i.e. a duplicate message
- Receives the messages. It receives both the messages as the queue does not detect duplicate messages.
- Sample creates another queue called “RemoveDuplicatesQueue” with duplicate detection enabled:
- Sends a message with MessageId “MessageId123”;
- Sends another message with the same MessageId i.e. a duplicate message
- Receives the messages. This time it receives only one message since the duplicate messages are detected and dropped by the queue itself.
- Sample deletes both the queues
Running the Sample
To run the sample:
- Build the solution in Visual Studio and run the sample project.
- When prompted enter following information:
- ServiceBus namespace;
- ServiceBus issuer name;
- 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. |