views:

200

answers:

1

Hi, I'm a beginning web developer sitting on an ambitious web application project.

So after having done some research, I found out about SQL Service Broker. It seems like something I could use, but I'm not sure. Since learning it requires someone to put in lots of time, I wanted to be sure that it would fit my needs.

I need to implement a system where website users can submit text to the website. This stream of messages has to be redundant and dealt with in a FIFO way, with on the other end of the stream another group of users dealing with the messages.

Now, a message that is being read by one of this last group of users, should be locked so that no-one else can read it at the same time. The user can then decide to handle the message or not. Only if he decides to deal with the message can it be deleted from the queue. If he decides that he doesn't want to deal with the message, the message should be put back in the queue (at the end of the queue, or at least with the highest priority), so that another user can read it and decide.

Is this something I would be able to implement with SQL Service Broker? Am I on the wrong track?

Thank you!

+1  A: 

IMO, the best use of Service Broker is for connecting to independent Application in a loosely coupled way. What I mean by that is that systems tied in this way can communicate through a set of mutually agreed message types. This in contrast to one application manipulating directly the other's database, for example.

From what you've said, I would implement it as a simple table, for example: Create a message table with an identity PK, an Allocation flag and your custom columns. Whenever an operator wants to fetch the last message, get the lowest PK value for which Allocation = 'N' and update Allocation to 'Y'. This in a single transaction. When/if the operation decides to return the message to queue, just set its AllocationFlag to 'N' and its back.

This is just an example. The database in this case is providing you consistency, heavy load performance, etc.

Behind the screens all data you submit to SSB is stored and manipulated as tables, so there is no reason for it to be necessarily faster than a database solution .

LeoPasta
thanks for your answer, it is what I suspected. I just thought that maybe it would be safer if SSB could be used, since it was designed by specialists with queuing in mind + I was not 100% confident in my own programming skills :)
chinmi