Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Mass Transit - Part 2 of N

Last week I posted the first in a series on Mass Transit, an open source enterprise messaging system.  This series is my public exploration into messaging for our eCommerce application.  In this post I'm going to dig in to see an actual working example.  I like to see something work, then dig in to figure out how it's all put together.  We'll take a look at a simple publish subscribe example to see the messaging in action.  In later posts we'll dig in deeper into the guts of MassTransit.  That said, let's see some MassTransit in action!

Getting Started

I've downloaded the MassTransit source from the Google Code repository and am going to run one of the samples provided with the source.  We'll look at their "PublishSubscribe" sample.

image

Project Structure

image Opening the solution reveals nine projects, a few more than what I would consider a simple sample, however don't let the solution scare you away.  It turns out that you can for the most part ignore five of the projects, the mass transit infrastructure projects.

There are four parts to this solution that are relevant and we'll focus on those:

  • Client - The client represents the application that wishes to leverage messaging.  It plays the role of publisher in this example.  It is worth noting however that in this example, as we'll see, this project is also a subscriber.
  • Security Messages - This is a pretty simple project as it should be.  This project encapsulates the strongly typed messages that will be passed throughout the system.  By having the messages in their own light-weight assembly we can keep our messages separate for their consumers.
  • Server - This project acts as the subscriber.  In a normal scenario this server may be sending out emails or logging particularly interesting things as messages come through or whatever else you may have a need for.  Like the client project, we'll see that this project also plays dual roles, the subscriber as mentioned and also a publisher.
  • SubMgr - The subscription manager, is quite a mystery to me.  It may not be obvious, but the subscription manager is needed to get everything to work.  As Dru explains it to me, it is the glue.  In my first go around with MassTransit, I created a client and server and was frustrated when nothing was working.  Talking with Dru, he quickly pointed out my error, I had no Subscription manager.  In the following posts I hope to clear up some of the mystery for myself around the subscription manager.  My understanding at this point of the subscription manager, which may be a bit simplistic, is that it pushes the messages to each of the queues which are interested in the message.  A publisher publishes a message, the subscription manager is the one that ensures that it ends up in the appropriate queue(s) for consumption by various subscribers.

Getting Setup

image In order to get this sample going you first have to create the MSMQ queues that this sample expects:

  • mt_client
  • mt_pubsub
  • mt_server

You can create these queues in the Message Queuing area of the Services and Applications snap-in in the computer management area on your computer.

Seeing Is Believing

Now that we've got the project set up let's fire it up and see what we get.  Since we need all three applications running at once, the client, server, and subscription manager we can take advantage of a cool feature in Visual Studio, multi-project startup.

With multi-project startup you start any number of projects in your solution.  From the properties dialog for the solution we can choose which projects we want to kick off.  (It is worth noting the order in which I have these projects launching.)

image

What's Going On

When you run this example, the client application will ask you to enter a new password.  When you type in a new password  you will get a nearly instantaneous response letting you know the password was updated.

image 

The thing to bear in mind here is that at the point you hit the <enter> key submitting your new password, the client publishes a message and then it is done.  It appears instantaneous but you'll want to keep in mind that it is asynchronous.

The Flow Of It All

image The diagram to the right illustrates what is going on once you hit the <enter> key.

  1. The client publishes a RequestPasswordUpdate message (see the Security Messages project in the solution for this message object).
  2. The server in this case consumes the RequestPasswordUpdate message.  When it is notified of the message, it logs the new password, then...
  3. The Server publishes a new PasswordUpdateComplete message.
  4. The client consumes the PasswordUpdateComplete message and in so doing writes to the console that the password update is complete.

It is worth noting here that the client knows nothing of the server and the server knows nothing of the client.  Our example could easily expand to have multiple clients (think for example a windows app or multiple web servers in a farm).  Likewise there could be multiple server instance, each consuming different messages.  In other words, we are very loosely coupled, which is a good thing.

Conclusion

I hope this introduction to the MassTransit was beneficial.  Now that we've seen the example working, in the next post I'll revisit the idea of durability.  We'll augment this example and simulate a breakdown in infrastructure and see what durability really means, which is really at the heart of this fantastic open source library.


Posted 10-21-2008 10:28 PM by Tim Barcz
Filed under:

[Advertisement]

Comments

Reflective Perspective - Chris Alcock » The Morning Brew #206 wrote Reflective Perspective - Chris Alcock &raquo; The Morning Brew #206
on 10-22-2008 3:32 AM

Pingback from  Reflective Perspective - Chris Alcock  &raquo; The Morning Brew #206

Javier Lozano wrote re: Mass Transit - Part 2 of N
on 10-22-2008 10:24 AM

damn, that's a lot of time spent on a blog post! :)  Great stuff!!

Ben Scheirman wrote re: Mass Transit - Part 2 of N
on 10-22-2008 11:22 AM

Thanks for these write-ups.  I'm liking this style of architecture more and more.

This project seems like a bad example though...  what's to stop me (a malicious employee) from setting up another service that consumes the RequestPasswordUpdate message and logs all the new passwords somewhere?

How does MT address privacy/security?  Does it just recommend encryption at both ends?  Or does MT take a more active approach?

Dew Drop - October 22, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - October 22, 2008 | Alvin Ashcraft's Morning Dew
on 10-22-2008 11:25 AM

Pingback from  Dew Drop - October 22, 2008 | Alvin Ashcraft's Morning Dew

Ayende Rahien wrote re: Mass Transit - Part 2 of N
on 10-22-2008 2:50 PM

Ben,

Typically, you encrypt such messages.

Security is at a higher level, although it would be pretty easy to have a subscription manager that actively managed security

kacibray wrote re: Mass Transit - Part 2 of N
on 09-26-2010 6:29 PM

prepared disputed retreat

best bookmarking sites wrote re: Mass Transit - Part 2 of N
on 01-17-2013 1:40 PM

OpdaNI I value the post.Thanks Again. Fantastic.

http://bestmedicineonline.info/ wrote re: Mass Transit - Part 2 of N
on 01-27-2013 7:27 AM

7jh6V0 Im grateful for the post.Much thanks again. Will read on...

loss weight pills wrote re: Mass Transit - Part 2 of N
on 02-01-2013 2:55 AM

VLS8LU Thanks for sharing, this is a fantastic post. Great.

buy viagra online wrote re: Mass Transit - Part 2 of N
on 02-02-2013 9:17 AM

aqp61Q I appreciate you sharing this article. Awesome.

buy clomid no prescription wrote re: Mass Transit - Part 2 of N
on 02-28-2013 7:24 AM

nWr4Cl Really informative article.Really thank you! Really Great.

social bookmarking service wrote re: Mass Transit - Part 2 of N
on 03-22-2013 10:13 PM

VQ8LzU Thanks a lot for the post.Really looking forward to read more. Really Great.

buy social bookmarks wrote re: Mass Transit - Part 2 of N
on 04-03-2013 6:10 PM

CLyfnn I really like and appreciate your blog article.Really looking forward to read more. Great.

bears wrote re: Mass Transit - Part 2 of N
on 04-05-2013 9:19 PM

I really liked your blog post.Thanks Again. Awesome.

buy social bookmarks wrote re: Mass Transit - Part 2 of N
on 04-08-2013 2:43 AM

DCZJ3T Thank you ever so for you article post.Really looking forward to read more. Want more.

buy social bookmarks wrote re: Mass Transit - Part 2 of N
on 04-13-2013 5:58 AM

AsNCIJ I truly appreciate this article post.Thanks Again.

buy social bookmarks wrote re: Mass Transit - Part 2 of N
on 04-19-2013 5:48 PM

72tI40 Thanks for the blog post.Really looking forward to read more. Will read on...

buy social bookmarks wrote re: Mass Transit - Part 2 of N
on 04-23-2013 11:40 AM

jVIt8K I value the article post.Thanks Again. Want more.

camera buying guide wrote re: Mass Transit - Part 2 of N
on 05-14-2013 11:02 AM

ZxoYTO Great blog post.Thanks Again. Will read on...

social bookmarking service wrote re: Mass Transit - Part 2 of N
on 06-06-2013 11:45 PM

mNSKGR I am so grateful for your article.Really thank you! Want more.

social bookmarks wrote re: Mass Transit - Part 2 of N
on 06-19-2013 7:58 AM

WwWtOB Thanks for sharing, this is a fantastic blog article.Really thank you! Much obliged.

good social bookmarks wrote re: Mass Transit - Part 2 of N
on 06-20-2013 10:10 PM

3CwczZ I really liked your blog post.Much thanks again. Awesome.

great service wrote re: Mass Transit - Part 2 of N
on 07-04-2013 8:53 AM

UPWxQS Appreciate you sharing, great blog. Will read on...

cool news wrote re: Mass Transit - Part 2 of N
on 07-08-2013 6:13 PM

FBE0oq Awesome article post.Really looking forward to read more. Great.

buy viagra online cheap wrote re: Mass Transit - Part 2 of N
on 07-23-2013 5:48 PM

Fantastic article post. Much obliged.

here wrote re: Mass Transit - Part 2 of N
on 07-24-2013 7:30 PM

I truly appreciate this article post.Thanks Again. Really Cool.

cheap social bookmarks wrote re: Mass Transit - Part 2 of N
on 07-28-2013 10:37 AM

Uj1gQ2 Awesome article.Thanks Again. Really Cool.

best news wrote re: Mass Transit - Part 2 of N
on 08-02-2013 10:40 AM

Im obliged for the blog article.Really thank you! Keep writing.

best news wrote re: Mass Transit - Part 2 of N
on 08-03-2013 4:59 PM

hUGIVY Fantastic article.Really looking forward to read more. Will read on...

awesome links for you wrote re: Mass Transit - Part 2 of N
on 08-19-2013 8:54 AM

nRZ0SD Really informative article post. Awesome.

awesome links for you wrote re: Mass Transit - Part 2 of N
on 08-19-2013 8:31 PM

tnGmJP Enjoyed every bit of your blog article.Really looking forward to read more. Great.

awesome links for you wrote re: Mass Transit - Part 2 of N
on 08-21-2013 4:53 AM

5drYrN Very good post.Thanks Again. Will read on...

buy viagra online cheap wrote re: Mass Transit - Part 2 of N
on 09-02-2013 1:55 PM

I really enjoy the article post.Really thank you! Great.

best link building wrote re: Mass Transit - Part 2 of N
on 09-04-2013 12:27 AM

ndOWc7 A round of applause for your blog.Really thank you! Really Cool.

the best seo service wrote re: Mass Transit - Part 2 of N
on 09-07-2013 4:28 AM

jSMksa I appreciate you sharing this blog post. Want more.

visit now wrote re: Mass Transit - Part 2 of N
on 09-08-2013 6:41 AM

Fantastic post.Much thanks again. Really Cool.

only for 5 dollars wrote re: Mass Transit - Part 2 of N
on 09-13-2013 5:24 PM

Sk1DEA This is one awesome post. Much obliged.

awesome link building wrote re: Mass Transit - Part 2 of N
on 09-24-2013 1:48 PM

BdoGfb A big thank you for your blog article.Thanks Again. Will read on...

awesome linkbuilding site wrote re: Mass Transit - Part 2 of N
on 09-30-2013 10:41 PM

Yusic6 Thanks so much for the blog post.Thanks Again. Will read on...

link building team wrote re: Mass Transit - Part 2 of N
on 10-16-2013 10:48 AM

snD9W8 Really informative post.Much thanks again. Keep writing.

top seo guys wrote re: Mass Transit - Part 2 of N
on 10-30-2013 5:36 PM

zFYTlQ I think this is a real great article.Really looking forward to read more.

click here wrote re: Mass Transit - Part 2 of N
on 11-18-2013 12:12 AM

l81kGj Thanks for the blog article.Thanks Again. Fantastic.

awesome site wrote re: Mass Transit - Part 2 of N
on 11-20-2013 10:14 PM

91WIKy Very informative post.Much thanks again. Really Great.

seo service wrote re: Mass Transit - Part 2 of N
on 12-15-2013 2:09 AM

AMKHqk I appreciate you sharing this blog. Great.

check it out wrote re: Mass Transit - Part 2 of N
on 01-10-2014 3:43 AM

88ErSz I cannot thank you enough for the article. Great.

nice seo guys wrote re: Mass Transit - Part 2 of N
on 01-15-2014 8:44 PM

33FO15 I loved your blog.Much thanks again. Fantastic.

stunning seo guys wrote re: Mass Transit - Part 2 of N
on 02-06-2014 3:31 PM

ovPMwU I think this is a real great blog post. Awesome.

stunning seo guys wrote re: Mass Transit - Part 2 of N
on 02-28-2014 3:51 PM

CZwZtX Great, thanks for sharing this blog post.Really thank you! Will read on...

nice backlinking wrote re: Mass Transit - Part 2 of N
on 03-13-2014 1:44 AM

EuwlxW I loved your article post.Really thank you! Cool.

nice seo guys wrote re: Mass Transit - Part 2 of N
on 03-22-2014 7:16 AM

2rxQkl Very good post.Thanks Again. Will read on...

best money here wrote re: Mass Transit - Part 2 of N
on 03-25-2014 7:18 AM

55YJe8 Thanks-a-mundo for the article post.Thanks Again. Want more.

check it out wrote re: Mass Transit - Part 2 of N
on 03-25-2014 10:43 PM

AAJ1FM Very good blog.Really thank you! Cool.

check it out wrote re: Mass Transit - Part 2 of N
on 04-01-2014 9:00 AM

PsHQ7Z I really enjoy the blog article.Really thank you! Will read on...

check this out now wrote re: Mass Transit - Part 2 of N
on 04-05-2014 12:50 PM

oNWKf8 Say, you got a nice blog post. Cool.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)