简体   繁体   中英

Creating continuous receiver for session enabled subscription from Azure Bus Topic

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?

There's a sample showing how you can continually read through all the available sessions. Could you please check to see if it is helpful?

https://github.com/Azure/azure-sdk-for-js/blob/21ff34e2589f255e8ffa7f7d5d65ca40434ec34d/sdk/servicebus/service-bus/samples/v7/javascript/advanced/sessionRoundRobin.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM