Search code examples
azureasync-awaitazureservicebusazure-webjobs

Azure Service Bus ReceiveMessages with Sub processes


I thought my question was related to post "Azure Service Bus: How to Renew Lock?" but I have tried the RenewLockAsync.

Here is the concern, I am receiving messages from the ServBus with Sessions enabled so I get the session then receive messages. All good, here's the Rub.

There are TWO ADDITIONAL processes to complete per message. A manual transform / harvest of the message into some other object which is then sent out to a Kafka topic (stream). Note its all Async on top of this craziness. My team lead is insistent that the two sub processes can just be added INTO the receive process (ReceiveAsync) and finally call session.CompleteAsync() AFTER the OTHER two processes complete.

Well needles to say I'm consistently erroring with "The session lock has expired on the MessageSession. Accept a new MessageSession." with that architecture. I haven't even fleshed out the send to Kafka part its just mocked so its going to take longer once fleshed out.

Is it even remotely plausible to session.CompleteAsync() AFTER the sub processes or shouldn't that be done when the message is successfully received, then move on to other processing? I thought separate tasks would be more appropriate but again he didn't dig that idea..

I appreciate all insight and opinions thank you !


Solution

  • "The session lock has expired on the MessageSession. Accept a new MessageSession." indicates one of 2 things:

    • The lock has been open for too long, in which case calling "RenewLockAsync" before it expires would help.
    • The message lock has been explicitly released, through a call to CompleteAsync, AbandonAsync, DeadLetterAsync, etc. That would indicate a bug, since the lock can not be used after it has been released