.netasp.net-mvcnservicebusesbazureservicebus

Custom in-memory application bus as placeholder for Azure Service Bus


We have an application that I would characterize as complex. The application is POS terminal software that initially will run only on one computer, but later should be easily scalable to many computers with central (possibly cloud) storage: many client terminals, application server with WCF services, database server.

In an MVC 4 application, we wanted to A) keep the controlllers in the application light weight by moving the (business) logic from the controllers to services. That has been blogged and written about in books numerous times and seems a "right" way to decouple things.

Step B) would be to remove the coupling between the controllers and the services by introducing an (in-memory) application bus. I say in-memory because we don't need (want) an ESB right now.

So a controller would never call a service directly. Instead:

For instance, in LineItemController.cs:

ILineItemDetailService _service;
....
public void CreateLineItemDetail( DetailInfo d )
{
    _service.CreateLineItemDetail( d );
}

...would become something like:

IBus bus;
...
public void CreateLineItemDetail( DetailInfo d )
{
    _bus.Send( new LineItemDetailMessage( d ) );
}

A handler for this type of LineItemDetailMessage will receive the object and in turn call the LineItemDetailService. And so forth.

Our requirements are speed and realiability (duh!), as there can be a lot of data (>1000 messages per minute) being sent over the bus to the services, and eventually to the database.

My quesiton is, since we don't want to use Azure or cloud services right now, is it easy to replace such a custom application bus later on with Azure SB or NSerivceBus?

Or do you suggest "biting the bullet" and do it right away, use NServiceBus?

What performance hit are we looking at here if we are using a bus (loosely coupled) isntead of calling the service directly (tight coupling)?

Has anyone done this before and what is your experience with the application bus pattern?

So is writing a custom "bus" as a "placeholder" for future move to Azure even feasable?


Solution

  • NServiceBus provides exactly the kind of IBus abstraction you're talking about. It also has a separate plugin model for transports so you can run it locally purely in-memory if you want, as well as on top of MSMQ, RabbitMQ, SQL Server, and on top of cloud services like Azure Service Bus and Amazon SQS/SNS as well.

    Let me repeat that - you can use Azure Service Bus under NServiceBus with just some minor changes in configuration/initialization code.

    Here's the docs on that: https://docs.particular.net/nservicebus/azure/

    You won't have much of a performance hit by introducing NServiceBus. Even when running on fully durable and transactional infrastructure, you can get up to several thousand messages per second - well above the target you set.