0

I am looking into Azure service bus topics and subscriptions in our distributed system. I want to control number of messages that can be processed at any given time. Say, we have say 5 nodes in the production and I understand I can specify Maximum number of concurrent calls at the time of creating a subscriber. So if I give it a value of 1, I will be limited to the number of active nodes in the environment.

Was wondering if there is way where I can restrict it further. For instance, process only one message from the subscription at a time even though there are active idle listeners waiting for work.

TIA

Scooby
  • 635
  • 3
  • 9
  • 21

2 Answers2

0

From your description, it sounds more like an use case for Service Bus queues (,in case you haven't explored it). There is a related question asked here https://stackoverflow.com/a/53277505/5344880

But just a thought, even in queues, when a message is being processed (lock acquired), other listeners will be able to pick next messages. So, to restrict this, you may have another queue with just one message at any point in time and all listeners listening to this. once any of your listeners get a lock on this the other listeners, even if free, won't have anything to process.

More information on Service Bus queues, https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions

Guru Pasupathy
  • 440
  • 1
  • 4
  • 13
  • Thanks for your answer. My system currently uses queues. I am moving to topics/subscriptions for business needs. – Scooby May 12 '20 at 12:52
0

I experimented a little more with this and ended up using sessionIds. I am setting a hardcoded value for the sessionId. So even if there are more than one eligible subscribers which can process this message only one will get the sessionlock and process it. I release the lock by closing the session once it is done processing so that new messages can be picked up by any of the processors. My only concern here is, is there any downside of closing the session after completion of message processing?

Scooby
  • 635
  • 3
  • 9
  • 21