Retrieve records from Azure Service Bus queue but not deleting data

I followed below sample from "https://github.com/noodlefrenzy/node-amqp10" to retrieve records from Azure Service Bus queue.  However, all data were deleted after run the code. 
const AMQPClient = require('amqp10').Client;
const Policy = require('amqp10').Policy;

const protocol = 'amqps';
const keyName = 'RootManageSharedAccessKey';
const sasKey = 'your_key_goes_here';
const serviceBusHost = 'namespace.servicebus.windows.net';
const uri = `${protocol}://${encodeURIComponent(keyName)}:${encodeURIComponent(sasKey)}@${serviceBusHost}`;
const queueName = 'partitionedQueueName';
const client = new AMQPClient(Policy.ServiceBusQueue);
client.connect(uri)
.then(() => Promise.all([client.createReceiver(queueName)]))
.spread((receiver) => {
    console.log('--------------------------------------------------------------------------');
    receiver.on('errorReceived', (err) => {
        // check for errors
        console.log(err);
    });
    receiver.on('message', (message) => {
        console.log('Received message');
        console.log(message);
        console.log('----------------------------------------------------------------------------');
    });
})
.error((e) => {
    console.warn('connection error: ', e);
});
I did a research and found out that I need to add "receiverSettleMode" to the value "Constants.receiverSettleMode.settleOnDisposition" within"client.createReceiver" function. So added following code before "client.connect(uri)":
const { Constants }= require('amqp10');

Updated the "client.createReceiver" function to
client.createReceiver(queueName, {
attach: {
rcvSettleMode: Constants.receiverSettleMode.settleOnDisposition
}
})

Execute the code and it works! All records are still there after processing.

To learn more about "Azure Solution Development", see this course"70-534 Architecting Microsoft Azure Solutions Certification"


Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

Effective LLM Prompting skills

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search