Paste
Pasted as Java by My Name ( 13 years ago )
package abc;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.util.StopWatch;
import org.junit.Test;
public class TestRedelivery extends CamelTestSupport {
private String finalMock = "mock:final";
@Test
public void testSend3Redelivery() throws Exception {
doTestSendRedelivery(3);
}
@Test
public void testSend20Redelivery() throws Exception {
doTestSendRedelivery(20);
}
public void doTestSendRedelivery(final int redelivery) throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// START SNIPPET: e1
// this error handler will try up till 20 redelivery attempts with 1 second between.
// however if we are stopping then do not allow any redeliver attempts.
errorHandler(deadLetterChannel(finalMock)
.allowRedeliveryWhileStopping(false)
.maximumRedeliveries(redelivery).redeliveryDelay(1000));
from("seda:foo").routeId("foo")
.to("mock:foo")
.throwException(new IllegalArgumentException("Forced"));
// END SNIPPET: e1
}
});
context.start();
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint(finalMock).expectedMessageCount(1);
template.sendBody("seda:foo", "Hello World");
assertMockEndpointsSatisfied();
// // should not take long to stop the route
// StopWatch watch = new StopWatch();
// context.stopRoute("foo");
// watch.stop();
//
// assertTrue("Should stop route faster, was " + watch.taken(), watch.taken() < 4000);
}
@Override
public boolean isUseRouteBuilder() {
return false;
}
}
Revise this Paste