Command Handling the Nancy Way

minibuss_small_thumb1_thumb_thumb MiniBuss is a micro service bus framework over msmq which consists of less than 400 lines of code, sitting inside one single source file. The project is hosted over at http://minibuss.codeplex.com and the source code is maintained at https://github.com/johandanforth/MiniBuss

I’ve been a fan of the Sinatra inspired web framework called Nancy, especially the neat way of setting up handlers for routes. The simplest sample on their site is this:

public class Module : NancyModule
{
    public Module()
    {
        Get["/greet/{name}"] = x => {
            return string.Concat("Hello ", x.name);
        };
    }
}

So, I shamelessly dug into the Nancy code and borrowed some 20-30 lines of code and came up with something like this for registering handlers for certain incoming commands on the minibus, what do you think?

public class CommandHandler : MessageHandler
{
    public CommandHandler()
    {
        WhenReceiving[typeof(SampleMessage1)] = x =>
        {
            Console.WriteLine("sample 1 message: " + x.Text);
        };

        WhenReceiving[typeof(SampleMessage2)] = x =>
        {
            Console.WriteLine("sample 2 message: " + x.Text);
        };
    }
}

It’s a bit more code but it helps/enforces you to move the handlers off to a certain module. Thoughts?

4 Comments

  • I tried MiniBuss, and it compiles quite nicely, but when I run the Sender app, it complains that I don't have permission.

    "The queue does not exist or you do not have sufficient permissions to perform the operation"

    Do you know why this would happen? I'm on Windows 7.

  • Have you made sure the msmq component is installed on your machine?

  • I thought I posted this, but it was TOTALLY my fault.

    The sender program requires that I run the reciever program, or there is no queue, thus the error.

    I'm loving the simplicity of your framework, and I'll use it soon.

  • @Fallon :) Good that things got sorted, I wish you luck. If you got other problems or questions, please use the issues feature on github, codeplex or contact me on twitter at @johandanforth

Comments have been disabled for this content.