Using Sessions in synchronous Request-Response patterns

1k Views Asked by At

I am trying to get sessions to work in the following architecture.

  • Multiple heterogenous worker roles that monitor and process requests from queue1, and send their responses to queue2.
  • One front web role, which receives requests from outside via REST or SOAP, submits them into queue1, and waits for a response from queue2. Once it's received, the response is returned to the caller.

The web role is there to leverage scalability and allow the worker roles to be created dynamically when the load is too high (which is why the entire Ruth Goldberg machine, there is no way without the service bus).

I am using a call to:

MessageSession sess = myQueueClient.AcceptMessageSession(mySessionId, TimeSpan.FromSeconds(timeoutPerSec));

which is followed by:

BrokeredMessage bm = sess.Receive();

and the call to AcceptMessageSession crashes and burns with the exception:

BR0012A sessionful message receiver cannot be created on an entity that does not require sessions. Ensure RequiresSession is set to true when creating a Queue or Subscription to enable sessionful behavior.

Now I do set RequiresSession to true:

        if (!_queueManager.QueueExists(clientID))
            _queueManager.CreateQueue(clientID).RequiresSession = true;
        else
            _queueManager.GetQueue(clientID).RequiresSession = true;

but it does not help.

What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

You have to create a queue with RequiresSession set to true in QueueDescription when you create a queue, not in a QueueDescription of already created queue.

So you in your case queue creation should look similar to this:

    if (!_queueManager.QueueExists(clientID))
    {
        QueueDescription queueDescription = new QueueDescription(clientID)
        {
            RequiresSession = true
        };
        _queueManager.CreateQueue(queueDescription);
    }