Azure Service Bus request reply pattern

Incahuazi 16 Reputation points
2020-06-04T11:15:39.677+00:00

Hello,

I'm trying to use the request reply pattern as described in the Microsoft Learn (https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions#request-response-pattern)

"Multiple applications can send their requests to a single request queue, with a specific header parameter set to uniquely identify the sender application. The receiver application can process the requests coming in the queue and send replies on the session enabled queue, setting the session ID to the unique identifier the sender had sent on the request message. The application that sent the request can then receive messages on the specific session ID and correctly process the replies."

As I understand it, it should be possible to send a message from multiple applications, have the receiver handle the message and send a response that will only be picked up by the initial sender.

Maybe I'm wrong, but a bit like this.
8986-20200528-165556.jpg

I couldn't find extensive documentation on this (only using sessions for ordered message handling) and I have no luck finding how to implement this.

Does anybody have an idea/experience with this?

I am using .net core 3.1 with the microsoft azure servicebus package (4.1.2)

Thanks in advance for any assistance!

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
544 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Incahuazi 16 Reputation points
    2020-06-05T13:34:22.4+00:00

    Hello Seanfeldman,

    Thank you for your reply!

    However, it took some figuring out but I think I was able to achieve the setup from the diagram.

    The process now is as follows:

    I have one normal queue (PostNL queue) and one shared 'applications' queue that is sessions enabled

    • An application (e.g App1) sends a message to the PostNL queue using a QueueClient and setting a unique SessionId
    • The receiver handles the incoming messages through QueueClient.RegisterMessageHandler
    • The receiver processes the message and sends a reply to the applications queue using QueueClient.SendAsync (the replymessage has the SessionId set to UniqueSessionId)
    • The sender uses a session = SessionClient.AcceptMessageSessionAsync("UniqueSessionId")
    • The sender can start receiving messages in this session using session.ReceiveAsync
      (all the other applications listening on the applications queue will not compete for these reply messages as long as they use other session Ids)

    Although a bit confusing, I do think that this setup is what is meant in the documentation.

    Greetings.

    3 people found this answer helpful.

  2. Sean Feldman 211 Reputation points MVP
    2020-06-05T06:01:10.503+00:00

    A few clarifications first.

    1. Request/Reply is not the same as Request/Response. Request/Reply is usually associated with asynchronous messages while Request/Response with the web.
    2. For request/reply to work, both the sender and the receiver require a designated queue. In your diagram App1 and App2 share the same queue, which makes them competing consumers over the replies rather than unique handlers. Either those are two instances of a scaled-out logical endpoint or they need to have their own queues.
    3. Message sessions are designed for ordered message processing first and foremost. I.e. when you need FIFO processing and preserve the order of messages grouped logically in a multiplexed queue.

    As I understand it, it should be possible to send a message from multiple applications, have the receiver handle the message and send a response that will only be picked up by the initial sender.

    That's correct. You'll need to have each request message to have an identifier where the reply should be sent to. With Azure Service Bus it can be accomplished by assigning the ReplyTo property on the original message with the value of the sender's queue. That way, the receiver will know where the reply should be sent to.

    1 person found this answer helpful.
    0 comments No comments

  3. Francois Nguyen 1 Reputation point
    2021-07-15T17:33:26.483+00:00

    I think what may work is a service bus with a topic for the PostNL to apps (One to many).
    Each app reads from the topic and send back responses on the queue (Many to one)
    In your topic message you can set the Reply to with the name of the queue to send the response.

    0 comments No comments