简体   繁体   English

Azure ServiceBus FaultTolerantAmqpObject`1' 异常

[英]Azure ServiceBus FaultTolerantAmqpObject`1' Exception

So I have upgraded to the Azure.Messaging.ServiceBus version 7.1.2 and my project to .NET 4.7.2 due to the need for TLS 1.2.因此,由于需要 TLS 1.2,我已升级到 Azure.Messaging.ServiceBus 版本 7.1.2,我的项目升级到 .NET 4.7.2。 I rewrote the listener (that is an on prem windows service) like so BusListener.cs :我像BusListener.cs一样重写了侦听器(即本地 windows 服务):

public static async Task ReceiveMessagesAsync()
    {   
        await using (ServiceBusClient client = new ServiceBusClient(ConfigurationManager.AppSettings[SERVICE_BUS_CONNECTION_STRING]))
        {
            ServiceBusProcessor processor = client.CreateProcessor(QUEUE_NAME, new ServiceBusProcessorOptions());

            processor.ProcessMessageAsync += MessageHandler;
            processor.ProcessErrorAsync += ErrorHandler;

            await processor.StartProcessingAsync();
        }
    }

That I call in my windows service ServiceMain.cs我在我的 windows 服务ServiceMain.cs中调用

Task.Run(() => BusListener.ReceiveMessagesAsync());

I get this error after about 10s of waiting and no message is ever received:等待大约 10 秒后,我收到此错误,但从未收到任何消息:

Cannot access a disposed object. Object name: 'FaultTolerantAmqpObject`1'. - at Microsoft.Azure.Amqp.Singleton`1.d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Azure.Messaging.ServiceBus.Amqp.AmqpConnectionScope.d__54.MoveNext() 

I looked around and it looked like from this other answer: Service Bus Disposed Object that I could be running into issues due to the method being static, even though this is what I'm following in the Microsoft "how to" guide here: https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues我环顾四周,它看起来像来自另一个答案: Service Bus Disposed Object ,由于方法是 static,我可能会遇到问题,即使这是我在此处的 Microsoft“如何”指南中所遵循的: Z5E0656C50BADE50A184 ://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues

I'm unsure if I'm writing the service bus part incorrectly or it's something else I'm missing?我不确定是我写错了服务总线部分还是我遗漏了其他东西? Is there a way to just ping or test connectivity to get a better idea of what is wrong?有没有办法只 ping 或测试连接以更好地了解问题所在?

When you create a ServiceBusClient , it owns the connection to the service used by any child objects that it creates.当您创建ServiceBusClient时,它拥有与它创建的任何子对象所使用的服务的连接。 By disposing the client in this line:通过在此行中处理客户端:

await using (ServiceBusClient client = new ServiceBusClient(ConfigurationManager.AppSettings[SERVICE_BUS_CONNECTION_STRING]))

You're closing the connection used by the processor that you've created.您正在关闭您创建的处理器使用的连接。 I'd recommend hoisting the client out of the method and allowing it to exist as a singleton for the lifetime of your application.我建议将客户端从该方法中提升出来,并允许它在应用程序的整个生命周期内以 singleton 的形式存在。 Generally speaking, that is the approach that we recommend for managing Azure clients.一般来说,这是我们推荐用于管理 Azure 客户端的方法。 (see: client lifetime ) (见: 客户生命周期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM