我可以将死信队列中的消息发送回死信队列吗?
我目前有一个Azure功能,该功能从服务总线的DLQ处理消息。 我要实现的是尝试手动处理此操作,但是如果它不能成功将消息转发回DLQ并基于自定义逻辑来做到这一点,请说3次。 我正在接收serviceBusreceivedMessage对象,但是当我尝试通过使用ServiceBusMessAgeActions创建新的ServiceBusClient和接收器将其发送回DLQ时,我要么获得a
lock suped lock used suped lock suped over suped lock suped lock used noval novali valli valq novalid codevers copection ofer。锁已过期,或者该消息已从队列中删除,或者已由其他接收器实例收到。 (Messagelocklost)
。或无效感受。
是我想完成的工作还是我应该创建一个新的ServiceBusMessage并将消息重新提交给原始队列而不是直接执行DLQ?
这是重新提交所有内容的代码:
try
{
var serviceBusClient = new ServiceBusClient(Environment.GetEnvironmentVariable("ConnectionString"), new ServiceBusClientOptions()
{
});
var receiver = serviceBusClient.CreateReceiver(Environment.GetEnvironmentVariable("QueueName"), new ServiceBusReceiverOptions()
{
SubQueue = SubQueue.DeadLetter,
});
await receiver.DeadLetterMessageAsync(dlqItem, deadLetterReason: Constants.DLQReason);
//Above method not working. Bellow neither
//await messageActions.DeadLetterMessageAsync(dlqItem, deadLetterReason: Constants.DLQReason);
} catch (Exception ex)
{
log.LogError($"MessageId: {dlqItem.MessageId}. There was an error sending the message to DLQ: {ex.Message}");
throw;
}
谢谢!
I currently have an azure function that processes message from a DLQ of a service bus.
What I want to implement is to try to process this manually, but if it doesn't succeed to forward the message back to the DLQ and based on a custom logic to do that for let's say 3 times.
I am receiving the ServiceBusReceivedMessage object but when I try to send it back to DLQ either by creating a new ServiceBusClient and receiver either by using the ServiceBusMessageActions I either get a The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance. (MessageLockLost)
. or an InvalidException.
Is what I want to do achievable or I should create a new ServiceBusMessage and resubmit the message to the original queue instead of doing it directly to the DLQ?
This is the code that resubmits everything:
try
{
var serviceBusClient = new ServiceBusClient(Environment.GetEnvironmentVariable("ConnectionString"), new ServiceBusClientOptions()
{
});
var receiver = serviceBusClient.CreateReceiver(Environment.GetEnvironmentVariable("QueueName"), new ServiceBusReceiverOptions()
{
SubQueue = SubQueue.DeadLetter,
});
await receiver.DeadLetterMessageAsync(dlqItem, deadLetterReason: Constants.DLQReason);
//Above method not working. Bellow neither
//await messageActions.DeadLetterMessageAsync(dlqItem, deadLetterReason: Constants.DLQReason);
} catch (Exception ex)
{
log.LogError(quot;MessageId: {dlqItem.MessageId}. There was an error sending the message to DLQ: {ex.Message}");
throw;
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当从一个死语的队列中收到一条消息时,它已经死了,不需要再次被删除。只要您在窥视模式下收到死去的消息,该消息就会保留在DLQ中。如果您在接收和删除模式下收到一条消息,它将从经纪人中消失,并且不能被DLQ-ED。
您需要小心不要在这里ddos。如果将功能配置为从DLQ接收而无法处理消息,则除非完成,否则它将继续收到该消息。
When receiving a message from a dead-letter queue, it's already dead-lettered and doesn't need to be dead-lettered again. As long as you receive the dead-lettered message in a peek-lock mode, the message will remain in the DLQ. If you receive a message in a receive-and-delete mode, it will be gone from the broker and cannot be DLQ-ed.
You need to be careful not to DDOS yourself here. If a function is configured to receive from a DLQ and cannot handle a message, it will continue receiving that message unless it's completed.