0

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.

H4p7ic
  • 1,669
  • 2
  • 32
  • 61

2 Answers2

2

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.

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

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 having 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.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • Ok, so i don't know if i am completely out of scope here but if i understand your comment correctly what you are saying is: Message Sessions put the incoming messages in the right order to later be polled out in the right order on the other end? So that is if i had a logic app pulling the messages they would still come in order less so to speak because the logic app is scalable/threaded? – H4p7ic Nov 13 '17 at 14:00
  • I've read up a bit on Message Sessions, the message will require a Session-ID. So what is the best way to implement one and and how do i handle in best practice how to increment the session ID for each message? – H4p7ic Nov 13 '17 at 15:51
  • It's important to provide details as what service / environment you're using to get a better answer :) If you're using Logic Apps, then you have an implementation of what's known as "Sequential Convoy" pattern. For that, Logic Apps provides a template that can correlated in-order delivery with Azure Service Bus message sessions. There's a post on it you can read [here](https://blogs.msdn.microsoft.com/logicapps/2017/05/02/in-order-delivery-of-correlated-messages-in-logic-apps-by-using-service-bus-sessions/). – Sean Feldman Nov 13 '17 at 17:50
  • _"what's the best way to implement"_ - it depends. If you have all messages as a part of a single session or not. You'd be looking at configuring Session ID **Next Available** if you have multiple sessions or **Next Available** if a single session with all of your messages. Hope that helps. Cheers. – Sean Feldman Nov 13 '17 at 17:51
  • I think that got me pointed in the right direction, i will definitely look into this, Thank you for your quick answer. – H4p7ic Nov 14 '17 at 06:06
  • Just adding this note here in case anyone is attempting to do this with azure function app. Currently sessions are supported as part of Microsoft.Azure.webJobs.Extensions.ServiceBus V3.1.0-beta2. For how to implement see [here](https://stackoverflow.com/questions/51298378/session-based-service-bus-with-azure-function). Note - You must remember to manually remove your session after completed use, to avoid additional storage. Session do not expire. – KingNDj Jul 24 '19 at 08:57