This section is home to feature articles by regular and guest authors. Topics and opinions vary - some articles include discussions!
| Up and Running with nServiceBus 1.9 |
| Features - Feature Articles |
| Written by Erik Westermann |
| Tuesday, 07 April 2009 14:31 |
|
nServiceBus version 1.9 is much more approachable for new developers, as compared to previous versions. This article describes how quickly start experimenting with nServiceBus based on one of the examples, PubSub. Along the way, I also discuss some details about how nServiceBus works.
http://sourceforge.net/projects/nservicebus
Verify that the script successfully setup the queues:
Build the solution (Select Build - Build Solution); it should compile without any problems.
The message label of the message in the 'messagebus' queue includes your computer/domain and username. Take a look at the message body - you'll see that this is a SubscriptionMessage to register the subscriber. When the server starts, it checks the messagebus queue and sets up scribers as you saw earlier by posting new messages into the subscriptions queue. You can start the server to see what happens to the message that's in the messagebus queue (it disappears and a new message appears in the subscriptions queue). <MsmqTransportConfig The MsMqTransportConfig section describes the subscriber’s input queue (worker) and its error queue (error). The UnicastBusConfig section describes the messages that flow through the system. The Server’s configuration is a little different: <MsmqTransportConfigThe Server's MsmqTransportConfig section sets the Server's input queue to the 'messagebus' queue and error queue, 'errors'. The Server - the publisher, conceptually handles messages by publishing them to the messagebus queue and then transferring the published message to interested subscribers. In reality, as of version 1.9, the server matches a message it wants to publish with a subscriber by iterating over a mapping of message types and subscriber information. When the server finds a match, it publishes the message to the subscriber's queue. The next section of the server's configuration should be familiar to you now. As before, the UnicastBusConfig section describes messages that flow through the system and the endpoint (queue) that manages them. The messages in this case reside in an assembly called Messages and their endpoint (or queue in this case) is the messagebus queue. This last section of the Server's configuration, MsmqSubscriptionStorageConfig, describes where the Server finds information about Subscribers - the subscriptions queue you worked with earlier. nServiceBus makes it easy to change the behavior of both publishers and subscribers with just a few lines or code, or some changes to the configuration file. In this example, I walk you through changing the durable nature of a subscription to something less durable. Subscribers normally continue to receive messages, even when they are offline. This example changes a subscriber such that it unregisters itself when it terminates; therefore, the subscriber won't be aware of messages that were sent to it while it was offline. You can change Subscriber1 to unregister itself when it terminates by adding just one line of code to Program1.cs in the Subscriber1 project. Add the following line, just after the end of the while loop in the Subscriber1 project's Program.cs file: bus.Unsubscribe<EventMessage>(); So the resulting code should look something like this: while (Console.ReadLine().ToLower() != "q") Start the server, and then start Subscriber one. Publish some messages and note that subscriber one receives them, then quit subscriber one. Publish some more messages, and finally restart subscriber one. You'll notice that it no longer handles messages that were sent to it while it was offline. The server in this case did not even publish messages for subscriber one because, when subscriber one goes offline it removes its entry from the 'subscriptions' queue; the server does not publish messages that don't have a subscriber. While this example demonstrates un-subscription behavior, you should be aware that there may be some cases where this does not work as seamlessly as it does in this example. It's recommended that you always work with the latest version of nServiceBus and that you consult the discussion board to research current issues before your project depends on certain functionality. The next article in this series walks you through the nServiceBus solution and demonstrates how to compile it. Your feedback is always welcome - send feedback to This e-mail address is being protected from spambots. You need JavaScript enabled to view it |
| The Art of Babel is seeking articles about Enterprise Application Integration, Business Process Automation, and Workflow technologies. Articles can use technologies from a variety of vendors. More Information. |