gpt4 book ai didi

azure - QueueClient 类替代品

转载 作者:行者123 更新时间:2023-12-02 06:55:52 26 4
gpt4 key购买 nike

Microsoft 已弃用名为 Microsoft.Azure.ServiceBus 的包,并将该包更新为 Azure.Messaging.ServiceBus,但在最近的更新中,他们删除了 QueueClient 类。那么这个 QueueClient 类的替代方案是什么?

public IQueueClient GetQueueClient(string queueName)
{
return new QueueClient(ConnectionString.Trim('"'), queueName);
}

最佳答案

在新版本中,您可以使用两个类 ServiceBusClientserviceBusSender 执行相同的操作。安装 Azure.Messaging.ServiceBus 后,您需要使用以下替代方案更新 QueueClient:

public ServiceBusSender PutintoQueueClient(string queueName)
{
var serviceBusClient = new ServiceBusClient(ConnectionString.Trim('"'));
return serviceBusClient.CreateSender(queueName)
}

现在您可以将消息发送到队列中

var serviceBusSender = PutintoQueueClient(queueName);
await serviceBusSender.SendMessageAsync(message).ConfigureAwait(false);

对于接收消息,它会像

public ServiceBusReceiver GetQueueClient(string queueName)
{
var serviceBusClient = new ServiceBusClient(ConnectionString.Trim('"'));
return serviceBusClient.CreateReceiver(queueName)
}

现在您可以将消息发送到队列中

var serviceBusSender = GetQueueClient(queueName);
ServiceBusReceivedMessage receivedMessage = await
serviceBusSender.ReceiveMessageAsync().ConfigureAwait(false);

引用: Guide for migrating to Azure.Messaging.ServiceBus from Microsoft.Azure.ServiceBus

关于azure - QueueClient 类替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71584886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com