views:

672

answers:

8

I'm currently working on an application where one component of the application needs to interact with multiple other system components based on certain events. These events occur based on many different triggers... some events are caused by a user's action where other users need to be notified, some events are time-based, and other events are based on a change in the state of the object.

Based on what I've looked at so far, it sounds like the cleanest way to decouple the application components is to set up a publish/subscribe model where my objects in the component publish events that other interested application components can subscribe to.

I've seen nServiceBus, and for "vendor-lock-in" reasons I cannot use .NET Services in Azure. Are there other technologies available? Is there a different approach that I should be considering?

Edit - to be clear, this is a web-based high volume application. The application is ASP.NET MVC and the MVC application is communicating with multiple WCF services for its data.

A: 

WCF

Google WCF Publish Subcribe model. I think the Annex part of Programming WCF by Juval Lowy had an excellent explanation of how to do it.

EDIT http://idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11
Look for Publish-Subscribe Framework

SKG
A: 

Prism comes with an EventAggregator that provides loosely coupled events.

GraemeF
+1  A: 

There's also MassTransit. Never used it but it's commonly mentioned in the same conversation as nServiceBus.

Depending on exactly what you're trying to do, there's also the Managed Extensibility Framework. Not really a publish/subscribe framework but it's something to be aware of if you weren't already.

Brian Hasden
I don't think MEF is quite right for what I am trying to do. +1 for the MassTransit rec...
mkedobbs
+3  A: 

WCF definitely is capable of handling pub/sub scenarios - and will be much more once .NET 4 with the new WCF Azure relay bindings is out.

For now, check out these articles on the topic:

For the future Azure-based pub/sub messaging using the .NET Service Bus, see these articles here:

marc_s
This seems to be the option that has the most complete documentation and looks like it'll be easier to move to the .NET Service Bus down the road, which is why I am accepting this answer.
mkedobbs
+1  A: 

Udi (the creator of nServiceBus) has a streamlined version of his concept of Domain Events on his blog

We used this as a base to develop a simpler implementation like nServiceBus that we could use in our solution.

Gord
A: 

The answers so far are good ones assuming you have a multi-process or SOA architecture.

If it's a simple standalone application, perhaps the built in C# event model works well in your case. Alternatively, one can also use delegates or an interface to pass to the server/publisher.

This observer pattern link may be helpful.

kenny
A: 

Here's a SO question about "nServiceBus, Rhino Service Bus, MassTransit - Videos, Demos, Learning Resources" with some good answers.

James Kolpack
A: 

To implement a classic publish/subscribe model with .net, I would use ActiveMQ. It is very easy to understand and if you know already JMS, the learning curve is really flat.

p2u