This question already has an answer here:
- Getting “amqp:internal-error” when peeking messages from Azure Service Bus Queue using AMQP, rhea and Node 1 answer
I'm trying to "Peek" messages from an Azure Service Bus queue using nodeamqp10
library but unfortunately I am not able to do so.
Here's the code I am using:
const AMQPClient = require('amqp10/lib').Client,
Policy = require('amqp10/lib').Policy;
const protocol = 'amqps';
const keyName = 'MyPolicy';
const sasKey = 'My SAS Key'
const serviceBusHost = 'account.servicebus.windows.net';
const uri = protocol + '://' + encodeURIComponent(keyName) + ':' + encodeURIComponent(sasKey) + '@' + serviceBusHost;
const queueName = 'queue-name';
const policy = Policy.ServiceBusQueue;
policy.receiverLink.attach.rcvSettleMode = 1;
var client = new AMQPClient(policy);
client.connect(uri)
.then(function () {
return Promise.all([
client.createReceiver(queueName),
client.createSender(queueName)
]);
})
.spread(function(receiver, sender) {
sender.on('errorReceived', function (tx_err) { console.warn('===> TX ERROR: ', tx_err); });
receiver.on('errorReceived', function (rx_err) { console.warn('===> RX ERROR: ', rx_err); });
receiver.on('message', function(message) {
console.log('Received message');
console.log(message);
console.log('------------------------------------');
messages.push(message);
});
var messageOptions = {
'applicationProperties': {
'operation': 'com.microsoft:peek-message'
}
};
return sender.send({}, messageOptions);
})
.error(function (e) {
console.warn('connection error: ', e);
});
Few things are happening with this code that I am not able to comprehend:
- The code above fetches the messages but it is fetching them in
Peek/Lock
mode i.e. every time I run the code, the delivery count of messages is increasing by one which is not what I am looking for. - The code above inserts a message in a queue every time it is run. I only want to fetch the messages from the queue and not insert any new message.
I have gone through the documentation here
, and based on this I am specifying operation
as com.microsoft:peek-message
in applicationProperties
which should only allow peeking at messages and not peeking and locking them.
Can anyone please tell me what am I doing wrong here?