use of org.apache.camel.Channel in project camel by apache.
the class ErrorHandlerTest method testLoggingErrorHandler.
public void testLoggingErrorHandler() throws Exception {
// START SNIPPET: e5
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").errorHandler(loggingErrorHandler("FOO.BAR")).filter(body().isInstanceOf(String.class)).to("seda:b");
}
};
// END SNIPPET: e5
List<Route> routes = getRouteList(builder);
assertEquals("Number routes created", 1, routes.size());
for (Route route : routes) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
assertIsInstanceOf(LoggingErrorHandler.class, channel.getErrorHandler());
assertIsInstanceOf(FilterProcessor.class, channel.getNextProcessor());
}
}
use of org.apache.camel.Channel in project camel by apache.
the class ErrorHandlerTest method testConfigureDeadLetterChannelWithCustomRedeliveryPolicy.
public void testConfigureDeadLetterChannelWithCustomRedeliveryPolicy() throws Exception {
// START SNIPPET: e4
RouteBuilder builder = new RouteBuilder() {
public void configure() {
// configures dead letter channel to use seda queue for errors and use at most 2 redelveries
// and exponential backoff
errorHandler(deadLetterChannel("seda:errors").maximumRedeliveries(2).useExponentialBackOff());
// here is our route
from("seda:a").to("seda:b");
}
};
// END SNIPPET: e4
List<Route> list = getRouteList(builder);
assertEquals("Number routes created" + list, 1, list.size());
for (Route route : list) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 2, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.Channel in project camel by apache.
the class ErrorHandlerTest method testOverloadingTheDefaultErrorHandler.
public void testOverloadingTheDefaultErrorHandler() throws Exception {
// START SNIPPET: e1
RouteBuilder builder = new RouteBuilder() {
public void configure() {
// use logging error handler
errorHandler(loggingErrorHandler("com.mycompany.foo"));
// here is our regular route
from("seda:a").to("seda:b");
}
};
// END SNIPPET: e1
List<Route> list = getRouteList(builder);
assertEquals("Number routes created" + list, 1, list.size());
for (Route route : list) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
assertIsInstanceOf(LoggingErrorHandler.class, channel.getErrorHandler());
Processor processor = unwrap(channel.getNextProcessor());
assertIsInstanceOf(SendProcessor.class, processor);
}
}
use of org.apache.camel.Channel in project camel by apache.
the class RouteBuilderTest method testSimpleRoute.
public void testSimpleRoute() throws Exception {
List<Route> routes = buildSimpleRoute();
assertEquals("Number routes created", 1, routes.size());
for (Route route : routes) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "direct://a", key.getEndpointUri());
EventDrivenConsumerRoute consumer = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumer.getProcessor());
SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
assertEquals("Endpoint URI", "direct://b", sendProcessor.getDestination().getEndpointUri());
}
}
use of org.apache.camel.Channel in project camel by apache.
the class RouteBuilderTest method testWireTap.
public void testWireTap() throws Exception {
List<Route> routes = buildWireTap();
log.debug("Created routes: " + routes);
assertEquals("Number routes created", 1, routes.size());
for (Route route : routes) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "direct://a", key.getEndpointUri());
EventDrivenConsumerRoute consumer = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumer.getProcessor());
MulticastProcessor multicastProcessor = assertIsInstanceOf(MulticastProcessor.class, channel.getNextProcessor());
List<Processor> endpoints = new ArrayList<Processor>(multicastProcessor.getProcessors());
assertEquals("Should have 2 endpoints", 2, endpoints.size());
assertSendToProcessor(unwrapChannel(endpoints.get(0)).getNextProcessor(), "direct://tap");
assertSendToProcessor(unwrapChannel(endpoints.get(1)).getNextProcessor(), "direct://b");
}
}
Aggregations