Azure service bus topic c# CloseAsync()

diego gutierrez 161 Reputation points
2021-03-04T20:18:41.687+00:00

Hi. I cannot figure out how work with the RegisterMessageHandler and CloseAsync(). I have a C# web app that connects with a azure service bus topic with this code: subscriptionClient.RegisterMessageHandler( async (message, token) => {.....await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); ........ } When I deploy this app to the IIS, everytime a message is inserted in the topic, its processed inmediately. The problem comes when I put the following code: await subscriptionClient.CloseAsync(); After I upload the new version it never processes again when a message is inserted, without this line, the webapp is able to process the messages every time they are inserted. Please Can someone explain to me why this line makes my process fail?

It also happens in Visual Studio environment, when I am in debug mode, every time I insert a new message it is processed without await subscriptionClient.CloseAsync(), but when I put this line if I insert a new message its not processed anymore.

Thanks in advance.

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
552 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,591 Reputation points Microsoft Employee
    2021-03-05T06:43:41.15+00:00

    @diego gutierrez That is the expected behavior. The RegisterMessageHandler handles creates an internal thread to listen and process messages as they come in but the CloseAsync call closes the connection and thereby the handler loop as well.

    If your intention is to process a message on request, you would need to use the MessageReceiver.ReceiveAsync directly instead for such a case.