I asked the very same question few days ago: Unable to "Peek" messages from an Azure Service Bus Queue using AMQP and Node. I'm asking the same question again but with a few differences (hence, please don't mark this question as a duplicate of the other question):
- In the previous question, I was using
nodeamqp10
library however based on some comments on the Github page for this library, I ended up usingrhea
instead ofnodeamqp10
library. - With some help from Azure Service Bus team, I made some progress and now I am getting an error back from Azure Service Bus which tells me that I am on the right track.
Here's the new code I am using:
var client = require('rhea');
const keyName = 'MyCustomPolicy';
const sasKey = 'SAS Key'
const serviceBusHost = 'account.servicebus.windows.net';
const queueName = '003';
client.on('connection_open', (context) => {
context.connection.open_sender({
target: { address: `${queueName}/$management` }
});
});
client.once('sendable', (context) => {
console.log('messages can be sent now....');
var receiver = context.connection.open_receiver({
source: { address: `${queueName}/$management` },
autoaccept: false,
target: { address: 'receiver-link' }
});
receiver.once('receiver_open', (context) => {
console.log('receiver is now open....');
});
receiver.once('message', (context) => {
console.log('message received by receiver....');
console.log(context.message);
});
var messageBody = {
'from-sequence-number': 1,
'message-count': 5
};
const msg = {
application_properties: {
operation: 'com.microsoft:peek-message'
},
body: client.types.wrap_map(messageBody),
reply_to: 'receiver-link'
};
context.sender.send(msg);
console.log('message sent....');
});
client.connect({
transport: 'tls',
host: serviceBusHost,
hostname: serviceBusHost,
username: keyName,
password: sasKey,
port: 5671,
reconnect_limit: 10
});
Now when I run this code, I'm getting 500
error back from Azure Service Bus:
{
"application_properties":
{
"statusCode":500,
"errorCondition":"amqp:internal-error",
"statusDescription":"The service was unable to process the request; please retry the operation. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101 Reference:ab667ed6-1565-4728-97b7-6ae4a33468b9, TrackingId:538f93a1-2c07-4bc0-bf41-dc00d7ae963c_B13, SystemTracker:account-name:Queue:003, Timestamp:8/2/2018 7:43:52 AM",
"com.microsoft:tracking-id":"538f93a1-2c07-4bc0-bf41-dc00d7ae963c_B13"
}
}
I even checked the link included in the error message (http://go.microsoft.com/fwlink/?LinkId=761101) but there is no mention of amqp related errors on that link.
As in the previous question, if I use address as just the queue name instead of queue-name/$management
, I am able to get the messages but the messages are locked and the delivery count for the messages is increasing. Furthermore, it is returning all the messages from the queue instead of just 5 messages that I am requesting.
I'm not sure what I am doing wrong. Can someone help?
With help of Azure Service Bus team, I was able to find a solution to this problem (in fact, they gave me this solution). Essentially elements of
messageBody
should be properly encoded using AMQP types.Following code works: