Sorting Service Bus Queue Messages

i was wondering if there is a way to implement metadata or even multiple metadata to a service bus queue message to be used later on in an application to sort on but still maintaining FIFO in the queue.

So in short, what i want to do is: Maintaining Fifo, that s First in First Out structure in the queue, but as the messages are coming and inserted to the queue from different Sources i want to be able to sort from which source the message came from with for example metadata.

I know this is possible with Topics where you can insert a property to the message, but also i am unsure if it is possible to implement multiple properties into the topic message.

Hope i made my self clear on what i am asking is possible.

2 answers

  • answered 2017-11-12 20:10 Mikhail

    I assume you use .NET API. If this case you can use Properties dictionary to write and read your custom metadata:

    BrokeredMessage message = new BrokeredMessage(body);
    message.Properties.Add("Source", mySource);
    

    You are free to add multiple properties too. This is the same for both Queues and Topics/Subscriptions.

  • answered 2017-11-13 07:51 Sean Feldman

    i was wondering if there is a way to implement metadata or even multiple metadata to a service bus queue message to be used later on in an application to sort on but still maintaining FIFO in the queue.

    To maintain FIFO in the queue, you'd have to use Message Sessions. Without message sessions you would not be able to maintain FIFO in the queue itself. You would be able to set a custom property and use it in your application and sort out messages once they are received out of order, but you won't receive message in FIFO order as were asking in your original question.

    If you drop the requirement of havign an order preserved on the queue, the the answer @Mikhail has provided will be suitable for in-process sorting based on custom property(s). Just be aware that in-process sorting will be not a trivial task.