Azure / azure-service-bus

☁️ Azure Service Bus service issue tracking and samples
https://azure.microsoft.com/services/service-bus
MIT License
586 stars 779 forks source link

OnMessage/OnMessageAsync very slow invocation with AMQP in WindowsAzure.ServiceBus client #226

Closed jr01 closed 2 years ago

jr01 commented 6 years ago

Consider the following simple code:

namespace ConsoleApp
{
    using System;
    using System.Diagnostics;
    using Microsoft.ServiceBus.Messaging;

    class Program
    {
        static void Main(string[] args)
        {
            var messagingFactory = MessagingFactory.CreateFromConnectionString(
                "Endpoint=sb://xxxxxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;" +
                "SharedAccessKey=xxxxxx=;TransportType=Amqp");

            var queueClient = messagingFactory.CreateQueueClient("myqueue");

            var sw = new Stopwatch();
            sw.Start();

            queueClient.OnMessage(
                b =>
                {
                });

            Console.WriteLine("Took: " + sw.Elapsed);
            Console.ReadLine();
        }
    }
}

Actual Behavior

  1. When using TransportType=Amqp the OnMessage invocation often takes more than 10 seconds, while without Amqp it takes around 0.5 second. Sometimes with Amqp it is fast though. With the new Microsoft.Azure.ServiceBus client it is always fast. So it looks like an issue with the older client. When there are many queues to listen to and thus multiple queue clients / OnMessage invocations (we are using webjobs framework...) it takes a long time to just startup the application.

Expected Behavior

  1. Invoking OnMessage/OnMessageAsync should be fast.

Versions

axisc commented 6 years ago

Thanks for submitting the feedback. We're not actively making changes to the older client version particularly for AMQP.

Is there any particular reason for you to use the previous client? We highly recommend switching to the new client if you are using AMQP.

jr01 commented 6 years ago

We use the Azure Webjobs SDK and that has the old library in its latest v2.x release. Webjobs SDK v3 has the new client,, but it's unclear when that will be released.

sxd63870 commented 6 years ago
 public MessageSession messageSession = null;

OnMessageOptions onMessageOptions = new OnMessageOptions(); onMessageOptions.AutoComplete = true; messageSession = ncwSubscriptionClient.AcceptMessageSession(Guid.NewGuid().ToString()); messageSession.OnMessage(ProcessSubscriptionResponse, onMessageOptions);

I am facing issue with above OnMessage(). All the times it is so quick - sometimes it takes 60+ seconds to exec the line OnMessage() . This is a big issue in our case. And my solution is a window service i am using windowsAzure.Servicebus