onRedelivery处理器的所有修改都会在下次重新传递时重置。有没有办法让修改成为永久性的?
答案 0 :(得分:2)
每次重新发送时都会保留属性。您可以使用它们来存储您想要使用的信息。
代码:
public class OnRedeliveryTest extends CamelTestSupport {
public static final String PROP_TEST = "PROP_TEST";
@Produce(uri = "direct:start")
ProducerTemplate producerTemplate;
@Override
public RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class)
.onRedelivery(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
final String current = (String) exchange.getProperty(PROP_TEST);
exchange.setProperty(PROP_TEST, "property" + current);
System.out.println((String) exchange.getProperty(PROP_TEST));
}
})
.maximumRedeliveries(3).redeliveryDelay(0)
.handled(true)
.end();
from("direct:start")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
}
})
.throwException(new Exception("BOOM"))
.to("mock:end");
}
};
}
@Test
public void smokeTest() throws Exception {
producerTemplate.sendBody("1");
}
}
在输出中,您将拥有:
propertynull
propertypropertynull
propertypropertypropertynull