Search in sources :

Example 6 with FailedToStartRouteException

use of org.apache.camel.FailedToStartRouteException in project camel by apache.

the class MultipleConsumersSupportTest method testNotMultipleConsumersSupport.

public void testNotMultipleConsumersSupport() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            MyEndpoint my = new MyEndpoint();
            my.setCamelContext(context);
            my.setEndpointUriIfNotSpecified("my:endpoint");
            from(my).to("mock:a");
            from("direct:start").to("mock:result");
            from(my).to("mock:b");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToStartRouteException e) {
        assertTrue(e.getMessage().endsWith("Multiple consumers for the same endpoint is not allowed: my:endpoint"));
    }
}
Also used : FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException)

Example 7 with FailedToStartRouteException

use of org.apache.camel.FailedToStartRouteException in project camel by apache.

the class GracefulShutdownNoAutoStartOrderClashTest method testStartupOrderClash.

public void testStartupOrderClash() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").routeId("foo").startupOrder(5).to("mock:foo");
            from("direct:bar").routeId("bar").startupOrder(5).noAutoStartup().to("mock:bar");
        }
    });
    try {
        context.start();
        fail("Should have thrown an exception");
    } catch (FailedToStartRouteException e) {
        assertEquals("Failed to start route bar because of startupOrder clash. Route foo already has startupOrder 5 configured" + " which this route have as well. Please correct startupOrder to be unique among all your routes.", e.getMessage());
    }
}
Also used : FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException)

Example 8 with FailedToStartRouteException

use of org.apache.camel.FailedToStartRouteException in project camel by apache.

the class ManagedDuplicateIdTest method testDuplicateId.

public void testDuplicateId() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").routeId("foo").to("log:foo").split(body()).to("log:line").id("clash").end().to("mock:foo");
            from("direct:bar").routeId("bar").to("log:bar").split(body()).to("log:line").id("clash").end().to("mock:bar");
        }
    });
    try {
        context.start();
        fail("Should fail");
    } catch (FailedToStartRouteException e) {
        assertEquals("Failed to start route foo because of duplicate id detected: clash. Please correct ids to be unique among all your routes.", e.getMessage());
    }
}
Also used : FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException)

Example 9 with FailedToStartRouteException

use of org.apache.camel.FailedToStartRouteException in project camel by apache.

the class CxfMultipleConsumersSupportTest method testMultipleConsumersNotAllowed.

@Test
public void testMultipleConsumersNotAllowed() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from(SIMPLE_ENDPOINT_URI).to("mock:a");
            from("direct:start").to("mock:result");
            from(SIMPLE_ENDPOINT_URI).to("mock:b");
        }
    });
    try {
        context.start();
        fail("Should have thrown an exception");
    } catch (FailedToStartRouteException e) {
        assertTrue(e.getMessage().endsWith("Multiple consumers for the same endpoint is not allowed: cxf://http://localhost:" + port1 + "/CxfMultipleConsumersSupportTest/test?serviceClass=org.apache.camel.component.cxf.HelloService"));
    }
}
Also used : FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) Test(org.junit.Test)

Example 10 with FailedToStartRouteException

use of org.apache.camel.FailedToStartRouteException 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);
        }
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) Endpoint(org.apache.camel.Endpoint) PollingConsumer(org.apache.camel.PollingConsumer) Consumer(org.apache.camel.Consumer) LifecycleStrategy(org.apache.camel.spi.LifecycleStrategy) ServiceStatus(org.apache.camel.ServiceStatus) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ShutdownRoute(org.apache.camel.ShutdownRoute) Route(org.apache.camel.Route)

Aggregations

FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)12 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CamelContext (org.apache.camel.CamelContext)1 Consumer (org.apache.camel.Consumer)1 Endpoint (org.apache.camel.Endpoint)1 PollingConsumer (org.apache.camel.PollingConsumer)1 Route (org.apache.camel.Route)1 ServiceStatus (org.apache.camel.ServiceStatus)1 ShutdownRoute (org.apache.camel.ShutdownRoute)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1