Windows Azure Brokered Messaging Main Classes

Posted: August 22, 2013 in Live in a Cloudy World, Windows Azure

I have blogged previously on the Brokered Messaging API but in this blog I will get more deeper, with some technical examples that maybe it will help clarify how to best use the services bus brokered Messaging classes. You can also find the best practices for using the Windows Azure Service Bus Brokered Messaging in a previous blog post.

The Windows Azure Service Bus
Brokered Messaging has several main classes that are mainly used to deliver basic development for your application. You will have to use these classes:

  • BrokeredMessage: is the type of the message that will be send from an application through the service bus
  • QueueClient: is the client that you have to create to handle all the instructions when using the Windows Azure Brokered Messaging Queue
  • QueueDescription: handle all the metadata of the queue.
  • TopicClient: is the client that you have to create to handle all the instructions when using the Windows Azure Brokered Messaging Topic/Subscription.
  • TopicDescription: handle all the metadata of the topic created.
  • SubscriptionClient: is the client that you have to create to handle all the instructions for the subscriptions when working with the Windows Azure Messaging Topic/Subscription
  • SubscriptionDescription: handle all the metadata for the subscription you create.
  • NamespaceManager: is responsible for runtime of the operations of the service bus messaging entities from inserting, creating, deleting and so on.
  • MessagingFactory: is responsible for tracking, monitoring and handling the lifecycle of the message
  • MessageReciver: this is the class responsible for receiving the Brokered Message from the sender application
  • MessageSender: this is the class responsible for sending the Brokered Message from an application to another
  • MessageSession:
  • Filter: helps you filter the messages according to topics so you can easily send the brokered message to its exact target application.
  • TokenProvider: is the security token that you will need to use for initiating a new instance of messaging factory and namespace manager.

You can have a look on the Service Bus namespaces from the following 2 documents, the first one is an overview on the Microsoft.ServiceBus Namespace and the second one is the Microsoft.ServiceBus.Messaging Namespace.

Here is a simple example for starting developidng Windows Azure Service Bus Brokered Messaging, the queue using the .NET.

The following code example is for those who are interested to start developing Windows Azure Service Bus using the Node JS for both the Windows Azure Service Bus Brokered Messaging whether using queue:

//creating Windows Azure Service bus Brokered Message using queue

 

//here is a brief explanation

//the initialization is very sample

// the main three functions are, creating the queue, sending the message and receiving the message

 

var azure = require(‘azure’);

var queuename = ‘queuename’;

var queuemsg = ‘the msg you want to send through the queue’;

 

var sbclient = azure.createServiceBusService();

 

//function to create the Windows Azure Service bus Queue

function createSBQueue(){

    sbclient.createQueue(queuename, function(error){

    if(!error){

        console.log(“Queue Created”);

    }});

}

 

//function to send through the Windows Azure Service Bus Queue created

function sendQueueMsg(){

    sbclient.sendQueueMessage(queuename, queuemsg, function(error){

    if(!error){

        console.log(“Queue Message delivered”);

    }});

}

 

//function to receive from the clients through the Windows Azure Service Bus Queue Created

function receiveQueueMsg(){

    sbclient.receiveQueueMessage(queuename, function(error, message){

    if(!error){

        console.log(message.body);

    }});

}

or Topic/Subscription:

//creating Windows Azure Service bus Brokered Message using queue

 

//here is a brief explanation

//the initialization is very sample

//four functions are needed, one to create the topic, the second to create the subscription

//the third for sending the message to a subscription and the fourth to receive the message

 

var azure = require(‘azure’);

 

var topic = ‘topicname’;

var subsc = ‘subscriptionname’;

 

var msg = ‘my msg’;

 

var sbclient = azure.createServiceBusClient();

 

//function to create the topic

function createTopic(){

    sbclient.createTopic(topic, function(error){

        if(!error){

            console.log(‘Topic Created’);

        }});

}

 

//function to create the subscription

function createSub(){

    sbclient.createSubscription(subsc, function(error){

        if(!error){

            console.log(‘Subscription Created’);

        }});

}

 

//function to send a message

function sendMsg(){

    sbclient.sendTopicMessage(topic, msg, function(error){

        if(!error){

            console.log(‘Message sent’);

        }});

}

 

//function to receive a message

function receiveMsg(){

    sbclient.receiveSubscriptionMessage(topic, subsc, function(error, message){

        if(!error){

            console.log(message.body);

        }});

}

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s