azure - QueueClient 类替代品

标签 azure azureservicebus azure-servicebus-queues

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/

相关文章:

spring - Jedis连接异常: Could not get a resource from the pool

Azure服务总线: Can't add rules to a subscription under Topics with partitioning enabled?

azure - 在 Azure 服务总线订阅上配置共享访问签名

azure - 使用 Azure 逻辑应用从 Salesforce 获取记录

python - azure-keyvault-secrets python 包中的 SecretClient 类引发意外错误

azure - UserContext类的AccountId、AuthenticatedUserId和Id有什么区别?

azure - 确定 Azure 服务总线队列上有多少消息

azure - 事件延迟N天的解决方案

java - 如何使用 Java SDK 从远程 Azure 应用程序配置检索服务总线队列的队列名称?

azure - 未从 azure 服务总线订阅获取所有代理消息