Search code examples
azureazureservicebusazure-servicebus-topicsazure-servicebus-subscriptions

Should we close session on Azure service bus subscription client


I am using Azure service bus topic/subscriptions with sessions. I am setting a hardcoded value for the sessionId as I want to control processing of incoming messages.

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?If I close session, will the processor with closed session be able to open session and process the message at later?

TIA


Solution

  • Sessions are usually intended for groups of messages and not a single message. When you want those messages to be processed in order (FIFO) a single subscriber should handle that subscription until messages in the session are all processed. And then, what you do, closing a session, is fine as it will expire eventually. Not to mention that your subscriber could start processing another session rather than waiting for an "empty" session to time out.

    In case you have a single message per session, I would advise against using sessions to begin with.