bob February 2016

how do i get data from azure queue message (service bus)

I need to get data from service bus from my console application, instead of my data I've got System.UnauthorizedAccessException error 401 I've got 2 static readonly string that I don't know how to use You may require one or both of the services below depending on the level of detail that you need-

    //sample usage string briefingDetailsByIdURI = string.Format(Constants.BRIEFING_DETAILS_ID_URI, brfId);

    public static readonly string ID_URI = "https://trtrtrtr.servicebus.windows.net/trtrtr/trttrttr/{0}";



    //sample usage - string URI = string.Format(Constants.sdgsdgg, sgsgsg, sgsgsg);

    public static readonly string DETAIL_ID_URI = "https://trtrtrtr.servicebus.windows.net/trtrtr/trrtrttr/{0}/{1}";

I just went in app.config and put this with the right namespace and password

<appSettings>
<!-- Service Bus specific app setings for messaging connections -->
<add key="Microsoft.ServiceBus.ConnectionString"        value="Endpoint=sb://<namespace>.servicebus.windows.net/;
 SharedAccessKeyName=Root      stManageSharedAccessKey;SharedAccessKey=<paasword> />

after that I went in my console program.cs

Console.Title = "Receiver2";

        // Creating the topic if it does not exist already using the service bus connection string stored in the app.config file
        string connectionString =
            CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
        //appSettings dans appsettings getSettings()

        //connection au service bus
        var namespaceManager =
            NamespaceManager.CreateFromConnectionString(connectionString);
        //verification  si queue existe

        if (!namespaceManager.QueueExists("CommentaireQueue"))
        {
            namespaceManager.CreateQueue("CommentaireQueue");
        }


        QueueClient client = QueueClient.Create("CommentaireQueue");
        C        

Answers


Jeffrey Rosselle February 2016

This is what I use to connect to the queue

QueueClient _client;
        var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
        var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
        if (!namespaceManager.QueueExists(QueueName))
        {
            namespaceManager.CreateQueue(QueueName);
        }

        _client = QueueClient.CreateFromConnectionString(connectionString, QueueName);

Instead of running a while loop. You could be using OnMessage() like this:

_client.OnMessage(message =>
                {
                    try
                    {
                        //do logic
                    }
                    catch (Exception e)
                    {
                        message.Abandon();
                        throw new Exception(e.Message);
                    }
                });

Make sure the connections string is set correct in your Azure ServiceConfiguration:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="App" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
  <Role name="App">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.ServiceBus.ConnectionString" value="THE CONNECTION STRING" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

Post Status

Asked in February 2016
Viewed 2,391 times
Voted 9
Answered 1 times

Search




Leave an answer