DEV Community

Cover image for Message Sessions In Azure Service Bus(FIFO Pattern).
Satya Biswal
Satya Biswal

Posted on

Message Sessions In Azure Service Bus(FIFO Pattern).

Introduction:

In this article, we will discuss sessions in the Azure Service bus queue for absolute beginners.

What is Session in Azure Service Bus?

Azure Service bus sessions ensure ordered handling of unbounded messages. Sessions are useful if your application demands an ordered message delivery (FIFO Pattern) or waits for a response after the message being delivered (Request-Response Pattern).

In this article, we'll be discussing FIFO Pattern.

Problem:

Let's assume we're building an application where we'll send a series of messages which are related to each other and moreover the sequence how it will be received and processed is very important. Looks easy. But there is a catch. There might be multiple receivers. Now how we'll guarantee the sequential delivery and ensures that single receiver receives and process all messages of the series. Here is the representational image.

Problem

The Azure Service Bus is not prescriptive about the nature of the relationship between messages and doesn't define a model for determining where a message sequence starts or ends.

Solution:

By assigning same session id to each message of the series we can assure the sequential delivery of the messages. When using sessions the service bus queue creates another virtual sub-queue inside and ensure FIFO pattern.

Solution

When the receiver receives one message it holds an exclusive lock on all messages with the received messages session-id that exists in the queue. That exclusive lock will be held till the last message of that session received.

Following are a few important points about sessions:

  • Sessions are not available for Basic price tier.
  • Once session is enabled for a queue, normal sending and receiving of messages won't be available in that queue. Every message should be sent and received with a session lock.

Conclusion:

There are many more features of Azure Service bus and session is one of them. I will be coming up with more articles about the rest of the features.

Watch this space for a code file link.

Useful articles related to Service Bus:

Cover Image Courtesy: Photo by Scott Webb on Unsplash

Top comments (0)