This sample demonstrates how to use Windows Azure Service Bus to send and receive messages asynchronously from a queue.
The queue provides decoupled, asynchronous communication between a sender and any number of receivers (here, a single receiver).
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.
Sample Flow
The sample flows in the following manner:
- Start a sender.
- Sender prompts for user Service Bus credentials.
- Sender creates queue.
- Sender sends messages to queue.
- Start a receiver.
- Receiver retrieves messages from the queue.
- Close receiver.
- Close sender (deletes queue).
Running the Sample
To run the sample:
- Build the solution in Visual Studio.
- Run the sender, inputting service namespace, issuer name, and issuer key when prompted to do so.
- Run the receiver, inputting service namespace, issuer name, and issuer key when prompted to do so.
Expected Output - Sender
Please provide the service namespace to use: <service_namespace> Please provide the issuer name to use: <issuer_name> Please provide the issuer key to use: <issuer_key> Creating Queue 'IssueTrackingQueue'... Sending messages to queue... Asynchronous Message Send Begin: Id = 1, Body = First Package Asynchronous Message Send Begin: Id = 2, Body = Second Package Asynchronous Message Send Begin: Id = 3, Body = Third Package After all messages are sent, press ENTER to clean up and exit. Asynchronous Message Send for Id = 3 Successful Asynchronous Message Send for Id = 2 Successful Asynchronous Message Send for Id = 1 Successful |
Expected Output - Receiver
Please provide the service namespace to use: <service_namespace> Please provide the issuer name to use: <issuer_name> Please provide the issuer key to use: <issuer_key> Receiving messages from queue... After all messages are received, press ENTER to exit. Message Received: Id = 3, Body = Third Package Message Received: Id = 1, Body = First Package Message Received: Id = 2, Body = Second Package Asynchronous Message Receive Completed for Id = 1 Asynchronous Message Receive Completed for Id = 2 Asynchronous Message Receive Completed for Id = 3 |