简体   繁体   English

无法连接到Azure服务总线队列

[英]Failure to connect to Azure Service bus queue

Am trying to listen to an azure service bus queue but am getting an exception when initializing the connection to to the queue. 我正在尝试监听azure服务总线队列,但是在初始化与该队列的连接时遇到异常。 I have tried to search for a way out but with less success. 我试图寻找出路,但成功率较低。 Note that am using .NETCore 2.1. 请注意,正在使用.NETCore 2.1。 This is how am initializing the connection it: 这是初始化连接的方式:

// Initialize the connection to Service Bus Queue
_queueClient = QueueClient.CreateFromConnectionString(_interswitchQueueConnectionString, _interswitchQueueName, ReceiveMode.ReceiveAndDelete);

And this the exception am getting: 而这个异常越来越:

System.TypeInitializationException: The type initializer for 'Microsoft.ServiceBus.Messaging.Constants' threw an exception. System.TypeInitializationException:'Microsoft.ServiceBus.Messaging.Constants'的类型初始值设定项引发了异常。 ---> System.TypeLoadException: Could not load type 'System.UriTemplate' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. ---> System.TypeLoadException:无法从程序集'System.ServiceModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.UriTemplate'。 at Microsoft.ServiceBus.Messaging.Constants..cctor() --- End of inner exception stack trace --- at Microsoft.ServiceBus.ServiceBusConnectionStringBuilder..ctor() at Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(String connectionString, String path, ReceiveMode mode) 在Microsoft.ServiceBus.Messaging.Constants..cctor()-内部异常堆栈跟踪的结尾-在Microsoft.ServiceBus.ServiceBusConnectionStringBuilder..ctor()在Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(String connectionString,字符串路径,ReceiveMode模式)

The same initialization works fine when using .net framework. 使用.net框架时,相同的初始化工作正常。 How can I do it in .NetCore ? 如何在.NetCore中做到这一点? Please Help Thanks in advance 请先帮助谢谢

With .NET Core you should use the new .NET Standard Azure Service Bus client, Microsoft.Azure.ServiceBus . 通过.NET Core,您应该使用新的.NET Standard Azure Service Bus客户端Microsoft.Azure.ServiceBus The old client WindowsAzure.ServiceBus is a legacy client, only works with Full Framework, and is not recommended moving forward. 旧客户端WindowsAzure.ServiceBus是旧客户端,仅适用于完整框架, 建议继续使用。

The new client does not have a concept of factory. 新客户没有工厂的概念。 You're in charge of creating entity clients ( QueueClient , SubscriptionClient , and TopicClient ) and managing connections. 您负责创建实体客户端( QueueClientSubscriptionClientTopicClient )并管理连接。

On Dotnet Core 2.1 you can try this. 在Dotnet Core 2.1上,您可以尝试此操作。

var queueClient = new QueueClient(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);

Hope this helps. 希望这可以帮助。

You can also do using MessagingFactory 您也可以使用MessagingFactory

MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);

            queueClient = await factory.CreateMessageReceiverAsync(_entityPath, ReceiveMode.ReceiveAndDelete);

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

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