我可以将死信队列中的消息发送回死信队列吗?

发布于 2025-02-13 08:19:41 字数 1482 浏览 0 评论 0原文

我目前有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-02-20 08:19:41

当从一个死语的队列中收到一条消息时,它已经死了,不需要再次被删除。只要您在窥视模式下收到死去的消息,该消息就会保留在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文