Basic extension model in Rebus: Injectionist

The new Rebus (i.e. “Rebus 2”, which is currently available from version 0.90.* on NuGet) is very easy to extend, due to the fact that the configuration API is backed by a very simple IoC-like container: the “Injectionist“.

The Injectionist is based on a simple general principle: For each type of service that you register (e.g. ISubscriptionStorage), you are allowed to register ONE primary implementation of that service (e.g. SqlServerSubscriptionStorage), and any number of decorators to that service (e.g. CachingSubscriptionStorage, etc.).

All registrations in the Injectionist are functions that must return objects – so for example to register our subscription storage example from above, we would do it like this:

and then, since the RebusBus instance is registered like this:

the configuration API can end up calling injectionist.Get<IBus>() in order to build a bus instance with the chosen implementations of the various abstractions.

In addition to making it easy to gradually build a configuration, the Injectionist enables YOU to intercept almost anything by registering your own decorators…

Want to mutate incoming/outgoing messages? There’s several ways of doing that, but one way would be to register a decorator for the ISerializer interface.

Want to measure the time it takes to dispatch a message? Again, there’s several ways to do that, but one way could be to decorate the IPipelineInvoker interface.

And so on ūüôā

Introducing Rebus 2

small-bus-logo-1I’ve been meaning to do this for a while, and while I am aware of the danger of doing it, I’ve done it anyways: I’ve rewritten Rebus!

Why would you do that?

Rebus was initially made to make me happy. I made it as an implementation of the parts of NServiceBus that I liked best in order to use it on a couple of projects, and thus I did not put too much effort into making a long-lasting design. Also, I aligned all APIs very closely to their NServiceBus counterparts, although I did loosen up on this as time went by.

In addition to this, Rebus was my first open-source project, and to this date, more than 20 besides me have contributed code to it, and many more are using it. It’s been fun to manage a project with actual contributors, and at times it’s been challenging to govern the project with regards to features, quality, ease-of-use, responsiveness, etc.

To sum it up: I have learned a lot since I started the Rebus project!

And usually, when you learn things, you want to put those things to use. At this point, I feel I’ve learned so much that I needed to put those things back into Rebus,

Why would you do it like that?

Rebus has – since its inception almost 5 years ago – done a good job of keeping message flowing and developers happy, so why would I rewrite it from scratch?

I’ve been meaning to improve a lot of things in Rebus for quite a while now, like reducing complexity, introduce message pipelines for incoming and outgoing messages, etc. I could probably have undertaken this as an incremental task, but my feeling is that the end result would not be nearly as clean as it will be with a rewrite.

Therefore, my conclusion was this: Rebus is small enough that a rewrite was the best way to refactor it (given the changes I wanted to make, obviously)!

Also, I did not actually throw old Rebus away. Rebus 2 is async to the core, and the OWIN-pipeliney design is heavily inspired by my (very brief) work with the NServiceBus team, but I kept everything aligned with old Rebus as far as it made sense, thus allowing me to port most of the integration implementations forward with very few modifications.

What has changed?
  • Rebus 2 is async to the core. All APIs are, in their most basic incarnation, async. Therefore, you await bus.Send(yourMessages) now. In other words, one single physical thread can do a lot of work, while consuming almost no memory, and almost no CPU.
  • Rebus has pipelines. Incoming and outgoing messages are passed through pipelines, which allows for extreme flexibility in how Rebus behaves. Several of Rebus’ “built-in” functionalities like e.g. compression and encryption are simply extra pipeline steps that are applied to incoming and outgoing messages.
  • Routing is based on topics. Topics based on .NET type names (which is how old Rebus worked) is thus just one case of a more general scheme where any string can be a topic.
  • There’s no batching. Batching (i.e. the fact that each and every transport message was actually a container of zero or more logical messages) provided almost no benefit, considering the amount of code it took to implement it. You can easily implement batching yourself in those few cases where you want it.
  • There’s an in-memory transport, an Amazon SQS transport, an Azure Storage Queues transport, a Jil serializer, and more cool stuff to come!
  • Idempotent sagas can be had by deriving your handler off of IdempotentSaga instead of Saga.
  • …and much more ūüôā
Show me the code!

Chances are that many Rebus users will not experience too many differences. Check this out – here’s how I start the usual MSMQ-enabled endpoint, capable of receiving requests and delivering replies:

and then, in order to send SomeMessage to the endpoint, do this:

Get started

Rebus 2 is initially released as Rebus 0.90.0, along with all of its integration packages. You can install-package rebus to get started right away.

How to upgrade

Because of the many changes, upgrading from Rebus 0.84.0 (the last “Rebus 1” version) to 0.90.0 (the first “Rebus 2 beta” version) may not be trivial.

Rebus 1 endpoints do not readily work with Rebus 2 endpoints, so you will need to upgrade all endpoints at the same time or manually bridge things while you upgrade.

Bugfixes might still be released for the 0.84.0 version of Rebus, but if you have the opportunity to pick a version, I recommend you go with 0.90.0.

As always, I’ll be very grateful to hear about your experiences with it – good or bad!

Happy messaging ūüėÄ

More GOTO Aarhus 2014

My personal highlights from the 2nd day of GOTO Aarhus:

New linting rules by Kyle Simpson

It was fun to watch this extremely opinionated guy talk about JavaScript and be “undougie” about things, especially about comparison type coercion “best practices”. I also learned a little bit more on how crazy JavaScript can be, and to which extreme lengths some JavaScript developers will go in order to bend the language – e.g. by using try/catch blocks to create a proper scope ūüôā

Matias Niemelä on Angular.js 1.3

Matias is clealy a Vim wizard, and it’s always fun to watch someone who can use a computer do some live coding. I had gotten the impression that the talk would be more like “what’s new in 1.3”, but it turned out to be mostly a general introduction to Angular’s features, and only at the end did he dive into some of the new animation and validation features.

Angular is a nice framework in many ways, and it’s actually pretty sweet to work with, but I can’t help to think that it’s becoming more and more bloated. I think I need to take a look at Facebook’s React soon.

Where’s Captain Kirk?

This was a double session where Kevlin Henney, as the host sort of, would introduce Eva Andreasson, Randy Shoup, and Ola Bini, and have them talk about stuff that enterprises, sadly, are apparently still not putting to enough use. Eva talked about the “Enterprise Data Hub”, Randy talked about the cloud and microservices, and Ola presented a polyglot project where they had used Java, Ruby, and Clojure on the JVM to build the system.

I had seen Ola Bini’s “Working on cancer” talk before, which was only mildly interesting from a technical angle, because it was basically a list of involved technologies – as in: “we used Ruby, and we used Java, and then we used Clojure” – so I wasn’t that impressed with his contribution to the talk.

I was more intrigued by Eva’s and Randy’s parts of the talk, and Eva actually made me think about what it would mean to basically archive every kind of information that would flow through the company. Basically that’s what you’re doing when you’re doing event sourcing, so I was thinking that the EDH could be seen as a kind of global event store for the entire company.


It was nice to be at GOTO again, and the quality of the sessions and the keynotes was generally pretty high. I can’t help to think that the “couple of days, several tracks, 50 minute sessions” format could use some kind of renewal though, and I guess that the GOTO arrangers are beginning to feel something too since the conference has been reduced to two days instead of the usual three.

GOTO Aarhus 2014

Just a brief note of today’s highlights:

Mads Torgersen on the future of C#

Listening to Mads Torgersen talk about Roslyn and some of the new additions to the C# syntax was nice – I love the fact that my trusty workhorse is keeping up and is still being improved. I would love it if F#’s discriminated unions and pattern matching would find a way into C# though.

Greg Young on event sourcing

Having been drinking a fair amount of event sourcing Kool-Aid lately :), I simply had to go to Greg Young’s talk about event sourcing. It was cool when our CQRS- and event sourcing framework got a mention from the master himself.

Mads Kristensen on ASP.NET vNext

Watching Mads Kristensen show off the new ASP.NET vNext stuff is another sign that Microsoft is doing a lot to keep up with current de facto web development toolchain standards, as they have added the concept of a “Task runner” to Visual Studio – this is where Grunt/Gulp/Mimosa/Broccoli/next week’s shiny new JavaScript task runner will pop up and become tightly integrated in our Visual Studio development flow.

Other stuff

There was probably other interesting stuff going on as well, but I must admit that my head hurts a little bit from having had one beer too many yesterday evening. But that is quite natural, actually, as going to conferences is ~50%(*) about having beers and talking to inspiring people.

(*) That claim is supported by a pretty decent amount of empirical evidence, which I have personally collected.

My GOTO Aarhus 2014 schedule


C# is my favorite enterprisey multi-purpose multi-paradigm language, so I simply have to watch Mads Torgerson talk about the new Roslyn-based compiler, even though my interest was slightly piqued by the Xamarin.Forms talk (mostly because my prejudice is that cross-platform mobile development does not work well, but I would love to be proven wrong!).

In the next slot, Mark Seeman is doing the interesting Look, no mocks!-talk about functional TDD with F#, which I also wanted to see, but I might end up going to one of the data talks – either Cliff Click’s Fast Analytics On Big Data-talk for some serious number-awe, or Mark Madsen’s Big Data, Bad Analogies-talk because I usually enjoy talks that add a historical perspective to something that many developers consider new and shiny.

In the 3rd slot, Greg Young will be talking about Event Sourcing, apparently, but there’s no abstract on the homepage… also, I’ve been to several of Greg’s talks about event sourcing, so I might end up going to Martin Thompson’s Responding In A Timely Manner-talk, which seems to be about latency at several levels.

In the last two slots on Monday, I have no idea where I want to go – being a .NET guy, I could go to Mads Christensen’s talk about The Future Of ASP.NET Web Tooling, but lately I’ve found myself enjoying more “general” web tooling like Bower, Mimosa, Gulp, etc. more, also for regular .NET web development, so I will probably go to either the NetflixOSS talk or the Big Data Deep Dive talk… or I might end up on a couch with my laptop, because at this point my fingers usually start to get an itch that can only be scratched by coding.


In the first slot on Tuesday, I think I’ll go get an update on Swift – I’ve coded a couple of hello worlds including one with draggable cookies with Swift, and I have pretty high expectations for the language, but I haven’t really followed along the last months, so it will be interesting to get an update.

In the next slot, I think I’ll go to Matias Niemel√§’s talk about Enhanced Front-end Applications In Angular.js 1.3 which will probably feed me some nuggets of information that will turn out to be valuable at work.

In the third slot, I could go to Yann Cluchey’s talk about Making Enterprise Data Available in Real Time with Elasticsearch but Jos√© Valim’s Idioms for building distributed fault-tolerant applications with Elixir-talk also looks interesting – I usually enjoy seeing what tricks they’re capable of in the Erlang-world.

In the next slot, I don’t know where to go – but in the last slot, I’m fairly sure that I’ll go watch Jan M√łller talk about the BitCoin protocol at the technical level because I expect it to be about distributed systems, consensus, and interesting stuff like that (which IMO is relevant knowledge for anyone who has ever done any kind of programming that involves more than one process talking…)


On Wednesday, I’ll be back at the d60 office, because GOTO is only two days now :'(

I’m going to GOTO Aarhus once again

Sk√¶rmbillede 2014-06-30 kl. 22.54.08Once again – this time for the 8th year in a row – I will attend Trifork‘s excellent GOTO conference in Aarhus.

Back in 2007 when I was employed by Trifork (or “Eastfork Object Space” as they were called back then), I attended my first conference which happened to be the company’s own “JAOO” conference (which used to be GOTO’s name, even though it had not been a pure Java conference for years).

As a light green software rookie I cannot exaggerate how uplifting it was for me to start working with EOS/Trifork, and it was a profoundly inspiring experience to go to JAOO where they weren’t only talking about .NET from a Microsoft point of view – no, they would have speakers talking about open source hippie technology that weren’t even backed by any of the sponsors!

At the time Ruby was all the rage, and I distinctly remember attending Chad Fowler’s talk on Rails’ ActiveRecord which I would contrast with Hamilton Verissimo’s talk on Castle ActiveRecord, and – even though I’ve written something like 20 lines of Ruby code in my life – I’m pretty sure that I’ve come to know most of the Ruby syntax, and I’m also pretty sure that the Ruby way of doing stuff has been influencing my coding style ever since, just because I’ve been regularly and repeatedly exposed to these Ruby things.

See, this is what’s cool about going to conferences: You go to talks about wrestling DBs with Ruby, representing state with Clojure, or on how to visualize the internals of programs by doing “beautiful debugging”, and it ends up making you better at C#. You enter talks that show off visionary technologies or visionaries themselves, and then it widens your horizon. I believe the more ideas and technologies you’re exposed to, the less bound you will be to any technology in particular, which is always a good thing to strive after as a software developer.

Once again, I’m looking forward to having an injection of insight and motivation, even if it is only for two days this year instead of the usual three (I wonder what that is about?)

See you there? ūüôā

Swift gesture recognizer that accepts a func

While doing iOS programming in Xamarin Studio, I’ve developed a pattern when working with gesture recognizers where I do something like this:

i.e. my gesture recognizers almost always work with a factory method that returns a recognizer whose callback closes over some local variables – this way, I have the full power of a dedicated class instance, but without the hazzle of defining a new class every time I need a new kind of recognizer.

I’ve messed around with Swift only a few days now, and I’m beginning to miss my closure-based recognizer pattern… but Swift (or, actually, the way Objective C is bridged) has a problem: When you addTarget on a gesture recognizer, it stores the callback – not as a Swift (UIGestureRecognizer) -> () reference, but rather as an Objective C selector-based target. This makes for a very un-Swifty feeling when adding the target, especially because it forces you to point to a method by typing its name in a string suffixed by “:”.

My first attempt towards supporting my beloved recognizer pattern in Swift was an extension on UIGestureRecognizer that would take a (UIGestureRecognizer) -> () as argument, wrap it in a class instance with an invoke method, and then do the addTarget call with that class instance – but then I got hit by the fact that the recognizer stores its callback targets with weak references, which means that my func-wrapping target would be gone by the time it was supposed to be used.

My current implementation seems to work fine though – I’ve extended UIPanGestureRecognizer to be able to be initialized with a (UIPanGestureRecognizer) -> () as its only argument, which it stores and has invoked by adding the invokeTarget method as the recognizer’s target.

This is the full code for the recognizer:

This way, I can use the recognizer like this:

which IMO makes for a pretty compact yet powerful way of creating focused and cohesive recognizers without a lot of boilerplate.

How to create a draggable cookie with Swift

or: “How I learned about the default value of userInteractionEnabled on UIImageViews”…

So, today I set out to create an iPad app in which my four year old son can drag some cookies around and get to do some light math.

In order to have draggable cookies, I figured the way to go would be to derive a DraggableImageView off of UIImageView that would add to itself a UIPanGestureRecognizer that would make the cookies (or any image, really) draggable.

This was my first attempt:

but for some reason I could not get it to recognize my dragging gestures! So I messed around with the code, coding various (failed) attempts at adding UIButtons and whatnot to my DraggableImageView in order to be able to do at least one single successful addTarget, but I simply could not make it work!

I loaded up some other Swift projects where my buttons worked fine, went back to the failing DraggableImageView, messed around with platform settings and other good stuff, suspecting that it was due to a bug – it is called XCode Beta, after all – and then it hit me:

  • New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.”
    Source: UIImageView documentation, emphasis mine.

Right! So I went and added self.userInteractionEnabled = true in the middle, which resulted in the full code reading (with nifty hover shadow effect added)

which in turn gave me these delicious draggable cookies…. Yummy!


Getting a good start with ElasticSearch

I’ve written before on how you can install ElasticSearch on a couple of Ubuntu VM’s in Azure, but while getting the database engine up and running is of course pretty important in order to start working, there are a couple of additional things that really make working with ElasticSearch super-smooth: Marvel and Kibana!

In this post I’ll show you how you can install both.


Marvel is a database monitoring tool that can show you how your ElasticSearch is feeling with a huge amount of meters and gauges – I won’t go into that here, because I haven’t actually looked at that part yet, but the thing I’m excited about is Sense, which is described as a “developer console” where you can go and do RESTful things to your ElasticSearch database.

Let’s install Marvel!

Open up a terminal and go to the root directory of your ElasticSearch installation. Depending on your platform, you’ll have to execute the following command with administrator rights, so it’s either sudo or

Skærmbillede 2014-06-13 kl. 21.11.00

for you – and then you go

which should result in downloading and installing the Marvel plugin. If it succeeds, you should be able to go to the /_plugin/marvel path of your ElasticSearch node to see all the graphs and meters I talked about. Try going to Sense by clicking on the Dashboard button in the top right corner – now you can use a lightweight cURL-like syntax with autocomplete to e.g. put a document to the database like this:


or do a quick search like this:


Neat! The Marvel plugin costs money if you want to use it for productino purposes, but as far as I can tell, it’s absolutely free to use during development, which is also the time when Sense makes the most sense, effectively meaning that you can consider Sense free.

Now, let’s check out Kibana…


Kibana is a simple generic ElasticSearch data analysis and dashboard tool that can help you visualize your data in pretty ways, and since it’s Apace V2-licensed, it’s absolutely free to use for all intents and purposes.

Since Kibana is just a modern SPA, you can go to Kibana’s GitHub and get the code which you can put in a directory or host on a web server somewhere, you’ll just need to edit the line in config.js where the ElasticSearch URL is configured.

Another option is to let ElasticSearch do the hosting, which can be easily achieved by installing Kibana as a plugin like this:

Small caveat: Installing the plugin will copy the entire source code as it looks in the Git repository, which means that the Kibana URL will become the base URL of the plugin /_plugin/kibana followed by the path /src/index.html – the full URL then becomes e.g. something like http://localhost:9200/_plugin/kibana/src/index.html.

Even though Kibana is fairly generic and can be used to visualize your ElasticSearch data in many ways, it seems to give special treatment to time series-based data, where especially logs come to mind – which is probably why it has extra-special treatment for logs imported into ElasticSearch via logstash.

That concludes this small guide on how to install Marvel and Kibana. Stay tuned for more ElasticSearch ūüôā

Playing with UIView shadows in Swift

I saw a demo somewhere, where some dude created different nifty shadow effects by tweaking the shadowPath property of UIView’s CALayer. Being pretty new to Swift and iOS development, I figured it would be fun to play around with it – here’s the result (screenshot from the iPhone simulator):

four different shadow effects

Here’s how I did it – first, I installed this simple UIViewController to display the four images:

and then I created the applyPlainShadow method (which is basically the shadow example you’ll find everywhere when you Google for “UIView drop shadow”):

Simple and neat… – but now the fun begins – let’s create that convex-piece-of-paper-on-a-surface-effect that you’ll see in many places on the web – it’s created by simply using a UIBezierPath to draw the outline of the shadow, and then setting the layer’s shadowPath to the path’s CGRect:

Neat! Lastly, let’s create a blurry oval drop shadow, as if the view was hovering high over some low surface that expands into the screen… again, I’m using the shadowPath property, initializing the UIBezierPath with the overload that creates an oval shape from a rectangle: