1

I am listing to a topic in azure service bus with the following javascript code.

Library and version @azure/service-bus 1.1.2

        const sbClient = ServiceBusClient.createFromConnectionString(
        config.merchant_event.connection_string
         );
        const topicClient = sbClient.createSubscriptionClient(
         config.merchant_event.topic_name,
         config.merchant_event.subcription_name
       );

  const receiver = topicClient.createReceiver(ReceiveMode.ReceiveAndDelete);

  receiver.registerMessageHandler(
      merchantEventMessageHandler,
      merchantEventErrorHandler
    );

As soon as the application starts, it working fine. But if any case connection loss or connection time out, the listener will stop listening.

Can you please advise how to address this. Is there any retry mechanism to enable for reconnect the connection if it is a loss.

Dinusha
  • 696
  • 1
  • 14
  • 27

1 Answers1

0

Version 1

If the clients had gone into a bad state due to the connection loss, you'd need to re-create the clients/receivers in Version 1 @azure/service-bus SDK. Here is a related issue on GitHub that talks about the registerMessageHandler and retries - azure-sdk-for-js/issues/11914.

However, I'd recommend you leverage the subscribe method that is offered in version 7 of @azure/service-bus SDK instead.

Version 7

You can leverage the subscribe method if you want to receive the messages forever(you can stop receiving as needed).

subscribe handles the disconnects and reconnections gracefully and is capable of recovering even from fatal errors such as entity-not-found.

You can refer to the receiveMessagesStreaming.ts sample code that uses version 7 of @azure/service-bus SDK.

I know this is a late reply, but just in case someone is running into issues with the older service-bus node SDK and landed here, refer to the links below.

The latest version 7.0.0 of @azure/service-bus has been released recently.