gpt4 book ai didi

activemq - 在未来某个时间点重试消息 (ActiveMQ)

转载 作者:行者123 更新时间:2023-12-04 12:13:14 27 4
gpt4 key购买 nike

我正在 ActiveMQ 中的一个系统上工作,我真的不想丢失消息。我的问题是重试消息导致我的消费者阻塞(而不是处理他们可以处理的消息)。我想给失败的消息几天重试(例如,我的潜在目的地之一是我将通过 SFTP 访问的另一台服务器,该服务器可能已关闭),但我不希望消费者阻塞几天 - - 我希望它继续处理其他消息。

有没有办法告诉经纪人稍后重新发送消息?现在我正在考虑将消息从队列中取出并延迟放置,但我想知道是否有更简单的方法。我正在使用 Apache Camel,所以使用它的解决方案也很好。

最佳答案

Camel 绝对可以帮助解决这个问题......

一种方法是使用单独的队列并定期重试与主流分开的消息(尤其是在考虑性能时)。此外,这提供了一个单独的队列,允许您对这些错误消息进行分类(查看、清除、更改、手动重试等)...

类似这样的事情...见 polling consumer更多细节

//main route to process message from a queue (needs to be fast)
from("activemq:queue:mainQ").process(...);

//handle any errors by simply moving them to an error queue (for retry later)
onException(Exception.class)
.handled(true).to("activemq:queue:mainErrorQ");

//retry the error queue
from("timer://retryTimer?fixedRate=true&period=60000")
.bean(myBean, "retryErrors");

...

public void retryErrors() {
// loop to empty queue
while (true) {
// receive the message from the queue, wait at most 3 sec
Exchange msg = consumer.receive("activemq:queue.mainErrorQ", 3000);
if (msg == null) {
// no more messages in queue
break;
}

// send it to the starting queue
producer.send("activemq:queue.mainQ", msg);
}
}

如果您找到更好的解决方案,请告诉我...祝您好运

关于activemq - 在未来某个时间点重试消息 (ActiveMQ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6065062/

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