Search code examples
javaconfigurationapache-camelstartuperror-reporting

How to configure apache camel to see the reason of the shutdown?


Preconditions:

Camel 2.17

I had defined some routes, that routes contain entries like:

.to ("log:org.apache.camel?level=DEBUG")

My logback config contains:

<logger name="org.apache.camel" level="TRACE" />

Context definition begins with:

<camel:camelContext id="someContext" ... trace="true">

When I am starting Camel, then I see Camel is proceeding and finally without ANY error report just shutting down. This looks like:

2016-10-04 13:40:56,146 [localhost-startStop-1] TRACE org.apache.camel.model.ProcessorDefinitionHelper - There are 6 properties on: From[direct:process]
2016-10-04 13:40:58,042 [localhost-startStop-1] DEBUG org.apache.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=Root WebApplicationContext: startup date [Tue Oct 04 13:37:25 CEST 2016]; root of context hierarchy]
2016-10-04 13:40:58,066 [localhost-startStop-1] INFO  org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.3 (CamelContext: someContext) is shutting down

I have as well:

    onException( java.lang.Exception.class )
            .handled( false )
            .to( "log:GeneralError?level=ERROR" );

But this is more related to the exchange processing and not to startup.

Is there any generic way to check what is going on out there? For example:

  • Is there any class missing and class loader fails?
  • Or is any exception thrown?
  • Or some connection fails?

Complete route definition:

final RouteDefinition kafkaRouteDefinition = from( "kafka:{{kafka.broker.endpoints}}" +
        "?topic={{kafka.topic.name}}" +
        "&groupId=my_group" +
        "&autoOffsetReset=earliest" +
        "&consumersCount={{kafka.consumer.count}}" );

LOG.info( "Kafka route definition: " + kafkaRouteDefinition.toString() );

kafkaRouteDefinition
        .routeId( Constants.ROUTE_ID_PROCESS_KAFKA_MESSAGES )
        .to( "log:org.apache.camel?level=DEBUG" )
        .process( new RawMessageProcessor() ).id( RawMessageProcessor.class.getSimpleName() )
        .to( "log:org.apache.camel?level=DEBUG" )
        .unmarshal( inputMessageFormat ).id( "ConvertRawMessageToLogline" )
        .to( "log:org.apache.camel?level=DEBUG" )
        .process( new LoglineMessageProcessor() ).id( LoglineMessageProcessor.class.getSimpleName() )
        .to( "log:org.apache.camel?level=DEBUG" )
        .to( Constants.CAMEL_PROCESS_ENDPOINT )
        .to( "log:org.apache.camel?level=DEBUG" )
        .multicast().stopOnException()
        .to( "log:org.apache.camel?level=DEBUG" )
        .to( Constants.CAMEL_STORE_ENDPOINT
                , Constants.CAMEL_INDEX_ENDPOINT
        )
        .to( "log:org.apache.camel?level=DEBUG" )
        .end();

Solution

  • I had Similar issue [But I was using Spring]

    This happens when main method which loads camel Context exits before camel context is fully loaded

    Add below code in your test case & it should run

    org.apache.camel.spring.Main main = new Main();
    main.setApplicationContextUri("camel-context.xml");
    main.start();
    Thread.sleep(1000);
    

    More over you can also make autostart stop & start camel context later whenever needed

    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
        <route>
            <from uri="direct:start"/>
            <to uri="mock:result"/>
        </route>
    </camelContext>
    

    then in some java file

    ApplicationContext ac = ...
    SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
    
    // now start Camel manually
    camel.start();