7

So I am trying to understand Azure service bus Session ID for creating FIFO in my queue.

The idea I have is pretty straight forward but I don't know if its the right way to thing when it comes to FIFO.

What i am thinking are in these steps fro creating FIFO in my queue:

TO CREATE:

First: Check the Queue for messages and their Session ID's to and expose the ID hierarchy.

Next: Create new message with the the latest Session-ID in the hierarchy and iterate that value by 1 (+1)

Next: Send to Service Bus Queue.

TO READ:

First: Check the Queue for messages and their Session ID's to and expose the the ID hierarchy.

Next: Read-And-Delete the earliest Session-ID in the hierarchy.

Next: Process...

Keep in mind I haven't included error handling and such for example the read-and-delete part, because that I have already figured out.

So the question is is this the right way of thinking and also, how do I achieve this in C# I cant really find something that explains this concept in a straight forward manner.

H4p7ic
  • 1,669
  • 2
  • 32
  • 61

2 Answers2

12

To elaborate:

Lets say you have 9 total queue messages and these are grouped into three sessions, session ids 1, 2, and 3. Each group of 3 messages will then be processed in order (First in first out).

However, parallelism can still occur between sessions - or between each group of messages - if there is more than one queue listener.

Each listener/processor of the queue storing all 9 messages gets a lock on all the messages that share the same session id and then processes each message one at a time until the session is complete (usually when there are no more messages left in the queue with that session id unless you turn off AutoComplete and decide to manually close the session whenever you deem it necessary).

Hopefully that makes sense.

boylec1986
  • 520
  • 5
  • 12
  • 1
    Which session out of the 3 is retrieved and locked first? (In case there are no more than 1 listener) – Deepak Dec 29 '20 at 14:18
  • 1
    It will be the session referenced by the first message to arrive in the queue because it is a FIFO queue. – boylec1986 Oct 16 '21 at 09:22
6

So I am trying to understand Azure service bus Session ID for creating FIFO in my queue.

Assuming you've gone through the documentation on Message Sessions and haven't skipped the linked sample for Microsoft.Azure.ServiceBus and WindowsAzure.ServiceBus, you'll notice that the latter sample has an extensive explanation on how sessions operate.

You don't "create" a FIFO queue, you just use it with sessions and that's how you achieve what you need. Sessions have their use cases. One of them is your scenario, where you have one indefinite session with a single session ID to keep your messages in orde.

Note: be aware of the limitations (no parallel processing which will affect your throughput).

how do I achieve this in C# I cant really find something that explains this concept in a straight forward manner.

The older client sample provides an answer to your implementation related question with very solid breakdown and explanations (WindowsAzure.ServiceBus).

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