Unable to receive some messages from Service Bus Queue

Ahsan Habib 126 Reputation points
2020-06-29T20:35:33.993+00:00

Hello !

I am using Service Bus Client Javascript library("@azure/service-bus": "^1.1.7"). My scenario is, I have an Azure Function which is using Event Hub trigger. After processing data from Event Hub, I am saving data to Azure Service Bus. Then using my client library(Node.js with Typescript), I am listening for incoming Service Bus messages(I am also using Service Bus sessions). During this process I have tried the ReceiveMode both as peekLock and receiveAndDelete.

For peekLock: Some of the messages do not get received and put back to the Service Bus Queue. Using the while loop as you can see from the code screen shot, I am not able to get back the messages automatically. I have to restart the script.

For peekLock: Some of the messages get lost and do not put back to the Queue or Dead-Letter Queue.

I am facing this problem very frequently. I am also testing Azure Event Hubs javascript(with Typescript) client library("@azure/event-hubs": "^5.2.0",). But, It works absolutely fine. I never miss a single message. The size of the messages are 1KB~1.2 KB.

So How do I make sure to get all the messages from Service Bus?

10982-image.png

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
626 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,466 Reputation points
    2020-06-30T10:14:32.17+00:00

    Welcome to Microsoft Q&A! Thanks for posting the question.

    In your scenario, as you have mentioned that using both receive mode you are facing the issue.

    When you are using peekLock mode you observe that some of the messages are not received by your receiver application and restarting the script helps you to consume those messages. Looks like the message was received for the first time. As the client was not able to complete within the lock duration (default 30 sec). Once the lock gets expired the messages were visible again to be consumed by your application.

    I believe you want to mention receiveAndDelete mode when you mentioned “Some of the messages get lost and do not put back to the Queue or Dead-Letter Queue.” . In receiveAndDelete mode, the message is delivered “at most once”. As soon the message is delivered to the client, the message will be deleted from the service bus end.

    Looking into the snippet I can see that you are receiving 10 messages at one time and mapping it. All 10 messages acquire the lock at the same time and if your client is not able to call complete/abandon (due to any issue at the client) within the lock duration then those messages are visible again for the client to be consumed once the lock expires.

    I have tested this https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/servicebus/service-bus/samples-v1/javascript/session.js and didn’t find any issue at my end. Testing your sample code at my end removing the mapping I didn’t found any issue as there was no logic in between the receive and complete calls. But adding the delay (time to execute business logic) the issue was reproduced.

    You can either set the lock duration value to higher value (max 5 minutes) or tweak the receiving messages count according to the test result at your client end.

    I hope this helps. Do let us know if you any further queries.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.