
Both consumers are receiving each message being published. Nothing else was required as the configuration is automatic.Īs desired. To prove that adding more consumers was working find I created another consumer class for the same message. But who doesn’t like beautiful console application output? After this is done all consumers will now start getting any messages being published by the Producer. Next we need each consumer registered with StructureMap to be subscribed to the service bus. To register all the consumers with StructureMap a scanner is used against executing assembly adding all consumers. Where(p => typeof (Consumes.All).IsAssignableFrom(p.PluginType))ĬonsumerInstances.Each(type => bus.Subscribe(type.ConcreteType)) Private static void SubscribeConsumers(IContainer container, IServiceBus bus) Scan.AddAllTypesOf(typeof (Consumes.All)) Ĭonsole.WriteLine("Stopping Subscriber") Take a look at the message Consumer setup: public class ConsumerMain Automatically Registering And Subscribing Message Consumersīefore the any message consumers can receive messages they need to be registered with StructureMap and subscribed to the service bus. I would love to be enlightened if unsubscribe is necessary in context of how we are subscribing consumers as you’ll see next. This consumer is where your business functionality goes. unsubscribeAction = bus.Subscribe(this) Ĭonsole.WriteLine("SimpleMessage consumer started.") Īgain boring easy yet very important stuff. Var message = new SimpleMessage '", message.Body) Private static void PublishSimpleMessage(IServiceBus bus) While (Console.ReadLine().Trim() != "x") Using (var bus = container.GetInstance ()) Var container = new Container(x => x.AddRegistry(new CommonRegistry())) The Producer does one thing, generates SimpleMessages and Publishes them. I included this solution view so you can see what references each project requires.

In this case the Message and StructureMap registry.
MASSTRANSIT ICONSUMERFACTPRY CODE
Common – code shared between producer and consumer.My first step was to grab the Mass Transit trunk from SVN, build it and start up a new solution with three projects: Why? Because it is great and we have two contributors on staff: creator Jeremy Miller and the brainy Josh Flanagan.

Our favorite IoC container is StructureMap. To be exact I want to see how easy it is to get Mass Transit working using StructureMap for an IoC container.ĭovetail uses Inversion of Control extensively to make our code more: testable and able to leap tall buildings, dodge bullets, and all that. I am spiking out right now what it takes to use a Mass Transit as a message bus for handling a simple producer consumer messaging architecture.
