Rei*_*ica 7 activemq-classic apache-camel
我正在使用ActiveMQ中的系统,我真的不想丢失消息.我的问题是重试消息导致我的消费者阻止(而不是处理他们可以处理的消息).我想在几天内给失败的消息重试(例如,我的一个潜在目的地是我将通过SFTP访问的另一台服务器,可能会关闭),但我不希望消费者阻塞几天 - - 我希望它继续处理其他消息.
有没有办法让经纪人稍后重新发送消息?现在我正在考虑将消息从队列中取出并延迟启动,但我想知道是否有更简单的方法.我正在使用Apache Camel,所以使用它的解决方案也会很好.
骆驼绝对可以帮助...
一种方法是使用单独的队列并定期与主流分开重试消息(特别是在考虑性能时).此外,这提供了一个单独的队列,允许您分类这些错误消息(查看,清除,更改,手动重试等)...
像这样的事情......请参阅投票消费者了解更多细节
//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);
}
}
Run Code Online (Sandbox Code Playgroud)
如果你找到更好的解决方案,请告诉我......祝你好运
| 归档时间: |
|
| 查看次数: |
4819 次 |
| 最近记录: |