Export (0) Print
Expand All

Step 3: Send Messages to the Queue

Updated: January 22, 2014

This is the third step in the Service Bus messaging features tutorial. In this step, you create the queue, then send the messages contained in the list of brokered messages to the queue.

To create and send messages to the queue

  1. First, create the queue. For example, call it myQueue, and declare it directly after the management operations you added in the last step:

    QueueDescription myQueue;
    myQueue = namespaceClient.CreateQueue("IssueTrackingQueue");
    
  2. In the Queue() method, create a messaging factory object with a newly-created Service Bus URI as an argument. Add the following code directly after the management operations you added in the last step:

    MessagingFactory factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty), credentials);
    
  3. Next, create the queue object using the QueueClient class. Add the following code directly after the code you added in the last step:

    QueueClient myQueueClient = factory.CreateQueueClient("IssueTrackingQueue");
    
  4. Next, add code that loops through the list of brokered messages you created and populated in Step 1 of the tutorial, sending each to the queue. Add the following code directly after the CreateQueueClient() statement in the previous step:

    // Send messages
    Console.WriteLine("Now sending messages to the Queue.");
    for (int count = 0; count < 6; count++)
    {
        var issue = MessageList[count];
        issue.Label = issue.Properties["IssueTitle"].ToString();
        myQueueClient.Send(issue);
        Console.WriteLine(string.Format("Message sent: {0}, {1}", issue.Label, issue.MessageId));
    }
    

Community Additions

ADD
Show:
© 2014 Microsoft