gpt4 book ai didi

java - Camel AWS-SQS : Set visibilityTimeout dynamically

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:45 25 4
gpt4 key购买 nike

我有一条 Camel 路线,大致定义如下:

from("aws-sqs://my-queue")
.process(myProcessor)
.to(myEndpoint);

但是,myProcessor 依赖于上游服务,该服务有时会变得不可用或返回“待处理”响应,因此处理器会引发异常,并且交换会留在队列中。 Camel 然后轮询并连续失败,直到消息被 DLQed。

我想做的是动态配置visibilityTimeout以实现指数退避,直到上游服务再次可用。因此,我将在我的路线及其内部注册一个异常处理程序,而不是 from("aws-sqs://my-queue?visibilityTimeout=30"),执行以下操作:

sqsClient.setVisibilityTimeout(Math.pow(2 * visibilityTimeout));

这可能吗?另外,是否可以为特定消息 ID 配置可见性超时(例如,这样它就不会影响其他消息的可见性超时)?

最佳答案

是的,可以更改正在处理的消息的 VisibilityTimeout。

来自AWS docs :

When you receive a message for a queue and begin to process it, the visibility timeout for the queue may be insufficient (for example, you might need to process and delete a message). You can shorten or extend a message's visibility by specifying a new timeout value using the ChangeMessageVisibility action.

For example, if the timeout for a queue is 60 seconds, 15 seconds have elapsed, and you send a ChangeMessageVisibility call with VisibilityTimeout set to 10 seconds, the total timeout value will be the elapsed time (15 seconds) plus the new timeout value (10 seconds), a total of 25 seconds. Sending a call after 25 seconds will result in an error.

Note

The new timeout period will take effect from the time you call the ChangeMessageVisibility action. In addition, the new timeout period will apply only to the particular receipt of the message. The ChangeMessageVisibility action does not affect the timeout of later receipts of the message or later queues.

关于java - Camel AWS-SQS : Set visibilityTimeout dynamically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40730493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com