title: How to read message off azure service bus
body: <p>I'm trying to read a message off the queue (notified rather than polling) using C# azure function.</p>
  
  <p>I'm currently pushing a message onto the queue using a console app for now, see below.</p>
  
  <p>There seems to be two different products, azure service bus and a queue within a storage account.  The following code uses the later, I'm not sure how to read the message of the queue?</p>
  
  <p>Many thanks,</p>
  
  <p><strong>Code example</strong></p>
  
  <pre><code>StorageCredentials creds = new StorageCredentials(accountname, accountkey);
          CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
          CloudQueueClient queueClient = account.CreateCloudQueueClient();
          CloudQueue queue = queueClient.GetQueueReference("test-queue");
          queue.CreateIfNotExists();
          while (true)
          {
              CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject("my message"));
              queue.AddMessage(message);
          }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>After the comments and following links as suggested by experts trying to help I have tried the following code sample to push a message onto Azure Service Bus (i.e not a queue in a storage account)</p>
  
  <pre><code>namespace ConsoleApp1
  {
      using System;
      using System.Text;
      using System.Threading.Tasks;
      using Microsoft.Azure.ServiceBus;
  
      class Program
      {
          const string ServiceBusConnectionString = "Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=xxx;SharedAccessKey=xxx";
          const string QueueName = "name_of_queue";
          static IQueueClient queueClient;
  
          public static async Task Main(string[] args)
          {
              const int numberOfMessages = 10;
              queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
  
              await SendMessagesAsync(numberOfMessages);
  
              await queueClient.CloseAsync();
          }
  
          static async Task SendMessagesAsync(int numberOfMessagesToSend)
          {
              for (var i = 0; i &lt; numberOfMessagesToSend; i++)
              {
                  string messageBody = $"Message {i}";
                  var message = new Message(Encoding.UTF8.GetBytes(messageBody));
  
                  Console.WriteLine($"Sending message: {messageBody}");
  
                  // Send the message to the queue
                  try
                  {
                      await queueClient.SendAsync(message);  // this line
                  }
                  catch (Exception ex)
                  {
                      throw ex;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>When I run the code above the console window doesn't do anything, no error message just nothing..!  strange..  Looking in the azure service bus overview it active message count is zero.</p>
  
  <p>I'm using this sample project but the queueClient.SendAsync never returns back.  Do I need to set something up in azure, permissions perhaps?</p>
  
  <p><a href="https://github.com/Azure/azure-service-bus" rel="nofollow noreferrer">https://github.com/Azure/azure-service-bus</a></p>
  
  <p><strong>Error eventually received</strong></p>
  
  <blockquote>
    <p>A connection attempt failed because the connected party did not
    properly respond after a period of time, or established connection
    failed because connected host has failed to respond</p>
  </blockquote>
  
  <p>I can see requests within the portal service bus screen</p>