Posted by David Boike on February 8, 2013
The NServiceBus Host process is a pretty amazing piece of software that hosts your message handlers, can be run from the command line or installed as a Windows service, and is supremely extensible. This is a great strength for NServiceBus but it can also be a little overwhelming for the developer just starting to wade into the great pool of service bus logistics.
Much of how an endpoint will configure itself is based on Profiles and Roles:
- Profile – controls the environment and features the endpoint is supposed to run with. These are set at the command line by passing the class name (or names) of the desired profile (or profiles) like “NServiceBus.Host.exe NServiceBus.Integration”. Because this is set at run-time, this allows the same collection of code to run in different configurations depending on environment.
- Role – controls what services the endpoint will need based on how it will interact with other services. There are 3 defined roles: AsA_Client, AsA_Server, and AsA_Publisher, and these are set in code, so these are static for an endpoint.
In this blog post I will try to spell out everything that these profiles and roles do, based on my experience and source code snooping with Reflector. Use this as a quick reference so you don’t have to go hunting through reflected source yourself.
Note that all of this information is based on NServiceBus 3.3.4. I’m positive that things will change as new versions are released.
Read more »
Posted by David Boike on October 6, 2012
Today I had a great time presenting Enterprise Service Bus Development with NServiceBus at the Fall 2012 Twin Cities Code Camp. I wasn’t sure before presenting if we would have enough time to get into sagas, and as it turned out, we ran out of time right in the middle!
So as promised, I finished the saga code and pushed it all to GitHub. Here is the link to my Twin Cities Code Camp 13 NServiceBus Example Code. Please feel free to clone it and explore!
Posted by David Boike on March 12, 2012
If you run an ASP.NET website with any non-trivial amount of traffic, the last thing you want to do is try to load an external resource with a web request. Even if you cache it, you’ve taken on that external source as a dependency to your system, which means that your website is only as reliable as the external source you depend on.
The primary strategy I’ve seen to cope with this is to request the data from the remote service on the first request from the web tier, cache it locally, and then have a background process periodically refresh that cache so that subsequent requests can use locally cached data.
Even with this background-updated cache, eventually the external resource will suffer some sort of issue. The data in the cache grows old and is invalidated, and then the web tier starts requesting the data again, except now, 100 different requests try to open 100 different connections to the remote service to get the exact same data, because either they all fail or none of them can complete quickly enough to store the cache item for the other threads to use. The Thread Pool fills up, and ASP.NET hangs its head and gives up.
Let’s assume that we are talking about a current weather tease that is a small part of a very large page, and that all our current weather information for the end-user’s zip code comes to us from an external provider.
So how do we avoid this mess? We can do it quite handily with a little NServiceBus and jQuery.
Read more »
Posted by David Boike on November 3, 2011
A common question about NServiceBus is how to use it to integrate with an external partner. The requirements usually go something like this:
- The third party will contact us via a web service, passing us a transaction identifier and a collection of fields.
- If we successfully receive the message in the web service, we respond with a HTTP 200 OK status code. If they do not receive the acknowledgement, they will assume a failure and attempt to retry the web service later.
- Once we receive the message from the third party, we need to distribute (think publish) the contents of the message to more than one internal process, each of which are completely independent of each other.
- We need to logically receive each message once and only once. In other words, it would be a “Very Bad Thing” for one of the internal subscribing processes to receive the same notification more than once.
This was most recently asked in this StackOverflow question, where it became difficult to explain more within the 600 character comment limit. The best explanation is example code, so here it is.
Read more »
Posted by David Boike on April 12, 2011
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 »
Posted by David Boike on February 27, 2011
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 »
Posted by David Boike on February 8, 2011
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 »
Posted by David Boike on February 7, 2011
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 NServiceBus. Jonathan 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.
Posted by David Boike on October 27, 2010
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 »
Posted by David Boike on October 21, 2010
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 »