【问题标题】:Azure service bus delete queue message by id using the .net sdkAzure 服务总线使用 .net sdk 按 ID 删除队列消息
【发布时间】:2021-12-15 11:36:33
【问题描述】:

我有一个充满消息的 Azure 服务总线队列,我想根据它的 ID 删除一条消息。

REST API 通过 http 请求提供此解决方案:

DELETE  http{s}://{serviceNamespace}.servicebus.windows.net/{queuePath}/messages/{messageId}/{lockToken}

对于 .net 5 sdk,微软提供了一个解决方案,不使用消息的 id 而是使用 receivedMessage 对象

string connectionString = "<connection_string>";
string queueName = "<queue_name>";

// since ServiceBusClient implements IAsyncDisposable we create it with "await using"
await using var client = new ServiceBusClient(connectionString);

// create a receiver that we can use to receive and settle the message
ServiceBusReceiver receiver = client.CreateReceiver(queueName);

// the received message is a different type as it contains some service set properties
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();

// complete the message, thereby deleting it from the service
await receiver.CompleteMessageAsync(receivedMessage);

我想使用 .net sdk 按 id 删除消息。

【问题讨论】:

    标签: c# azure .net-5 azure-servicebus-queues


    【解决方案1】:

    不幸的是,没有办法通过简单的命令来实现它。其中一些已经讨论过here。您可以将自己的声音添加到主题中,并希望它能传达给正确的受众。

    【讨论】:

      猜你喜欢
      • 2017-01-16
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多