There’s something in RavenDB which every platform developer should copy into their own platforms: Well written exception messages. Here’s one example:
The maximum number of requests (30) allowed for this session has been reached.
Raven limits the number of remote calls that a session is allowed to make as an early warning system. Sessions are expected to be short lived, and
Raven provides facilities like Load(string[] keys) to load multiple documents at once and batch saves.
You can increase the limit by setting DocumentConvention.MaxNumberOfRequestsPerSession or DocumentSession.MaxNumberOfRequestsPerSession, but it is
advisable that you'll look into reducing the number of remote calls first, since that will speed up your application signficantly and result in a
more responsive application.
Not only does this tell you what went wrong, it also tells you why and also offers advices on how to fix it. Does it get any better than this?
Good exceptions can be real time-savers.
By default the NServiceBus generic host uses Spring for its IoC-needs. Changing this is as easy at it gets.
Note: If you’re hosting NServiceBus without the generic host, please follow this tutorial instead.
1. Select your desired IoC-container
NServiceBus comes with a built-in support for the following IoC-containers:
- Spring
- Autofac
- Castle Windsor
- Structuremap
- Unity
You can pick your favorite. This tutorial will use the Structuremap.
2. Include the IoC-container in your project
Supported IoC-containers can be located from the NServiceBus/binaries/containers –folder. In Visual Studio, open up an NServiceBus application for which you want to change the IoC-container. Add a reference to the following files:
- NServiceBus.ObjectBuilder.StructureMap.dll
- StructureMap.dll
Note: Change the dlls if you selected an another IoC-container.
3. Modify the initialization
Now open the generic host initialization method. By default, it may look like something like this:
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ServerInit : IWantCustomInitialization, IWantCustomLogging
<span style="color: #606060" id="lnum2"> 2:</span> {
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Init()
<span style="color: #606060" id="lnum4"> 4:</span> {
<span style="color: #606060" id="lnum5"> 5:</span> NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
<span style="color: #606060" id="lnum6"> 6:</span> }
Modify this method by adding a call to NServiceBus.Configure.With().StructureMapBuilder() –method. This changes the IoC-container.
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Init()
<span style="color: #606060" id="lnum2"> 2:</span> {
<span style="color: #606060" id="lnum3"> 3:</span> NServiceBus.Configure.With().StructureMapBuilder();
<span style="color: #606060" id="lnum4"> 4:</span> NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
<span style="color: #606060" id="lnum5"> 5:</span> }
Simple, wasn’t it? The new method comes from the NServiceBus.ObjectBuilder.StructureMap.dll. If your application has already initialized an StructureMap container, you can pass it to the NServiceBus as a method parameter.
Links
Earlier we’ve gone through on how one can modify the NServiceBus FullDuplex sample so that the NServiceBus debug-messages aren’t shown on the console. The change we did allowed us to change the whole log4net configuration. But, if we only care about hiding the debug-messages, there’s an easier way.
NServiceBus.Host.exe has a support for different profiles. Profiles are meant to easy the path from moving your application from the development into the production. The profiles allow you to change some aspects of your application (like logging) without making any code or configuration changes. NServiceBus comes with three different profiles and you can build your own. The built-in profiles are:
- Lite
- Integration
- Production
You can find more information about the built-in profiles through the NServiceBus documentation.
If you’re using the generic host (NServiceBus.Host.exe) and you want to remove the NServiceBus debug messages from your console, you can easily do that with the help of the built-in profiles. If you start your host with an Integration-profile, the debug-messages will not print on the console.
To start the host with a specified profile, add the profile’s class name as an argument to the host. In our case we want to start the host with an integration-profile and here’s how we do that:
NServiceBus.Host.exe NServiceBus.Integration
And as you can see, the debug messages are gone.

RavenDB is a .NET-based open source document database. I've been playing with it lately and love everything thus far. The server is really painless to install and the documentation is easy to follow. In the following weeks I'm hoping to post some tutorials related to the RavenDB and document databases in general.
In our previous tutorial we added an encrypted data into our message. But what happens if our client’s and server’s Rijndael Encryption Key differ from each other? Here’s the answer:
