quangpn88
quangpn88

Reputation: 615

Apache Camel: all modifications of onRedelivery's processor is reset in next redelivery

All modifications of onRedelivery's processor is reset in next redelivery. Is there any way to make the modifications becomes permanent?

Upvotes: 1

Views: 590

Answers (1)

Jonathan Schoreels
Jonathan Schoreels

Reputation: 1720

Properties are kept at each redelivery. You can use them to store information that you want to use after.

Code :

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");
}

}

In output, you will have :

propertynull

propertypropertynull

propertypropertypropertynull

Upvotes: 2

Related Questions