Description
- Package Name: @azure/service-bus
- Package Version: 7.9.4
- Operating system: linux
- nodejs
- version: 20
- browser
- name/version: NA
- typescript
- version:5.1.5
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://learn.microsoft.com
Describe the bug
We have a scenario where a publisher publishes a user's activity to other microservices(consumer), which process the data based on the received event. There is a strict requirement for in-order processing of events at the consumer side. We have been using service bus without sessions for some use cases, and want to use a service bus for this scenario as well. We have done a PoC, but we couldn’t come up with a good implementation for the sessions. Here’s what we have done
- Created a session enabled service bus.
- We are using userId as the sessionId at the publisher side
- Due to the large number of users, consumers won’t know the session IDs. So, we use acceptNextSession to retrieve the next available session and create a session-enabled receiver.
- Subscribe to the receiver and process messages as they arrive.
If there are no sessions available at the time of deployment then acceptNextSession timeout because it can not find a non empty session. So one consumer instance can consume only one user's event and then wait for the next message from the same user, which means only 10-15 user's event can be processed until or unless consumer restarts(or we do it in loop with handling many scenarios) and gets a session corresponding to a different user .
This seems to be a common use case. We searched extensively online but couldn’t find any good solution besides using a sessionRoundRobin. We have seen similar(#10330 created a long time back) and related issues in this repository but none of them gives an elegant solution.
Could you help us with a better solution for this scenario (Not very comfortable with round robin code)? or is this not the right use case for service bus?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A consumer is assigned a session and processes all the messages from that session. Once all messages are consumed, a new session is assigned to the consumer, and the process repeats.
Screenshots
N/A
Additional context
N/A