use of org.apache.camel.Route in project camel by apache.
the class RouteBuilderTest method testSplitter.
public void testSplitter() throws Exception {
List<Route> routes = buildSplitter();
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());
assertIsInstanceOf(Splitter.class, channel.getNextProcessor());
}
}
use of org.apache.camel.Route in project camel by apache.
the class ContextErrorHandlerTest method testOverloadingTheDefaultErrorHandler.
public void testOverloadingTheDefaultErrorHandler() throws Exception {
RouteBuilder builder = new RouteBuilder() {
public void configure() {
errorHandler(loggingErrorHandler("FOO.BAR"));
from("seda:a").to("seda:b");
}
};
List<Route> list = getRouteListWithCurrentContext(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);
assertIsInstanceOf(LoggingErrorHandler.class, channel.getErrorHandler());
SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
log.debug("Found sendProcessor: " + sendProcessor);
}
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultCamelContext method start.
@Override
public void start() throws Exception {
try (MDCHelper mdcHelper = new MDCHelper()) {
vetoStated.set(false);
startDate = new Date();
stopWatch.restart();
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is starting");
// Note: This is done on context start as we want to avoid doing it during object construction
// where we could be dealing with CDI proxied camel contexts which may never be started (CAMEL-9657)
// [TODO] Remove in 3.0
Container.Instance.manage(this);
doNotStartRoutesOnFirstStart = !firstStartDone && !isAutoStartup();
// then we may need to start the routes on the 2nd start call
if (firstStartDone && !isAutoStartup() && isStarted()) {
// invoke this logic to warm up the routes and if possible also start the routes
doStartOrResumeRoutes(routeServices, true, true, false, true);
}
// super will invoke doStart which will prepare internal services and start routes etc.
try {
firstStartDone = true;
super.start();
} catch (VetoCamelContextStartException e) {
// mark we veto against starting Camel
vetoStated.set(true);
if (e.isRethrowException()) {
throw e;
} else {
log.info("CamelContext ({}) vetoed to not start due {}", getName(), e.getMessage());
// swallow exception and change state of this camel context to stopped
stop();
return;
}
}
stopWatch.stop();
if (log.isInfoEnabled()) {
// count how many routes are actually started
int started = 0;
for (Route route : getRoutes()) {
if (getRouteStatus(route.getId()).isStarted()) {
started++;
}
}
log.info("Total " + getRoutes().size() + " routes, of which " + started + " are started.");
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") started in " + TimeUtils.printDuration(stopWatch.taken()));
}
EventHelper.notifyCamelContextStarted(this);
}
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultCamelContext method doStartOrResumeRouteConsumers.
private void doStartOrResumeRouteConsumers(Map<Integer, DefaultRouteStartupOrder> inputs, boolean resumeOnly, boolean addingRoute) throws Exception {
List<Endpoint> routeInputs = new ArrayList<Endpoint>();
for (Map.Entry<Integer, DefaultRouteStartupOrder> entry : inputs.entrySet()) {
Integer order = entry.getKey();
Route route = entry.getValue().getRoute();
RouteService routeService = entry.getValue().getRouteService();
// if we are starting camel, then skip routes which are configured to not be auto started
boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this) && this.isAutoStartup();
if (addingRoute && !autoStartup) {
log.info("Skipping starting of route " + routeService.getId() + " as its configured with autoStartup=false");
continue;
}
// start the service
for (Consumer consumer : routeService.getInputs().values()) {
Endpoint endpoint = consumer.getEndpoint();
// check multiple consumer violation, with the other routes to be started
if (!doCheckMultipleConsumerSupportClash(endpoint, routeInputs)) {
throw new FailedToStartRouteException(routeService.getId(), "Multiple consumers for the same endpoint is not allowed: " + endpoint);
}
// check for multiple consumer violations with existing routes which
// have already been started, or is currently starting
List<Endpoint> existingEndpoints = new ArrayList<Endpoint>();
for (Route existingRoute : getRoutes()) {
if (route.getId().equals(existingRoute.getId())) {
// skip ourselves
continue;
}
Endpoint existing = existingRoute.getEndpoint();
ServiceStatus status = getRouteStatus(existingRoute.getId());
if (status != null && (status.isStarted() || status.isStarting())) {
existingEndpoints.add(existing);
}
}
if (!doCheckMultipleConsumerSupportClash(endpoint, existingEndpoints)) {
throw new FailedToStartRouteException(routeService.getId(), "Multiple consumers for the same endpoint is not allowed: " + endpoint);
}
// start the consumer on the route
log.debug("Route: {} >>> {}", route.getId(), route);
if (resumeOnly) {
log.debug("Resuming consumer (order: {}) on route: {}", order, route.getId());
} else {
log.debug("Starting consumer (order: {}) on route: {}", order, route.getId());
}
if (resumeOnly && route.supportsSuspension()) {
// if we are resuming and the route can be resumed
ServiceHelper.resumeService(consumer);
log.info("Route: " + route.getId() + " resumed and consuming from: " + endpoint);
} else {
// when starting we should invoke the lifecycle strategies
for (LifecycleStrategy strategy : lifecycleStrategies) {
strategy.onServiceAdd(this, consumer, route);
}
startService(consumer);
log.info("Route: " + route.getId() + " started and consuming from: " + endpoint);
}
routeInputs.add(endpoint);
// add to the order which they was started, so we know how to stop them in reverse order
// but only add if we haven't already registered it before (we dont want to double add when restarting)
boolean found = false;
for (RouteStartupOrder other : routeStartupOrder) {
if (other.getRoute().getId().equals(route.getId())) {
found = true;
break;
}
}
if (!found) {
routeStartupOrder.add(entry.getValue());
}
}
if (resumeOnly) {
routeService.resume();
} else {
// and start the route service (no need to start children as they are already warmed up)
routeService.start(false);
}
}
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultCamelContext method doPrepareRouteToBeStarted.
private DefaultRouteStartupOrder doPrepareRouteToBeStarted(RouteService routeService) {
// add the inputs from this route service to the list to start afterwards
// should be ordered according to the startup number
Integer startupOrder = routeService.getRouteDefinition().getStartupOrder();
if (startupOrder == null) {
// auto assign a default startup order
startupOrder = defaultRouteStartupOrder++;
}
// create holder object that contains information about this route to be started
Route route = routeService.getRoutes().iterator().next();
return new DefaultRouteStartupOrder(startupOrder, route, routeService);
}
Aggregations