how do i get data from azure queue message (service bus) -
i need data service bus console application, instead of data i've got system.unauthorizedaccessexception error 401 i've got 2 static readonly string don't know how use may require 1 or both of services below depending on level of detail 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 went in app.config , put right namespace , password
<appsettings> <!-- service bus specific app setings messaging connections --> <add key="microsoft.servicebus.connectionstring" value="endpoint=sb://<namespace>.servicebus.windows.net/; sharedaccesskeyname=root stmanagesharedaccesskey;sharedaccesskey=<paasword> />
after went in console program.cs
console.title = "receiver2";
// creating topic if not exist using service bus connection string stored in 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"); console.writeline("test console"); //boucle infini pour recevoir tous les messages while (true) { var message = client.receive(); if (message != null) { var comm = message.getbody<string>(); string mystring = comm.contenu; try { console.writeline(mystring); } { //enlever le message de la queue message.complete(); } } } }
this use connect 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 while loop. using onmessage() this:
_client.onmessage(message => { try { //do logic } catch (exception e) { message.abandon(); throw new exception(e.message); } });
make sure connections string set correct in 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>
Comments
Post a Comment