Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Service Broker as a generic Enterprise Message Bus for .net

I'm in need of an Enterprise Service Bus/Message Queueing solution for publisher/subscriber functionality. I know MANY exist... MSMQ, MS Series, RabbitMQ, NServiceBus, etc etc etc...

My one requirement is that in a shared hosting solution, the only dependency that I can guarantee will exist is SQL 2005 and later... this leads me directly to SQL Service Broker.

If it sounds like I'm trying to shoehorn ESB functionality into SSB... I suppose I am...

My question is: does anyone know of a .NET API or framework that sits on top of SQL Service Broker and already provides much of the plumbing?

If I were to use pure ADO.net, I could add items to the queues by calling a stored procedure, but then:

  1. Do to the nature of conversations, would I make one conversation per message?
  2. If so, do I lose sequential message processing?
  3. How do I receive messages (I know the receive syntax in t-SQL), do I call a stored procedure repeatedly in a message loop to try to get a message off the queue?
  4. Or would I WAITFORever? Keeping the connection open and executing the stored procedure forever?
  5. SQL Service Broker doesn't support monologue conversations, but I read they can be implemented...

It's these kind of questions that make me wish there existed a .net solution that already managed all of this.

like image 611
Novox Avatar asked May 13 '14 14:05

Novox


People also ask

What is SQL Service broker used for?

Service Broker provides queuing and reliable messaging for SQL Server. Service Broker is used both for applications that use a single SQL Server instance and applications that distribute work across multiple instances. Within a single SQL Server instance, Service Broker provides a robust asynchronous programming model.

Are service brokers deprecated?

A few additions were made in 2008 and since then only relatively minor additions have made their way into the product. This tends to lead some people to the (incorrect) conclusion that Service Broker is becoming deprecated – this is most definitely not true.

What is the basic feature that all service brokers should have?

A Service Broker service has the following characteristics: Services are always defined within the scope of a database. The service contains application logic (code) and the associated messages (state) A contract describes in which directions messages can be exchanged with the service.


Video Answer


1 Answers

There was an effort to package a WCF Transport Channel for SQL Server Service Broker but, afaik, is abandonware.

But NServiceBus supports Service Broker as a transport, see Using NServiceBus and ServiceBroker.net and there are github projects like A simple wrapper API for SQL Service Broker and an ITransport plugin for NServiceBus. While not exactly mainstream, some support and community effort does exists.

As an ESB I think you will have problems due to lack of true pub-sub and broadcast. SQL Server 2012 has the ability to SEND a message to multiple targets, see How to Multicast messages with SQL Server Service Broker, but you will still have to implement the pub-sub infrastructure (publishing topics, subscribers etc) from scratch. MySpace did that and was a major effort, see Scale out SQL Server by using Reliable Messaging. My observation reffers to the low level direct use of SSB, I have never used NServiceBus so I cannot tell how well does it abstracts/expose unicast/broadcast/multicast/pub-sub over SSB.

As for your specific questions, I recommend reading Writing Service Broker Procedures and Reusing Conversations.

like image 190
Remus Rusanu Avatar answered Oct 25 '22 15:10

Remus Rusanu