2

I created a Service Bus Queue following the tutorial in Microsoft Documentation. I can send and receive messages, however, only half of my messages make it through. Literally half, only the even ones.

I tried changing the message frequency but it doesn't change anything. It doesn't matter if I send a message every 3 seconds or 3 messages per second, I only get half of them on the other end.

I have run the example code in all the possible languages and I have tried using the REST API and batch messaging but no dice.

I also tried using Azure Functions with the specific trigger for Service Bus Queues.

This is the receiving function code:

module.exports = async function(context, mySbMsg) {
  context.log('JavaScript ServiceBus queue trigger function processed message', mySbMsg);
  context.done();
};

And this is the send function code:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    var azure = require('azure-sb');

    var idx = 0;
    function sendMessages(sbService, queueName) {
      var msg = 'Message # ' + (++idx);
      sbService.sendQueueMessage(queueName, msg, function (err) {
       if (err) {
         console.log('Failed Tx: ', err);
       } else {
         console.log('Sent ' + msg);
       }
      });
    }

    var connStr = 'Endpoint=sb://<sbnamespace>.servicebus.windows.net/;SharedAccessKeyName=<keyname>;SharedAccessKey=<key>';
    var queueName = 'MessageQueue';

    context.log('Connecting to ' + connStr + ' queue ' + queueName);
    var sbService = azure.createServiceBusService(connStr);
    sbService.createQueueIfNotExists(queueName, function (err) {
      if (err) {
       console.log('Failed to create queue: ', err);
      } else {
       setInterval(sendMessages.bind(null, sbService, queueName), 2000);
      }
    });
};

I expect to receive most of the sent messages (specially in this conditions of no load at all) but instead I only receive 50%.

Rick S
  • 21
  • 2
  • Can you check if the messages you're sending are actually reaching Service Bus Queue? To check, simply remove the receiver and send a fixed number of messages to the queue and check the count of messages. Also, please check if the queue is configured to delete messages automatically after a certain period of time. – Gaurav Mantri Mar 26 '19 at 11:16
  • I changed to another subscription and everything started working flawlessly. Same deploy script, same functions' code. I don't know what was causing the issue. – Rick S Mar 26 '19 at 12:12

1 Answers1

0

My guess is that the reason is that you are only listening to one of 2 subscriptions on the topic and it is set up to split the messages between subscriptions. This functionality is used to split workload to multiple services. You can read about topics here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview and https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

Here sort description from above links: "Partitioning uses filters to distribute messages across several existing topic subscriptions in a predictable and mutually exclusive manner. The partitioning pattern is used when a system is scaled out to handle many different contexts in functionally identical compartments that each hold a subset of the overall data; for example, customer profile information. With partitioning, a publisher submits the message into a topic without requiring any knowledge of the partitioning model. The message then is moved to the correct subscription from which it can then be retrieved by the partition's message handler."

To check this you can see if your service bus have partitioning turned on or any other filters.Turning partitioning off should do the trick in your case I think.

JohanSellberg
  • 2,423
  • 1
  • 21
  • 28
  • Service Bus Queues are mentioned in question and not Topics and Subscriptions. – Gaurav Mantri Mar 26 '19 at 11:30
  • 1
    This helped me debug my issue. I (accidentally) had two listeners to the same topic subscription and Azure seemed to distribute the messages between those two. One listener was only receiving every second message, so 50%. – Heinrich Ulbricht May 30 '21 at 21:05