

- #Masstransit publish how to
- #Masstransit publish code
- #Masstransit publish download
- #Masstransit publish windows
So, add another class library to the MtPubSubExample solution and name it “Configuration”. However, in my case, I preferred to use a common class which I’ll call “BusInitializer” to set up my instance to MassTransit and get it configured.
#Masstransit publish code
This is fine, particularly if you really aren’t in a position to share much code between the two sides (except the contracts of course). Initially, this example had the service bus setup code duplicated in both the publisher and subscriber projects. When you’re writing a new project from scratch, you go through many permutations and refactor as you go. MassTransit will call our Consumer class whenever a SomethingHappened message is received, and we can handle it as we wish, presumably inspecting the What and the When properties. Our subscriber will then set up a subscription (aka Consumer) to listen for all messages of type SomethingHappened. Our publisher will create an instance of a class implementing SomethingHappened, set What and When properties, and publish it onto the service bus. SomethingHappened will be the message interface we use for our sample message. To the class library, add a single interface called “SomethingHappened.” using System So, the first step is to create a new solution called MtPubSubExample and a new class library called “Contracts”. To keep the publisher and subscriber as loosely coupled as possible, I like to put my contracts in their own assembly so that this is the only shared dependency. They don’t need to know anything about the implementation of this interface on either side. This is an interface definition that both the publisher and subscriber have to agree upon. I like to use the concept of a “contract” for my messages I want to put onto the service bus. You can get the entire source from: Creating a Contract I used Visual Studio 2013 to create this sample, but it should work in 2012 as well. The only thing that an Exchange can do that most traditional Post Offices don’t do is actually make multiple copies of a message to be delivered to multiple mailboxes. So, to use a real world analogy, an Exchange is like the local Post Office, and a Queue is like your mailbox. Queues can actually hold messages and are where applications can actually pick up messages. It’s merely a set of routing instructions that tell RabbitMQ where to deliver the message. You’ll see the following default RabbitMQ exchanges:Īn exchange is something you can send messages to. There’s not much to see yet, but we’ll set the stage. Default credentials to login are guest/guest (you can change the credentials from the Admin tab). Now go to to open the management console. You can use the Services MMC snap-in to restart it or just run the following command: > net service stop RabbitMQ
#Masstransit publish windows
When installed on Windows, RabbitMQ runs as a Windows service. It will confirm that the plugin and its dependencies have been enabled and instruct you to restart RabbitMQ. From the command line, run the following command: > rabbitmq-plugins enable rabbitmq_management To enable this, find the “RabbitMQ Command Prompt (sbin dir)” item that the RabbitMQ installer added to your Start menu and launch it. With this, you can see the exchanges and queues that are set up by MassTransit in RabbitMQ. One RabbitMQ feature that I found extremely useful (but which isn’t enabled by default) is the web-based management interface. Enabling the RabbitMQ Web Management Interface Again, it’s an easy setup wizard that you can quickly fly through.
#Masstransit publish download
Next, download the latest version of RabbitMQ for Windows. It’s a simple setup wizard, so you’ll have Erlang installed on your machine in short order. Head over to ’s download page and get the latest binary release for Windows (it’s likely you’ll want the 64-bit version). RabbitMQ requires the Erlang runtime, so that’s the first thing you need to download and install.
#Masstransit publish how to
In a future post, I’ll detail how to set up multiple RabbitMQ instances in a cluster. Both our publisher and subscriber will connect to the same RabbitMQ instance. In this article, you’re going to run RabbitMQ on your local Windows development box. When creating a cluster of RabbitMQ servers for availability, this routing information is replicated to all the nodes. The reason for this is that RabbitMQ has a complete routing framework built-in and MassTransit will leverage this when persisting your subscriptions.

That’s especially true when using the publish/subscribe pattern.

MassTransit supports MSMQ, RabbitMQ, and others, but I find that RabbitMQ is really the way to go. The first thing you need is a message queuing framework. NOTE: There is a newer version of this post for those using MassTransit 3.
