Category Archives: Development

Rolling Counter

Sometimes I need a rolling counter, especially in diagnostics-related scenarios. How many requests have occurred in the last hour? It’s not okay for a counter object to drop out of cache every hour, because the value will be meaningless if I happen to observe it at (Cache Drop + 3 minutes).

A real rolling counter is needed in these situations. The counter must increment, and then at some point those hits must drop off.

But especially in these situations, low impact is the key. A Queue where each item contains a timestamp is too unruly. Too many objects are created and too much cleanup is required. Less is more.

Read more »

NServiceBus Retries: Why no back-off delay?

When presenting my Distributed Application Development with NServiceBus talk at the Twin Cities Code Camp 10, I was asked by an attendee why NServiceBus’s automated retry feature doesn’t have some sort of a delay or back-off algorithm.  Unfortunately I had never really thought about it, and I didn’t have a very good answer for him.

This week I have the good fortune to be attending Udi Dahan’s Advanced Distributed System Design course in New York, so I thought I would get the answer direct from the source.

Udi gave me several good reasons why this is intentionally left out of NServiceBus.  I’ll try to convey his answers and add my own thoughts as well.

Read more »

Injecting NServiceBus into ASP.NET MVC 3

In the past, integrating NServiceBus into a web application typically meant adding the fluent configuration block to the Global.asax file and then keeping a static reference to the IBus property, because ASP.NET has not been very friendly to dependency injection.

In ASP.NET MVC 3, Microsoft has changed that by adding some nice abstractions around dependency resolution.  With a little effort, this allows us to inject NServiceBus (and its dependency injection container) into the dependency resolution pipeline.

In this example, I will show how to add NServiceBus to an MVC 3 web application so that common NServiceBus types (IBus chief among them) are injected into your controller classes.

Note: Karl Nilsson has written a post extending this one, showing how to inject NServiceBus into an ASP.NET MVC4 Web API solution, which requires just a few minor adjustments.

Read more »

Apple iOS Push Notifications with NServiceBus

I’m no big fan of Apple’s Push Notifications API, but the fact is that iOS applications are no passing fad.  As developers providing server-side resources to mobile applications, our job is to do so as efficiently as possible.

For .NET developers able to commit financial resources, third party solutions such as Urban Airship can be the answer.  For developers wishing to control their own destiny, the open-source apns-sharp provides Apple push notifications and feedback services in a C# library.

Considering the ridiculous complexity of the Apple Push Notification format, it would behoove any developer to use apns-sharp instead of trying to re-invent the wheel.  NServiceBus together with apns-sharp would offer the reliability and scalability needed to successfully send push notifications for a high-capacity enterprise system.

Unfortunately, until recently apns-sharp and NServiceBus didn’t work and play well together.  I contributed to the apns-sharp to address these shortcomings.  In this article, I will describe how to use these modifications to apns-sharp to send push notifications with NServiceBus.

Read more »

My NServiceBus moment of bliss

Sometimes technology is more than just technology.  Sometimes it reaches out and grabs you, and you have a moment of bliss where you realize everything has changed, that this is going to change everything and make your life better.

LINQ was one of those technologies for me.  Not the query-like syntax, per se; I consider that to be just a fancy compiler trick.  But the set of extension methods for IEnumerable<T> and the way they can reduce a complex looping structure to a line or two is amazing and game-changing.

Over the last year I have been embracing NServiceBusJonathan Oliver describes NServiceBus as the best thing to happen to distributed systems since Ethernet, and he’s right on the money.  My first major project using NServiceBus has now been in production for a few months, and since then I’ve been reflecting on the process.

Now I realize there was one moment – that perfect moment of bliss – when I realized NServiceBus had changed everything.

Read more »

Automating IIS7 Setup with Microsoft.Web.Administration

Switching from Subversion to Mercurial with Kiln was one of the best things we ever did, but it wasn’t without its pain points. The biggest problem is when you have websites that can’t be hosted by the integrated Visual Studio web server (Cassini) and require complex IIS configurations that can’t be version-controlled.

With a distributed version control system (DVCS) such as Mercurial, you’re supposed to clone branch repositories all over the place, but redoing the IIS configuration can be a major drag.

Luckily, IIS7 comes with Microsoft.Web.Administration.dll, a managed assembly that allows you to automate server administration tasks, something that was next to impossible in IIS6.

Read more »

Apple Push Notification certificates without the Mac Keychain

If you want to send push notifications to an iPhone application from a .NET platform, the Mac Keychain turns out to be a major buzzkill.  In order to get a .p12 file suitable for use with the apns-sharp push notifications library in the Keychain, you have to perform a complex, manual (read error-prone) procedure that gets really annoying, especially if you have many apps to provision for push notifications, as I do.

Wouldn’t it be great if you could do this in C#, on Windows, without a Mac or the Keychain?  Well, you can!

Read more »

Why not publish NServiceBus messages from a web application?

It may be the single most asked question on the NServiceBus Yahoo Group, and it usually goes something like this:

The NServiceBus Documentation/FAQ says not to publish messages from a web application. But…why?

All the documentation says on the topic amounts to “Don’t. Bus.Send() a message instead.” This is true and good practice, but developers are smart people that aren’t commonly happy with an answer that doesn’t include a why.

In this article I’ll go into some depth on the three main reasons why you’re better off using Bus.Send() when in the web world than Bus.Publish().

Read more »

Deploying NServiceBus in a Windows Failover Cluster

NServiceBus is made from the ground up for scalability and reliability, but to take advantage of these features, you need to deploy it in a Windows Failover Cluster. Unfortunately, information on how to do this effectively is, as yet, incomplete and scattered. This article will describe the process for deploying NServiceBus in a failover cluster.

Read more »

Hey Apple, Your Push Notifications API Sucks

I’ve been an Apple fanboy for years. I grew up programming in BASIC on an Apple IIGS. I love my iPhone to death. However, I am not a member of the Church of Jobs that believes Steve can do no wrong. Now I’m a software developer and I appreciate a good, clean, easy to use API, and Apple falls short.

But fear not Apple! You may already have two push notification command formats on the books, but keep reading and I’ll suggest a third that won’t leave developers frustrated and angry with you.

Read more »