How to Receive Notification Through Queue


Get queue information from api

Anyone who wants to receive notification from queue needs to get queue details from api mentioned below.

API Urlhttp://devpoc-api-notification-us-e-001-wapp.azurewebsites.net/api/v1/company/queue?cuId=cuid

This api will return 2 records with priority[0-Normal, 1- High] queue details.

  • {  
       "data":[  
          {  
             "queueName":"<cuid>_high",
             "priority":1,
             "connectionString":"<high priority queue connection string>"
          },
          {  
             "queueName":"<cuid>_normal",
             "priority":0,
             "connectionString":"<normal priority queue connection string>"
          }
       ],
       "count":"2"
    }

Sample code to receive message from queue

Example of receive data from queue in C# is as below:


Using statements

using Microsoft.ServiceBus.Messaging;
using Newtonsoft.Json.Linq;
using System;
using System.IO;


Sample for read queue

var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
client.OnMessage(message =>
{
             var stream = message.GetBody<Stream>();

      //data contains message data.
      var data = JObject.Parse(new StreamReader(stream).ReadToEnd());

});

NOTE: How to implement or read queue message in other languages(e.g. Java, Node.js, PHP etc) are described on below link:

 https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues