This section is home to feature articles by regular and guest authors. Topics and opinions vary - some articles include discussions!
| Open Source Integration with nServiceBus |
| Features - Feature Articles |
| Written by Erik Westermann |
| Sunday, 01 March 2009 15:54 |
|
Commercially available products, like Microsoft’s BizTalk Server, are a key part of many organizations’ SOA-style applications and application integration solutions. Freely available, open source solutions have been gaining acceptance in the broader marketplace. The acceptance of open source solutions is based on not only the maturity of the solutions, but also based on the accessibility and maturity of the underlying user groups that use, develop, and promote open source solutions. nServiceBus is a freely available, open source distributed, scalable, communications framework that’s based on the publish-subscribe model. nSerivceBus, available since early 2007, is evolving under the guidance of it’s architect and author Udi Dahan. It’s latest release, version 1.9, primarily focuses on improving the underlying configuration model making it easier for developers that are not only new to nServiceBus, but also new to messaging-based solutions.
One of the samples that comes out-of-the-box, called PubSub, is designed to demonstrate how easy it is to get nServiceBus working. The sample also demonstrates how to create message types and associate a message type with an endpoint. The following walks you through some of the sample’s major features – you don’t have to have nServiceBus or the samples installed to follow-along.
IEvent eventMessage; The code appears to be simple becasue the underlying infrastructure that nServiceBus provides handles the details of ensuring that the message has a subscriber and handles the details of sending the message to the subscriber. Subscribers handle messages as follows: // Handle messages of type IEvent IMessageHandler in the preceding code is defined by nServiceBus. The nServiceBus infrastructure calls the Handle method when it delivers an EventMessage type message to the subscriber. nServiceBus is multi-threaded so that you can set it up to take advantage of available resources. The preceding method gets called whenever a message from any thread is available, thereby further simplifying the programming model. Subscribers still need to ensure that their code is thread-safe whenever they write to any shared resources. Messages in the sample get transported between Publishers and Subscribers using MSMQ. I’m not going to explain the complete details about configuration here since it will divert the focus of this article. I will say that configuration is easy to understand if you take some of the code you see at face value. If you are not familiar with acronyms like IoC and DI, you may have to simply accept some of the code you read in the sample without trying to understand it, focusing instead on working with nServiceBus. Here is how the Publisher binds to the underlying bus: var bus = NServiceBus.Configure.With() The code uses a new C# language feature that was introduced in version 3.0 - implicitly typed variables (shown on the first line – var bus . . .). Reading the rest of the code, which is really just one line, reveals that the publisher serializes messages using an XmlSerializer, and sends messages using MSMQ. nServiceBus runs the publisher asynchronously on its own thread so that once the above line executes, it immediately returns control to your code giving you the freedom to run other aspects of your application. Although nServiceBus does not currently include documentation it does have an active user community - Udi Dahan actively participates in the disucssions. The community’s discussions include enhancements, features, use cases, and day-to-day operation of nServiceBus. More information about nSeriviceBus is at these sites:
This is the first of what will be a series of articles covering nSerivceBus – stay tuned! |
"The number of computer science majors enrolled at U.S. universities increased for the first time in six years..." |