Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud

In this article we will introduce a very simple messaging scenario which we will implement using the AppFx.ServiceBus framework to show how easy it can be to get up and running with Windows Azure Service Bus.

In this scenario we want to achieve the following:

  • We want to define a schema for our message which will flow over the wire and generate .net types which can be used to represent this object
  • From a .net client application we want to push a message to a queue in Windows Azure Service Bus
  • In this example we will use JSON serialization format
  • We then want to use the AppFx.ServiceBus console host application to be configured to handle our message
  • We will develop a message handler which will be dll dropped into the console hosts bin directory which will contain our custom code

 

Hopefully that is pretty clear, so now lets walk through the steps to implement it.

 

Setting up Azure Service Bus

The Windows Azure configuration for this particular sample is very easy. We simple need a queue and to ensure we have permissions to access it to send and receive messages.

I'm going to assume at this stage you are already familiar with how to create queues in Windows Azure Service Bus and you know about being able to use the owner credential which is ok for demo purposes.

For this sample we will create a new queue called Sample1-HelloWorld.

The rest of the settings on this queue can remain the default settings.

 

Creating your message

When creating our message with AppFx.ServiceBus we prefer the technique of creating a schema to represent your message. This means we have a good contract for the message which we can then create classes in most programming languages to represent these schemas. This also allows us to serialize an object based on this schema to numerous formats such as XML or JSON.

One convention which we do use which is quite important is borrowed from BizTalk world where we use the combination of xml namespace + root element name to uniquely identify a message. The AppFx.ServiceBus framework will use this to be able to work out how to handle a message and how it can be serialized and deserialized.

An example of this message type from this sample is:

http://contracts/v1.0#UpdateCustomer

Note: Please note the # character used to separate the namespace and root element name

In the sample we will begin in the Contracts c# project. Here we have created a schema in the schemas folder called contracts_v1_0.xsd and we have populated this with a simple definition of a type shown below:

<?xml version="1.0" encoding="utf-16"?>

<xs:schema

id ="Contracts_v1_0"

xmlns="http://contracts/v1.0"

elementFormDefault="qualified"

targetNamespace="http://contracts/v1.0"

xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="UpdateCustomer">

<xs:complexType>

<xs:sequence>

<xs:element name="MessageID" type="xs:string" />

<xs:element name="Name" type="xs:string" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Now you would be able to give this schema to other parties who should be able to create classes from it and use them, but in our very simple demo we will next generate a class from this schema and keep it in the contracts assembly which will be shared either side of the queue just to keep it simple.

In the overridebuild.targets file you will see how we generate the class using svcutil which will produce a class in our contracts assembly.

<Exec Command='"$(SvcUtilPath)\svcutil" /dconly Schema\Contracts_v1_0.xsd /language:C# /serializable /directory:Types /namespace:http://contracts/v1.0,Contracts.Types.Contracts_v1_0' />

 

The contracts assembly is now done and we have a message which we can use in this sample.

Note: If you look in the other samples we will be likely to use this same technique elsewhere so it's worth taking a minute to understand this.

Creating your message handler

In the server project in the sample we will hold our logic to handle the message and do whatever our application needs to with that message. To begin with we will create a class called UpdateCustomer_v1_0_Handler.

This class will implement the IHandleMessage interface so that it can handle messages and work in the AppFx.ServiceBus framework.

In addition to handling this interface we also need to add the MEF (managed extensibility framework) attributes so that during start up the host will identify this class as a message handler and workout what type of messages it handles.

The below snippet shows you what the class looks like when decorated with these attributes:

[Export(typeof(IHandleMessage))]

[ExportMetadata("MessageType", XsdMessageType)]

public class UpdateCustomer_v1_0_Handler : IHandleMessage

{

public const string XsdMessageType = "http://contracts/v1.0#UpdateCustomer";

 

We now have a class which the framework will identify as handling the UpdateCustomer message we defined earlier.

The below picture shows the definition of our message handler class.

 

Just to explain some of those elements of the interface in a little more detail.

Interface Item

Description

HandleRequestResponse

This is the method where your implementation will go if your message handler gets a request response message

Handle

This is the method where your implementation will go if your message handler gets a one way message

InputMessageType

This is the string defining the message type your message handler handles. This is in the xml namespace + root element format

InputClrMessageType

This is the .net message type which your message handler wants the message deserialized to. This will be the type of the class you generated from the schema

HandlesRequestResponseMessages

This is a Boolean indicator to inform the framework if the message handler handles request response messages

HandlesOneWayMessages

This is a Boolean indicator to inform the framework if the message handler handles one way messages

Priority

This is the priority used to workout which message handler to execute if two are in the bin directory handling the same message. The highest priority is executed and others are not.

DeserializeRequestMessage

This indicates if the message handler wants the AppFx.ServiceBus framework to deserialize the request message before handing over execution to the handler. Normally this may be true unless you are executing a handler which is generic

 

In the message handler for our customer update message in this sample we will only be handling one way messages so you will see the implementation in that class to look like below.

For the purposes of the sample we will simply record that we received the message.

Our message handler is now complete and ready to be used.

Note: In the implementation above the logger from the framework will instrument into log4net which is used by the AppFx.ServiceBus framework.

 

Configuring the receive side Host

Next we will configure the AppFx.ServiceBus console host. We could just as easily use the Windows Service Host (which you would be more likely to do in a production scenario) however for the purposes of the demo we will use the console host.

In the server c# project you will see a file called AppFx.ServiceBus.Hosts.Console.exe. This is the file which needs configuration for the host to run and we have kept a copy of it with the server project to make it easier to see how this works.

In this file we currently have two things. There is the configuration for log4net which we will not go into except to say that log messages will be written to the console and also a rolling log file to help you with troubleshooting.

The rest of the configuration is for the receive framework for AppFx.ServiceBus.

In the config file we have firstly declared the sections for AppFx.ServiceBus and also for log4net. As shown below:

Next we have the configuration for any connection strings we wish to use for connecting to the Windows Azure Service Bus namespace. In this case we only have one because most of the samples will run in the same namespace. The below picture shows you the connection string.

 

Next we will implement the AppFx.ServiceBus configuration. The main part to talk about in this sample is the listeners within the appfx.servicebus.receiver section pictured below.

This listeners collection allows you to configure the host to listen to multiple service bus endpoints to process messages. In this example we will listen to the queue called Sample1-HelloWorld using the connection string we defined earlier and we will listen with 3 threads.

The rest of the elements in this configuration we will go through in future samples.

 

At this point if you compile the Server c# project I have modified the build output of this project so that the dll's and the config file will be copied to the ..\Library\AppFx.ServiceBus.Hosts.Console folder which is where the console application is located ready to run.

 

Starting the receive side Host

To start the receive side host simple double click the AppFx.ServiceBus.Hosts.Console.exe application in the ..\Library\AppFx.ServiceBus.Hosts.Console folder.

Because you compiled the server project which copied over our contracts.dll containing our message types, the server.dll containing our message handlers and the AppFx.ServiceBus.Hosts.Console.exe.config file containing our configuration, you should see the console application will fire up and display some trace messages to show you that multiple listener instances are now polling the queue for messages.

The console application will look like the below:

 

The console is now waiting to process messages.

 

Configuring the client

In this sample you now need to refer to the client c# project in the solution. In this project you will see the app.config file which contains our configuration for AppFx.ServiceBus. The below picture shows this:

The connection strings are the same as on the receive side where you will use the Windows Azure Service Bus connection string format.

In the appfx.servicebus.client element you can now add a number of clients. These clients can be referenced from your code to provide settings for sending a message. The example above specifies a client which will point to the Sample1-HelloWorld queue and send messages using JSON.

 

Sending the message from the client

In the client application there is a windows form with a button which will allow you to test sending a message. The code behind this button is as follows:

You can see that you will use the Generic MessagingClient class where you will tell it what type of message you wish to send. You will also supply the client name which refers to your settings in the configuration file.

Next you use the send method, and that will dispatch the message onto the queue.

When you click the button you will get a message box confirming the message has been sent which looks like the below:

 

On the console application side you will spot that very soon after the message is submitted the console text will change to show that your message handler has executed. The text indicates that an update customer message was received and processed and then the host started listening for the next message.

 

 

Summary

Hopefully this article shows you how much simpler AppFx.ServiceBus can make it for you to use Windows Azure Service Bus. The framework should handle all of the plumbing and once your initial configuration of the Azure Service Bus is complete you will be able to focus on your functional code which will involve:

  1. Define message
  2. Create message handler
  3. Send the message
Posted on Sunday, February 3, 2013 6:25 AM | Back to top


Comments on this post: AppFx.ServiceBus - Hello World

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
good Today all the movie fans need to see the films online. There are so many apps accessible, but Mobdro is the most used program Download Mobdro chrome to install Mobdro if you don't have mobdro nice.
Left by ajay on Mar 01, 2016 7:13 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
good which allows one to instantly shareit download to talk about file from different devices like tablet computers, great.
Left by ram on Mar 02, 2016 7:20 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Excellent read! Ive bookmarked your site and Im adding your RSS feed.
Free Android APK download safe link apkdom best safe APK downloader
free download mirror obb server CoC private link. Love fun lovematchfun join now.
Left by Darrel on May 13, 2016 5:08 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
The Best Prank Apps and shocking Games for Android. pranky apps Cracked screen joke, Love Match Detector Prank, transparent screen android app, etc.
Free Android APK download safe link softlot best safe APK downloader.
Left by Gale on May 13, 2016 5:09 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Gift Ideas gifts pilot gifts for her and kids.
Cheers!
<script><!--
Left by Eog on May 13, 2016 5:09 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Extremely it's so nice material shared. I really like the sort of information. Thanks for publish it.,copaamerica.live
Left by helen on May 15, 2016 4:26 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Looking for celebrities information, Well here you can find all worldwide celebrity related info with all details.
Left by Rokcy on Jul 17, 2016 4:09 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Do you know that IMO App was developed by former Google employees also known as Harik brothers named as Ralph Harik and Georges Harik. Being a former part of Google, Harik Brothers' work will be predominantly significant as we compare with the other social messenger applications out there. IMO App for Mobile is capable of delivering messages in low bandwidths too even if signal is week. The IMO App works in microseconds and transfers data within few seconds. The video quality of IMO App is very very good and pretty much equal to any paid app out there like Skype.
Left by James Smith on Aug 14, 2016 5:51 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
you can download world best photo editing app now on your android smartphones. You can download it from here.
Download Prisma Apk
Left by Download Prisma Apk on Aug 22, 2016 11:49 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Thanks for the information, you are great to provide different knowledge to us. Pleas do right something about Halloween Horror Nights
Left by SammyPhilips on Aug 25, 2016 9:14 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I am sure nobody can challenge me on this super amazing fighting game ever.
Tekken 7 Release Date
Left by Pooja Bedi on Aug 27, 2016 9:25 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
One of the relevant post, thanks for sharing it.
micromax mobile under 10000
Left by softmobo on Sep 16, 2016 10:47 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Bigo is a Social Network App.Bigo Is released for Android and iPhones. Bigo Live
Left by Surjit Khiva on Sep 30, 2016 9:07 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
After months of anticipation, Finally Super Mario Run an endless running game is announced for iPhone and Android devices. Super Mario Run APK

Left by Surjit Khiva on Sep 30, 2016 9:08 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Emoj.io Game is combination of Pac-man Game and Agar.io Game. Emoj.io
Left by Surjit Khiva on Sep 30, 2016 9:08 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
great post thanks for sharing this information.
http://www.ihappynewyear2017messages.com/
Left by bigo live downloa on Oct 04, 2016 10:48 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
great post admin thanks for sharing this
Left by bigo live downloa on Oct 04, 2016 10:52 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...

After months of anticipation, Finally Super Mario Run an endless running game is announced for iPhone and Android deviceshumayun Iqbal
Left by jcarry on Oct 20, 2016 5:13 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
No matter how complex it is to root you phone, towelroot lest you do it in 2 mins! And that too, you don't have to connect to a PC!
#doYouEvenTowelRootBro !
Left by Towelroot on Oct 21, 2016 8:26 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Once you know what causes bags under eyes, you can take steps to prevent those bags from developing. The following tips will do help prevent puffy eyes and bags under eyes.
Left by poe ma on Oct 22, 2016 2:03 AM

# forexnewyorkcity.com
Requesting Gravatar...
Awesome Post keep it up guys!
http://www.forexnewyorkcity.com/
Left by Ranbir Sharma on Oct 24, 2016 11:45 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I am happy to see this post here on this website because there are many messaging apps available in the market but here we are looking forward with a complete new scenerio in this field of Messaging. I hope we will succeed. thanks for sharing this post.
For Trading Scottrade
Left by Charles Dan on Nov 02, 2016 9:17 PM

# buy sarees online
Requesting Gravatar...
sarees is a indian traditional dress if u are looking to buy buy sarees online online buy from voonik



Left by voonik on Nov 09, 2016 10:35 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
thanks for posting the informative content surely deserves appreciation
download the latest premium app from the play store apk and enjoy your life
Left by danny doanld on Nov 10, 2016 10:49 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Hopefully this article shows you how much simpler AppFx.ServiceBus can make it for you to use Windows Azure Service Bus. The framework should handle all of the plumbing and once your initial configuration of the Azure Service Bus is complete you will be able to focus on your functional code which will involve:


SHAREit For PC
Clash Of Clans For Computer
Left by Frank Tiger on Dec 08, 2016 2:09 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I am happy to see this post here on this website because there are many messaging apps available in the market but here we are looking forward with a complete new scenerio in this field of Messaging. I hope we will succeed. thanks for sharing this post.

TV Portal APK Download
Clean Master App Download
Left by Frank Tiger on Dec 08, 2016 2:10 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
watch anime online whenever and wherever you want only on href="http://www.appsandapks.com">kissanime you will love all the anime there updating regularly.
Left by tom cruise on Dec 10, 2016 8:12 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
watch anime online whenever and wherever you want only on kissanime you will love all the anime there updating regularly.
Left by tom cruise on Dec 10, 2016 8:14 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. spotify premium apk
Left by kyelaaputri on Dec 12, 2016 4:25 PM

# online shopping
Requesting Gravatar...
Such intelligent work on the subject and ideal way of writing here. Best Shampoo Bowls 2017 I am really impressed! This post is a helpful overview of the particular topic and very actionable. Interesting approach!
Left by kishan on Jan 06, 2017 10:21 PM

# Free 2017 Calendar Download
Requesting Gravatar...
Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Best Shampoo Bowls 2017 Keep up the good work you are doing here.
Left by radhika on Jan 06, 2017 10:36 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
After read a couple of the articles on your website these few days, and I truly like your style of blogging. I tag it to my favorites internet site list and will be checking back soon. Please check out my web site also and let me know what you think. tummy tuck cost
Left by tummy tuck in dubai on Jan 09, 2017 6:42 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Thanks for such post.For Best WhatsApp Status just visit Best WhatsApp Status
Left by Best WhatsApp Status on Jan 16, 2017 10:24 PM

# Assignment Writing Service Australia
Requesting Gravatar...
I personally like your post; you have shared good insights and experiences. Keep it up. Assignment Writing Service Australia

Left by Assignment Writing Service Austr on Jan 31, 2017 6:27 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Pretty helpful material, much thanks for this article Thesis help service

Left by Thesis help service on Jan 31, 2017 7:00 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Science Channel’s are giving a complete knowledge to its viewers about every thing students write done dissertation on this subjects and show its importance.
Finance Assignments
Left by Finance Assignments on Jan 31, 2017 9:36 PM

# Android Application Development Service
Requesting Gravatar...
I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs. Android Application Development Service

Left by Android Application Development on Feb 01, 2017 12:24 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog at PS3 Not Reading Disc Fix. Thanks.
Left by Larry Jones on Feb 07, 2017 8:51 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog at Best Headphones For Running. Thanks.
Left by Larry Jones on Feb 14, 2017 4:45 AM

# WWE WRESTLEMANIA 33
Requesting Gravatar...
I like the helpful information you provide for your articles. I'll bookmark your weblog and test once more right here regularly. I am somewhat certain WWE Wrestlemania 33 2017<> I will be told lots of new stuff right right here! Good luck for the following!
Left by JIO99 on Feb 24, 2017 12:45 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
DHA | Bahria Town Lahore Karachi Islamabad | Sasti Property
Sasti Property Provide Real Estate Services Land Home House Plot for Sale or Rent in DHA Lahore DHA Karachi DHA Islamabad DHA Multan DHA Peshawar and Bahria Town Lahore Bahria Town Karachi Bahria Town Islamabad
http://www.sastipro.pk
Left by sastipro on Mar 09, 2017 8:03 AM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
Wow, I have never come across a website with such comprehensive and detailed information on a particular subject. It displays the seriousness and the commitment of the site owners to convey information to the public. This site will be very useful to students especially those who are pursuing programming courses and it will help them to come up with a Plagiarism Free Case Study.
Left by Plagiarism Free Case Study on Mar 21, 2017 10:08 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
bisa di andalkan kaya nya
Left by kikin on Mar 22, 2017 6:26 PM

# re: AppFx.ServiceBus - Hello World
Requesting Gravatar...
I like the helpful information you provide for your articles. I'll bookmark your weblog and test once more right here regularly. I am somewhat certain Calendar
I will be told lots of new stuff right right here! Good luck for the following!

Left by raj on Apr 19, 2017 8:35 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Stephenson | Powered by: GeeksWithBlogs.net