java - apache Camel - 将消息警报添加到死信队列

标签 java apache-camel rabbitmq alerts

String queueA = "rabbitmq://host:5672/queue-a.exchange?queue=queue-a.exchange..etc

from(queueA)
  .routeId("idForQueueA")
  .onException(Exception.class)
    .maximumRedeliveries(0)
    // .processRef("sendEmailAlert")  * not sure this belongs here*
    .to(deadLetterQueueA)
    .useOriginalMessage()
  .end()
    .processRef("dataProcessing")
    .processRef("dataExporting")
  .end();

Explaining the code above:

消息取自queueA。当各种进程成功时,消息就会被消耗。如果失败,则将其添加到死信队列“deadLetterQueueA”。这一切都正常。

我的问题是

When messages arrive in the deadletter queue I want to add alerts so we know to do something about it... How could I to add an email alert when a message arrives in the dead letter queue. I dont want to lose the original message if the alert fails - nor do I want the alert to consume the message.

<小时/>

我的想法是..我需要在异常时拆分消息,以便将其发送到两个不同的队列?一个用于警报,然后发送电子邮件警报,然后自行消耗。然后是一个用于就在那里的死信队列的吗?但我不知道该怎么做?

最佳答案

您可以使用多播将消息拆分为多个端点(详细信息 here ):

.useOriginalMessage().multicast().to(deadLetterQueueA, "smtp://username@host:port?options")

这使用了描述的camel邮件组件端点here 。或者,您可以在 to 之后继续处理消息。所以类似:

.useOriginalMessage()
.to(deadLetterQueueA)
.transform().simple("Hi <name>, there has been an error on the object ${body.toString}")
.to("smtp://username@host:port?options")

如果您有多个收件人,您可以使用 recipients list

public class EmailListBean {
    @RecipientList
    public String[] emails() {
        return new String[] {"smtp://joe@host:port?options",
                "smtp://fred@host:port?options"};
    }
}

.useOriginalMessage()
.to(deadLetterQueueA)
.transform().simple("...")
.bean(EmailListBean.class)

在等待人们操作消息时,请小心使用 JMS 队列来存储消息。我不知道您收到什么样的消息流量。我假设如果您想为每次失败发送一封电子邮件,那么数量不会太多。但我通常会对这种事情保持警惕,并选择使用日志记录或数据库持久性来存储错误结果,并且仅使用 JMS 错误队列来通知其他进程或消费者错误或安排重试。

关于java - apache Camel - 将消息警报添加到死信队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479481/

相关文章:

ubuntu - 如何安装特定版本的 Erlang/OTP?

java - 在 Android 中调用 REST Web 服务并在字符串数据中获取 null

java - 对 JPanel 中的 JButton 进行排序

java - 设置JList的最大容量?

java - Apache camel netty 自定义编码器和解码器示例

database - 高性能交易引擎应该同步保存到数据库吗?

java - 使用方法引用和原始类型进行类型推断

java - Camel 路由 - 用 HTTP 负载替换消息正文中的 DTO

java - Camel CXF : How can I change the namespace of my incoming message?

python - AMQP:确认和预取