Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

MessageSessionAsyncHandler.OnCloseSessionAsync() gets called only after the MessageWaitTimeout time

$
0
0

Hello,

We are using MessageSessionAsyncHandler as described here:
https://msdn.microsoft.com/en-us/library/azure/dn790528.aspx

With one difference – we register it using the provided factory method:

    QueueClient client = …;
    await this.client.RegisterSessionHandlerFactoryAsync(new QueueMessageReceiverSessionFactory(…),new SessionHandlerOptions
        {
            AutoComplete = true,
            AutoRenewTimeout = TimeSpan.FromSeconds(600),
            MaxConcurrentSessions = 500,
            MessageWaitTimeout = TimeSpan.FromSeconds(60)
        });

    class QueueMessageReceiverSessionFactory : IMessageSessionAsyncHandlerFactory
    {
        public QueueMessageReceiverSessionFactory(…)
        {
            …
        }

        public IMessageSessionAsyncHandler CreateInstance(MessageSession session, BrokeredMessage message)
        {
            return new QueueMessageReceiverSession(…);
        }

        public void DisposeInstance(IMessageSessionAsyncHandler handler)
        {
            var disposable = handler as IDisposable;

            // Dispose the handler if it is disposable
            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
    }

    class QueueMessageReceiverSession : MessageSessionAsyncHandler
    {
        public QueueMessageReceiverSession(…)
        {
            …
        }

        protected override async Task OnMessageAsync(MessageSession session, BrokeredMessage brokeredMessage)
        {
            Console.WriteLine("OnMessageAsync()");
        }

        protected override Task OnCloseSessionAsync(MessageSession session)
        {
            Console.WriteLine("OnCloseSessionAsync()");
            return base.OnCloseSessionAsync(session);
        }

        protected override Task OnSessionLostAsync(Exception exception)
        {
            Console.WriteLine("OnSessionLostAsync()");
            return base.OnSessionLostAsync(exception);
        }
    }

Everything works fine, however the QueueMessageReceiverSession.OnCloseSessionAsync() method gets called only after the MessageWaitTimeout time. There is nothing blocking the OnMessageAsync() method and there are also no exceptions (execution time < 1 sec). The questions I have are as follows:
-    Why is this happening?
-    Is this the expected behavior and if so, what is the purpose of this feature?
-    Is there any concern of a resource starvation with a high rate of messaging?

Tested with Service Bus v2.6.7 and v2.7.5.


Thank you,

Alex


Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>