RabbitMq anti-starvation pattern

849 Views Asked by At

The problem to solve: Prevent a customer from starving other customers.

I plan for every customer to have their own queue and then one Consumer consuming from all those queues. In my case there could be hundreds of customers, but queues are cheap. Having a reasonable low prefetch count the default broker behavior (to randomly select which queue to pop from) should yield a satisfying result.

enter image description here

The issue with this strategy is when a new customer comes along. I can lazily create the queue and bind it to the exchange msg.in in the Publisher. But how do I get the Consumer to consume from this new customer.xxx queue?

It's almost the Topics pattern, but not really since I need a buffer per client. Nor can this be solved with Priority which will screw up the per customer message order. Is there a way to consume based on a pattern? Like there is for binding, eg. customer.*.

Polling the management API is an option, but will delay the processing of the first message of a new customer until the Consumer have polled. Having a separate pub/sub channel for meta-data like new customer.003 that the Consumer could act upon would reduce the latency (and avoid polling the API), but will make the Publisher more complex.

I've a feeling there's a nice solution out there, I just haven't been able to find it yet. Thankful for your feedback!

0

There are 0 best solutions below