Creating continuous receiver for session enabled subscription from Azure Bus Topic

Viewed 28

We are having a session-enabled azure bus topic. This topic can have multiple messages with distinct session IDs. We want to create a listener/receiver that keeps reading messages from the Topic. As we have multiple dynamic session IDs, we can not use acceptSession to create a handler. We have tried using the methods createReceiver and acceptNextSession methods of ServiceBusClient but they have the following issues

  1. CreateReceiver: This method does not work on session-enabled subscriptions giving a runtime error.

  2. acceptNextSession: This method only listens to the first message and does not read further messages.

Our Current code is :

 const serviceBusSettings = this.appSettings.Settings.serviceBus;
 const sbClient = new ServiceBusClient(serviceBusSettings.connectionString);

 //const receiver = sbClient.createReciver(topicName, subscriptionName);
 const receiver = sbClient.acceptNextSession(topicName, subscriptionName);
 const handleTopicError = async (error: any) => {
             this.logger.error(error);
             throw error;
        };

 (await receiver).subscribe({
        processMessage: handleTopicMessage, // handleTopicMessage is a method passed as an argument to the function where this code snippet exists
        processError: handleTopicError
 });

We also tried implementation one of the sample code repo wiki. But the methods shared in the example seems to be no longer available in new npm version of @azure/service-bus Link to tried example

Can anyone suggest some solution to this?

1 Answers
Related