views:

394

answers:

2

We currently have an application that uses service broker to queue messages to sent to an external system, which we communicate with via a web service interface.

At present we only integrate with a single company, so one queue is sufficient - however we need to start passing messages to multiple companies who all use the same web service interface.

I'm wondering if a single queue system is sufficient for this or should we have a queue per company. With a queue per company I'm worried about scaling this out as we could have lots of queues and then lots of connections to check the queues.

With a single queue however we can just add more readers as required. However, if we cannot communicate with one of the external systems (e.g. connectivity issue), then there isn't an issue with the message, and we'd want to retry it, but we don't want to delay messages for companies whose systems are up. I was wondering how people are currently dealing with similar scenarios?

We could reinsert the message, but the concern I have about that is that we don't guarantee order of delivery.

+2  A: 

I'm assuming that by "reinserting" a message you mean just rolling back the transaction that received it. The effect will be that the message will become available for receive again, as a first message from the given conversation (so you don't need to worry about preserving the order of delivery). That said, there is a problem with this approach, namely the poison message handling. If 5 consecutive receives from a given queue are rolled back, the queue will become disabled.

An alternative approach, described in detail in Klaus Aschenbrenner's book, is to have a table of pending requests. As soon as the activated procedure receives a request message from Service Broker queue, it tries to do the web service call. If that fails for some reason, the request is put in the pending requests table and retried every once a while (you can use conversation timers to schedule retries). That way, if a web service is not available, it won't keep blocking the Service Broker reader from servicing other companies (assuming the timeout for the first request is small enough). And since the receive will be committed no matter if the web service call succeeds, you won't run into poison message problem.

Pawel Marciniak
What I mean by re-inserting is that you'd take the message out of the queue and put it back in, so you don't get the poison message handling. However you lose the ordered delivery - I'll look into the pending requests table as you suggested.
spooner
Bought the book and that gives me everything I need. Thanks for the heads up.I think my problem was I was thinking too much about keeping the messages in the queue, rather than trying to utilise other features of the database where it's more appropriate (e.g. the retry table).
spooner
Glad I could help. Many Service Broker usage patterns involve a table that holds the application state between processing related messages (usually keyed by conversation group ID), so that the queue readers may be truly asynchronous.
Pawel Marciniak
A: 

Hi Pawel!

Could you please tell me which example in the Klaus Aschenbrenner's book implements that? (With the web services)

Thanks BS