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:

  1. Start a sender.
    1. Sender prompts for user Service Bus credentials.
    2. Sender creates queue.
    3. Sender sends messages to queue.
  2. Start a receiver.
    1. Receiver retrieves messages from the queue.
    2. Close receiver.
  3. Close sender (deletes queue).

Running the Sample

To run the sample:

  1. Build the solution in Visual Studio.
  2. Run the sender, inputting service namespace, issuer name, and issuer key when prompted to do so.
  3. 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
                    

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