//Cloud notes from my desk -Maheshk

"Fortunate are those who take the first steps.” ― Paulo Coelho

All about Azure Service Bus -messaging services

Recently I had a chance to read about various Azure Application Services(Messaging) like Azure Queues, Azure Service Bus – Queues, Topics, Relay, Event Hub and Notification hubs.

I was curious to know what is all this from an Architect’s perspective. As a dev, one can start quickly with samples from official documentation. But I was trying to understand when to use what – key differentiator and competitor offerings etc.. I have tried few samples some time back but never bothered to compare and learn. Coming to documentation, I have to appreciate our Azure content team for their excellent documentation and easy information dissemination. Learning path(diagrams) is something which is easy to follow and understand the contents in high level. DISQUS comment integration also add’s lot of value to the reader – one can interact with the author,fellow reader and also report any issues. Kudos guys.

One can consume these service/offerings from Azure management portal as below. You may not find them in preview portal as of now – but you will be redirected if they have not supported yet.

      clip_image002

For majority of these service, Microsoft.ServiceBus.dll is the important assembly to refer. You can get it from Nuget easily by simply running the below command in your Visual Studio > Tools > Nuget Package Manager >Package Manager Console. You should have corresponding project created say Console application and then run this. You would notice the relevant assemblies added behind the scene automatically downloaded from net. For detailed assembly reference please check this link – Service Bus .NET

PM> Install-Package WindowsAzure.ServiceBus

Let us start checking one by one..

1) Service Bus Queues 

  • if you’ve worked earlier with MSMQ, then this is the same except the message is stored in/read from Cloud with features like Auto scale, backup etc.
  • offers one-directional – FIFO communication; designed to read sequentially. We just insert them-> process and delete. (1 MESSAGE : 1 READ/RECIEVER)
  • a sender sends a message to a <Service Bus queue> and a receiver picks up that message at some later time/offline processing
  • message can be sent from ‘n’ senders but picked by one receiver(1 message/receiver). For multicast service – we should consider “Topics”(below) instead Queue
  • message has two parts: a set of properties, each a key/value pair, and a binary message body. It can be considered for implementing state machine.

 

          clip_image004

2) Service Bus Topics 

  • similar in many ways to a queue, provides one-directional communication using subscriptions-a single topic can have multiple subscriptions; use a filter to receive only messages matching the declared criteria.
  • big difference is that topics let each receiving application create its own subscription by defining a filter.
  • Ex: In the below pic, Sub1 using a filter Seller =“AVA” receives only such matching message. Single message sent to a topic can be received by multiple subscribers ((ONE TOPICS CAN HAVE MANY RECIEVERS)
  • this publish and subscribe model can considered for multiple app interested in the same messages.

 

          clip_image006

· 3) Relays

  • provides bi-directional communication, doesn’t store in-flight messages, it just passes them on to the destination application.
  • each application establishes an outbound TCP connection with Service Bus, then keeps it open.
  • to use Service Bus relays, applications rely on WCF. Service Bus provides WCF bindings that make it straightforward for win applications to communicate with relays.
  • it is perfect for enabling communication between different application over cloud to an on premise datacenter.
  • it gets deleted when the connection goes off or closing the host
  • mainly recommended for exposing WCF from a corporate n/w to public cloud without opening firewall connection.

          clip_image008

Service Bus messaging is a brokered communication mechanism. Similar to a postal service in the physical world. The messaging service ensures that the information is delivered even if the two parties are never both online at the same time. Service Bus supports two distinct messaging patterns: relayed messaging and brokered messaging. Earlier one provides many benefits, but requires both to be online at the same time in order to send and receive messages. In contrast to the relayed messaging scheme, brokered messaging can be thought of as asynchronous, or “temporally decoupled.” – both parties do not have to be online at the same time. 

4) Event Hubs 

  • highly scalable publish-subscribe event ingestor that can asynchronously intake millions of events per second. It act as a “front door” for an event pipeline, often called an event ingestor.
  • supports HTTP POST or via an AMQP 1.0
  • best suits for processing and analyzing the massive amounts of data produced by IOT devices or any other connected apps
  • some real world scenarios:
  • IOT devices sending thousands of message/second which is processed, stored and displayed in live dashboard’s,
  • behavior tracking in mobile apps or traffic information from web farms, or data collected from machines or vehicles

            clip_image010

Let us see how easy to create a WCF Relay(this blog sample-download here) – referred from this blog here.

=================================================

Interface:

[ServiceContract(Namespace = “urn:ps”)]

interface IProblemSolver{

[OperationContract]

int AddNumbers(int a, int b);

}

interface IProblemSolverChannel : IProblemSolver, IClientChannel { }

Server:

========

static void Main(string[] args) {

var cf = new ChannelFactory<IProblemSolverChannel>(new NetTcpRelayBinding(),

new EndpointAddress(ServiceBusEnvironment.CreateServiceUri(“sb”, “HelloWCFServiceThroughAzure”, “solver”)));

cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior {

TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(“RootManageSharedAccessKey”, “yourkey”)

});

Console.WriteLine(“Azure Service Relay Client- Started “);

using (var ch = cf.CreateChannel()) {

Console.WriteLine(ch.AddNumbers(4, 5));

}

Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine(“Azure Service Relay Client- Finished Reading. ENTER to close the client”);

Console.ReadLine();

}

class ProblemSolver : IProblemSolver {

public int AddNumbers(int a, int b) {return a + b; }

}

Client:

=======

static void Main(string[] args) {

var cf = new ChannelFactory<IProblemSolverChannel>(new NetTcpRelayBinding(),

new EndpointAddress(ServiceBusEnvironment.CreateServiceUri(“sb”, “HelloWCFServiceThroughAzure”, “solver”)));

cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior {

TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(“RootManageSharedAccessKey”, “yourkey”)

});

Console.WriteLine(“Azure Service Relay Client- Started “);

using (var ch = cf.CreateChannel()) {

Console.WriteLine(ch.AddNumbers(4, 5));

}

Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine(“Azure Service Relay Client- Finished Reading. ENTER to close the client”);

Console.ReadLine();

}

Output:

=======

Both are console application, required nuget assemblies(service bus assemblies) installed. Run the server application first which will create the relay name in the Azure Portal. Once after the name, you can your client application. When you stop the server, then the relay gets deleted automatically. 

In Action:

==========

clip_image012

Links to start : https://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-queues/

See you next time with various cloud patterns associated with messaging..

//happy messaging

Advertisements

2015-09-13 Posted by | Uncategorized | , , , | Leave a comment

How to automate your Azure Infra tasks using Azure Automation?

We always wanted to shut down our VM’s when not in use so that we can save our subscription bill amount. But many times, we forget to stop it resulting $0 credit 😦 like me below. clip_image001

 

 

 

 

This not only affects our ongoing cloud developments but affects our important hosted apps in production. Yes, recently I published an Office Add in/Apps to the store(production) which is not available now. At present, we do not have an option to allot or block certain amount of credit towards an app so that such critical production would continue.. Any one aware of blocking the credits to different offerings?

Side note : Just learned from here –> Amazon EC2 instances are billed by the “hour” as opposed to by the “minute” with Azure.

Let us talk about how we can automate certain Azure infra tasks like auto shutdown or deallocate after testing using Azure Automation. This blog post is based on our PFE blog but wanted to try first-hand experience to start as blog. I encourage you to try at your phase, so that it gives good idea exploring various options and possibilities with PowerShell. Most importantly. you can reuse the same automation for your real time resource management down the line. Ok, let’s start.

Microsoft Azure Automation

provides a way to automate a simple <-> complex manual infra tasks, often repeated or could be a long running, error-prone activities performed by devops(mostly) during testing/deployment can be easily be automated using scripting (PowerShell). You can reuse the same script for DEV, TESTING, STAGING and PROD environment easily for similar replication/setup. Let me break down in points for easy understanding..

  • It also help us to create, supervise, manage and deploy resources to azure using runbooks (Windows PowerShell workflows)
  • You can schedule it for Day/Monthly/yearly so that it can trigger and run the jobs as scripted. It’s kind of a scheduler for managing Azure resources.
  • The runbooks contains the PowerShell works easily with resources like Azure Websites, VM’s, Storage, SQL Server, and other popular Azure services using command lets.
  • Another good candidate, we can also manage windows updates, auto backups/recovery, copy files to storage, prepare machines for deployment etc..
  • Best part is, one can see the job status and result in the portal. It also gives the nicer dashboard displaying failed request, queued jobs and stopped etc.

Note : For this hands-on, you should have a valid azure subscription. If you have got MSDN account, then you could activate it under MSDN subscription page as below or try this link for free trial – https://azure.microsoft.com/en-us/pricing/free-trial/

clip_image002

Microsoft Azure Automation – Overall execution

clip_image003

Let us see it in action:

1) How to start the Automation from Azure old portal or management portal – http://manage.windowsazure.com/

clip_image004

2) Same thing you can try it from Preview Portal also, but we are going to see how to use the management portal for the rest of the hands on –

clip_image005

3) After creating the Automation a/c from the Step1, now click on Assets > Add Settings for adding the credential passed as known value.

clip_image006

clip_image007

4) Enter the credential of the co-admin account. For creating Co-Administrator, please refer here – Azure Automation: Authenticating to Azure using Azure Active Directory http://azure.microsoft.com/en-us/blog/azure-automation-authenticating-to-azure-using-azure-active-directory/

clip_image008

5) Now, let us go ahead and add the Runbook as below.

clip_image009

6) Now, you would get the default workflow as below. Go ahead and copy the below PowerShell script. Make sure, our workflow name and our runbook name should be same. This is very important. Right now we are going to create runbook for Starting our VM’s.

clip_image010

workflow start-my-sharepoint2016-testing {

$cred = Get-AutomationPSCredential -Name “Azure-Automation-Cred”

Add-AzureAccount -Credential $cred

Start-AzureVM -ServiceName “sharepoint216” -Name “sharepoint2016”

}

7) Now save the changes and publish it, so that you can do the scheduling.

clip_image011

clip_image012

clip_image013

8) Let us test by executing it manually..clip_image014

clip_image015

clip_image016

9) Now, I see the VM has started, similarly you can do it for stopping the VM at your scheduled time.

clip_image017

For stopping VM,

workflow Stop-VM-Testing {

$cred = Get-AutomationPSCredential -Name “Azure-Automation-Cred”

Add-AzureAccount -Credential $cred

Stop-AzureVM -ServiceName “sharepoint216” -Name “sharepoint2016” -force

}

I suggest this free ebook from MVA for further detailed documentation about its possibilities and advanced reading :  http://www.microsoftvirtualacademy.com/ebooks#9780735698154 

clip_image018

Starter links:

 

See you next time with some other interesting stuff..

//Happy reading.

2015-09-12 Posted by | Uncategorized | , , , | Leave a comment

My first blog post in MSDN

All,

There is always an excitement and authentic feel when we read/blog/refer any of the MSDN Tech blogs. I follow quite a bunch of MSDN blogs and always prefer reading over any other non-Microsoft blog post. I start referring first -MSDN documentation and then PG team blog or PM’s blog for better clarity.

Blogging is not new to me, Yes -I have an award winning blog at https://maheshkumar.wordpress.com/ (awarded by our Steve Ballmer) writing for the past 10+ years in WordPress medium(started originally in Live.spaces.com later moved). Being a blogger, I always love to share the interesting tech stuff/code which I read and tried for better understanding and also valuable feedback from readers. I greatly believe in learning by sharing

About me: I am a passionate C#.NET developer & technologist started my career in 2004. I had an opportunity to work with various Microsoft Technology projects in Web and Windows for the companies like Sobha Renaissance IT, Sapient Global Markets and Thomson Reuters. I stared as dev for ASP.NET 2.0, then Window forms, back end developer(Windows/ Web services/WCF) etc. Mostly worked on WPF/XAML winform development, performance tuning, design and delivery products for Healthcare, Trading & Financial market domain. Currently I work for Microsoft as Technical Evangelist for Azure assisting ISV’s to grow bigger.

My hobby & passion: I have an innate passion for building/studying/architecting enterprise software systems. I follow Cloud news from the initial stage(early adaptor) and tried various hands-on offerings from Azure and AWS stack. Apart from technical stuff, I spend time with family & friends, market news, travelling, @MahesKBlr and reading strategy books.

What to expect here: I have told myself and going to limit by blogging only codes/hands on experience with Microsoft Technology offerings –.NET /XAML/Services/Azure/Cloud/tips. 

** Certified 70-487 –Developing Microsoft Azure and Web Services

** Certified 70-532Developing Microsoft Azure Solutions 

** Docker certification from Lynda.com

** Linux certification from Udemy.com

Some of my all time favorite quotes:

  1. “Learning to write programs stretches your mind, and helps you think better, creates a way of thinking about things that I think is helpful in all domain” – Bill Gates
  2. “Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” – Thomas A. Edison
  3. “The snake which cannot cast its skin has to die.” -Friedrich Nietzsche
  4. “You have a dream. Go get it. Period.” -Chris Gardner

// Happy Blogging !

***************************************************************************************************************************************************************************

A Quick Disclaimer: The views and opinions expressed in this blog are my mine and not of my employer! Any feedbacks and suggestions are most welcome..

***************************************************************************************************************************************************************************

2015-09-09 Posted by | Uncategorized | | 3 Comments

   

%d bloggers like this: