0

I'm using Azure service bus to send messages across containers in my K8s setup. Implementation of service that receives message is done in Node.js.From the doc page, here is the code I'm using to receive the messages.

serviceBusService.receiveQueueMessage('feedback', function(error, receivedMessage) {

  if (!error) {

   // Message received and deleted

   console.log(receivedMessage);

  //..

   }

});

Everything works as expected for the first time but the messages are not received for the second time. It works as expected when the code snippet is kept inside the setInterval block. Which seems not the intended way of doing this.

Any ideas what could be wrong?

StateLess
  • 5,344
  • 3
  • 20
  • 29

2 Answers2

0

I have not used the js library for ServiceBus client, but the .NET library that has it seems similar methods. So if the js versjon works the same way, so then it receives only one message and you have to continue yourself.

In .Net library there are generally two ways:

  1. You write your own while loop with whatever you think necessary

  2. You use RegisterMessageHandler that seems to be absent from js library

The option number 2 generally does the same and starts the while loop inside the pump so that you don't have to implement it yourself.

You can take a look here on how the while loop is implemented and do something similar to it in js.

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0

Like Mikhail Shilkov has mentioned previously in the comments, I suspect it only receives one message and I'd also recommend using the AMQP libraries.

I know this is a late reply, but just in case someone is running into issues, refer to the links below.

Version 7.0.0 of @azure/service-bus(based on AMQP) has been recently published.