0

I have following ProcessQueueMessage function that gathers messages from service bus queue:

    public static void ProcessQueueMessage([ServiceBusTrigger("dsique2")] BrokeredMessage message,
        TextWriter logger)
    {
        logger.WriteLine($"Processing message: {message}");
        Stream stream = message.GetBody<Stream>();
        StreamReader reader = new StreamReader(stream);
        string s = reader.ReadToEnd();
        //Parse json
        string output = s.Substring(s.IndexOf('{') , s.IndexOf('}') - s.IndexOf('{') + 1);
         var  json = JsonConvert.DeserializeObject<dynamic>(output);
         var TS = Convert.ToDouble(json.ts);
         var Speed = Convert.ToDouble(json.speed);
         var Ped = Convert.ToDouble(json.ped);
         var BrakePed = Convert.ToDouble(json.brakeped);
         var lateralAcc1 = Convert.ToDouble(json.lateralacc1);
         var steeringAngle = Convert.ToDouble(json.steeringangle);
         //sends parsed values to function 
         Program.receive_emulate(0x415, Speed, TS, "offlineSpeed");
         Program.receive_emulate(0x204, BrakePed , TS, "BrakePed ");
         Program.receive_emulate(0x7D, lateralAcc1 , TS, "lateralAcc1 ");
         Program.receive_emulate(0x92, steeringAngle , TS, "steeringAngle ");
}

So basically, whenever data comes from service bus queue as json format, I parse the json, get values and sent each signals to receive_emulate function. The problem is that the function is triggered before the data processing in receive_emulate function ends. What I want to do is, process single message, send them to receive_emulate functions. When function returns, take the second message in the queue. Unfortunately I could not achive this, any ideas would be deeply appreciated. Another even though it is written that Fifo is guaranteed in service bus queues in azure documentation, I notice that my messages are not coming in order. Is there any way to get them in ordered form? Many thanks

emkay
  • 187
  • 12

2 Answers2

1

If I read your code correctly, you are using Azure Functions with Service Bus trigger.

Try setting maxConcurrentCalls parameter to 1 in hosts.json file, which is shown here.

The maximum number of concurrent calls to the callback the message pump should initiate. The default is 16.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
1

Just like @Mikhail pointed out, setting concurrency to one will allow you to process your messages in serial way either via host.json you can

I'll focus on your second question about FIFO. Azure Service Bus does not guarantee order of messages, unless you're using Messaging Sessions. As far as I know, Service Bus sessions are not currently supported with Functions.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80