我想根据标题过滤。如果某些属性不为null,则将数据从该属性发送到其他路由。
from(SAVE_RECEIVED_IDS)
.process(exchange -> {
//here i set true for filters because there is faulty data
exchange.getIn().setFault(true); //for PROCESS_FAULTY route
//if filter catches, it should get and send this but it does not come here
exchange.setProperty("faultyOnes","somearraylistOrData"); //for PROCESS_FAULTY route
exchange.setProperty("other fields irrelevant to faulty","somearraylistOrData");//for route GO_NEXT_ROUTE
})
//here i neeed to filter if value is ture
.filter(exchange -> exchange.getIn().isFault()) //it does not come here
.to(PROCESS_FAULTY)
.end() //end for filter
.to(GO_NEXT_ROUTE) //if there is no faulty come here. if there is faulty, after send come here.
.end() //end from()
还是我应该在何时使用选择?
.choice()
.when(header("foo").isEqualTo("bar"))
...
.when(header("foo").isEqualTo("chese"))
...
.otherwise()
....
.end(),
像这样吗?我使用isFaulty但标题还是更好的属性?但是我应该在哪里保存错误数据?感谢您的回答
答案 0 :(得分:0)
首先,将消息设置为错误时请小心。这主要是为不可恢复的错误而设计的,这些错误应触发错误恢复例程。
标题是更好还是属性?但是我应该在哪里保存错误数据?
看看Passing values between processors in apache camel,还要在相同的线程上通过Claus的以下回答。最值得注意的是,属性在整个骆驼中在消息处理的整个过程中被安全地存储。相反,标头是消息协议的一部分,并且可能不会在路由期间传播(引用克劳斯答案的形式)-简而言之,属性更适合,尤其是当您的消息也跨协议传递时(http,jms等) )。因此,请使用属性来存储错误数据。