Azure服务总线死信队列消息无法在死信中停留更长时间 [英] Azure service bus deadletter queue message unable to stay in deadletter for longer time

查看:72
本文介绍了Azure服务总线死信队列消息无法在死信中停留更长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Azure Main函数应用程序,该应用程序处理来自服务总线的即将到来的消息.

I have Azure Main function app which processes coming messages from service bus.

如果由于API故障导致发生异常,则我将消息推送到Dead Letter Queue.

If exception occurs because of API is down then I push message into Dead Letter Queue.

我有另一个天蓝色的Dead功能应用程序,可以连续读取DLQ并将消息推回主队列.

I have another azure Dead function app which continuously read DLQ and push back message into main queue.

然后,主要功能应用检查api是否关闭,然后再次向DLQ推送消息,直到API启动并且主要功能应用成功处理消息为止.

And main Function app check if api is down then push message again to DLQ this should go on until API is up and Main function app process message successfully.

但是问题是一段时间后消息会自动清除.

But issue is after some time message purge automatically.

我检查默认邮件生存时间"为2小时30分钟,但邮件无法停留那么长时间.当我将消息推回Main时,我认为是在Dead Function应用中.主队列中的邮件可能被标识为重复但不确定.

I check Default Message Time To Live is 2 hours 30 minutes but message unable to stay there so long. I think in Dead Function app when I push message back to Main. in main queue message may be identified as duplicate but not sure.

在给定的默认消息生存时间下,我应如何将消息维持在DLQ中?

What should I do to sustain message into DLQ for given Default Message Time To Live?

死信功能应用程序代码,可将消息推回主队列-

Dead letter function app code which push back message to main queue -

 MessageSender sender = new MessageSender(Environment.GetEnvironmentVariable("ConnectionStringSettingName"), UtilityHelper.GetAndValidateAppSetting("TopicName"), RetryPolicy.Default);

            Message deadLetterMessage = new Message(message.Body);

            foreach (KeyValuePair<string, object> userProperty in message.UserProperties)
            {
                deadLetterMessage.UserProperties.Add(userProperty.Key, userProperty.Value);
            }

            //Send the message to the Active Queue
            await sender.SendAsync(deadLetterMessage);

主要功能应用代码-

[FunctionName("ProcessMessage")]
        public static async System.Threading.Tasks.Task RunAsync([ServiceBusTrigger("mytopic", "mysub", Connection = "ConnectionStringSettingName")]Message mySbMsg, string lockToken, MessageReceiver messageReceiver, ILogger log)
        {
            
            try
            { 
                  log.LogInformation("Process message...");
            }
            catch (Exception ex)
            {
                log.LogInformation($"Send message to dead-letter: {ex}");
                await messageReceiver.DeadLetterAsync(lockToken);
            }
        }

我的逻辑是:在API启用之前,我正在将消息发送到DLQ和DLQ功能应用程序,将其推回主队列,以免丢失消息.

My logic is: until API is up I'm sending message into DLQ and DLQ function app pushing it back to main queue so that I don't lost message.

找出根本原因:

Microsoft.Azure.ServiceBus.ServiceBusCommunicationException:一个无法执行套接字上的操作,因为缺少系统足够的缓冲区空间或因为队列已满ErrorCode:NoBufferSpaceAvailable --->System.Net.Sockets.SocketException:一个无法执行套接字上的操作,因为缺少系统足够的缓冲区空间或队列已满Microsoft.Azure.ServiceBus.ServiceBusConnection.CreateConnectionAsync(TimeSpan超时)

Microsoft.Azure.ServiceBus.ServiceBusCommunicationException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full ErrorCode: NoBufferSpaceAvailable ---> System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was fullat Microsoft.Azure.ServiceBus.ServiceBusConnection.CreateConnectionAsync(TimeSpan timeout)

如何解决这个问题?

推荐答案

默认生存时间设置不适用于死信.根据文档:

The Default Message Time To Live setting does not apply to dead-letter. As per documentation:

没有自动清除DLQ.消息将保留在DLQ中,直到您从DLQ中显式检索它们并在死信消息上调用Complete()为止.

There's no automatic cleanup of the DLQ. Messages remain in the DLQ until you explicitly retrieve them from the DLQ and call Complete() on the dead-letter message.

上面将死信返回到原始队列的函数代码将完成每条死信,而这些消息将从死信队列中消失.

The code above for the function that returns dead-lettered messages to the original queue will complete each dead-lettered message and those will be gone from the dead-letter queue.

这篇关于Azure服务总线死信队列消息无法在死信中停留更长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆