locked
AcceptMessageSession - serverWaitTime What is this? RRS feed

  • Question

  • Hi,

    I am developing code to send messages and receive responses via service bus. Messages and responses are paired via a SesionID.

    I am trying to understand the various timeouts that are available

    My code (first draft) looks like this:

            public async Task<TResponse> SendMessageAsync(TMessage message)
            {
                // send request message
                var msg = CreateRequestMessage(message);
                _requestClient.SendAsync(msg);
    
                var receiver = await _responseClient.AcceptMessageSessionAsync(msg.ReplyToSessionId, TimeSpan.FromMilliseconds(TimeoutMs)).ConfigureAwait(false);
                try
                {
                    // receive response message
                    BrokeredMessage receivedMessage = await
                        receiver.ReceiveAsync(TimeSpan.FromMilliseconds(TimeoutMs)).ConfigureAwait(false);
                    if (receivedMessage != null)
                    {
                        var body = receivedMessage.GetBody<Stream>();
                        return _serializer.DeserializeObject<TResponse>(new StreamReader(body, true).ReadToEnd());
                    }
                    else
                    {
                        throw new TimeoutException();
                    }
                }
                finally
                {
                    receiver.Close();
                }
            }

    I am testing all my assumptions within the code and am trying to figure out the effect of the serverWaitTime parameter within the AcceptMessageSessionAsync call.

    I cant figure it out and the docs are unclear (at least to me ;-). Whatever the value (even TimeSpan.FromTicks(1)) the call returns a MessageSession immediately. No nulls, no TimeoutException.

    Only the serverWaitTime on ReceiveAsync seems to make a difference.

    Am I missing something? Can someone please explain the serverWaitTime parameter in the AcceptMessageSessionAsync method.

    Thanks,

    M

    Tuesday, March 21, 2017 4:11 PM

All replies

  • operationTimeout - This on factory settings. Server will honor this while fulfilling the request.

    serverWaitTime - This is client timeout value. Client will give up on the request if server won't return in the given time window.

    * If you do not specify serverWaitTime, client will take operationTimeout as the default wait time.

    * If you specify a small timeout, I believe the client still adds a buffer on top of that like couple seconds. That is why your AcceptMessageSessionAsync returns a valid session even with small timeout value.

    Let me know if you have any other questions.

    Wednesday, March 22, 2017 5:58 PM
  • Thank you. That makes it much clearer.

    One more question though..

    If AcceptMessageSessionAsync does time out does it return null (like ReceiveAsync), or does it throw an exception?

    Thanks.

    M

    Thursday, March 23, 2017 10:29 AM
  • AcceptMessageSessionAsync throws System.TimeoutException if there are no available sessions to receive.
    Tuesday, April 11, 2017 4:09 PM
  • AcceptMessageSession() takes serverTimeOut value as argument, which specifies how long accept operation will wait on session.

    This value cannot be less than one minute. If you specify for example TimeSpan.FromSeconds(10), it will not fail, but it will be rounded to one minute.

    This method does not return NULL after session is not accepted. It throws with TimeOutException.


    Damir Dobric
    developers.de
    daenet.de
    daenet.eu
    daenet.com

    Thursday, June 20, 2019 1:45 PM