DEV Community

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

Posted on

2 3

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️