Wednesday, 19 July 2017

Get started in Queue, Topic and Subscription in Microsoft Azure

In this post we are going to see how to start in Microsoft Azure for Queue, Topic and subscriptions

Go to the Azure Portal and create a Service Bus Namespace and get a connection string, Next create a queue and Topic

using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
    class Program
        static string connectionString = "Endpoint=sb://;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=sbxireNSHksjqaiorlkms";
        static string QueuePath = "test_queue";
        static string Topicpath = "test_topic";

        static void Main(string[] args)
            // For Queue
            var _queueClient = QueueClient.CreateFromConnectionString(connectionString,QueuePath);

            // sender side for queue
            for (int i = 0; i < 10; i++)
                var message = new BrokeredMessage("Message " + i);

            // receiver side for queue
            _queueClient.OnMessage((mes) => processMessage(mes));

            // sender side For Topic
            string username = "rajesh";
            var manager = NamespaceManager.CreateFromConnectionString(connectionString);

            var subscription = new SubscriptionDescription(Topicpath, username)
                AutoDeleteOnIdle = TimeSpan.FromMinutes(5)

            var factory = MessagingFactory.CreateFromConnectionString(connectionString);
            var topicClient = factory.CreateTopicClient(Topicpath);

            // receiver side for topic that is subscription
            var subClient = factory.CreateSubscriptionClient(Topicpath, username);
            subClient.OnMessage(msg => processMessage(msg));

            var helloMessage = new BrokeredMessage("Has entered Room");
            helloMessage.Label = username;

            while (true)
                string readText = Console.ReadLine();
                if (readText.Equals("exit")) break;

                var readTextMessage = new BrokeredMessage(readText);
                readTextMessage.Label = username;

            var leftMessage = new BrokeredMessage("Left the room");
            leftMessage.Label = username;



        private static void processMessage(BrokeredMessage mes)
            var label = mes.Label;
            var text = mes.GetBody<string>();
            Console.WriteLine("Received " + text);

From this post you can learn how to get started in Queue, Topic and Subscription in Microsoft Azure 

1 comment:

  1. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information about the web design and web development.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    hire developer
    hire dot net developer