c# - Azure 服务总线使用 .net sdk 按 ID 删除队列消息
问题描述
我有一个充满消息的 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 删除一条消息。
解决方案
不幸的是,没有办法用一个简单的命令来实现它。这里讨论了其中的一些内容。您可以将您的声音添加到线程中,并希望它能够传达给正确的受众。
推荐阅读
- drone - 如何在drone.io 中为构建配置硬内存限制
- c - 函数中的 for 循环会产生随机数
- dynamics-crm - 过滤仪表板中的数据?
- python - 完全约束最小二乘的向量化函数
- java - 如何添加其他目标作为自定义 Maven 插件的依赖项?
- c++ - 解析 RapidJSON 字符串在括号中返回 NULL
- grpc - 为什么浏览器不支持 gRPC?
- scala - Spark Structured Streaming + Kafka:当 Kafka 消息与 JSON 模式不匹配时,停止查询崩溃
- java - y/n 输入验证,包括无输入 Enter 键
- java - twitter 中的 twitter4j 状态有图像但没有媒体实体