javaspring-bootapache-camelopenshift

Spring boot app with Apache Camel shuts down right after it has started


My application is written in Java using Spring Boot and Apache Camel. When run in my Windows development environment it starts and runs nicely. But when run inside my Open Shift test environment, the app starts as normal and then shuts down, as if I pressed CTRL+C.

Some suggestions online is to add or remove a certain dependencies. This is already done in my Maven pom.xml:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
  </exclusions>
</dependency>

The following is the most relevant part of my log:

2019-04-23T12:34:37.009+0000 INFO  [main] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Route: myservice-localhost started and consuming from: direct://myservice-localhost
2019-04-23T12:34:37.011+0000 INFO  [main] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Route: route1 started and consuming from: direct://myservice-myroute
2019-04-23T12:34:37.016+0000 INFO  [main] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Route: myservice started and consuming from: servlet:/myservice/%7BcompanyID%7D
2019-04-23T12:34:37.021+0000 INFO  [main] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Total 9 routes, of which 9 are started
2019-04-23T12:34:37.041+0000 INFO  [main] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Apache Camel 2.21.0 (CamelContext: OBGW-Camel) started in 4.165 seconds
2019-04-23T12:34:37.289+0000 INFO  [main] [org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer] [] [] [] [] [] [] [] [] [] [] Undertow started on port(s) 8090 (http)
2019-04-23T12:34:37.294+0000 INFO  [main] [org.springframework.context.support.DefaultLifecycleProcessor] [] [] [] [] [] [] [] [] [] [] Starting beans in phase 0
2019-04-23T12:34:37.415+0000 INFO  [main] [org.apache.camel.component.servlet.CamelHttpTransportServlet] [] [] [] [] [] [] [] [] [] [] Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
2019-04-23T12:34:37.416+0000 INFO  [main] [org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer] [] [] [] [] [] [] [] [] [] [] Undertow started on port(s) 8080 (http)
2019-04-23T12:34:37.422+0000 INFO  [main] [com.mycompany.Application] [] [] [] [] [] [] [] [] [] [] Started Application in 21.385 seconds (JVM running for 22.759)
2019-04-23T12:34:49.811+0000 INFO  [Thread-2] [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] [] [] [] [] [] [] [] [] [] [] Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5387f9e0: startup date [Tue Apr 23 12:34:17 UTC 2019]; root of context hierarchy
2019-04-23T12:34:49.812+0000 INFO  [Thread-2] [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] [] [] [] [] [] [] [] [] [] [] Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@630390b9: startup date [Tue Apr 23 12:34:31 UTC 2019]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5387f9e0
2019-04-23T12:34:49.846+0000 INFO  [Thread-2] [org.springframework.context.support.DefaultLifecycleProcessor] [] [] [] [] [] [] [] [] [] [] Stopping beans in phase 2147483647
2019-04-23T12:34:49.846+0000 INFO  [Thread-2] [org.apache.camel.spring.SpringCamelContext] [] [] [] [] [] [] [] [] [] [] Apache Camel 2.21.0 (CamelContext: OBGW-Camel) is shutting down
2019-04-23T12:34:49.852+0000 INFO  [Thread-2] [org.apache.camel.impl.DefaultShutdownStrategy] [] [] [] [] [] [] [] [] [] [] Starting to graceful shutdown 9 routes (timeout 300 seconds)
2019-04-23T12:34:49.872+0000 INFO  [Camel (OBGW-Camel) thread #1 - ShutdownTask] [org.apache.camel.impl.DefaultShutdownStrategy] [] [] [] [] [] [] [] [] [] [] Route: myservice shutdown complete, was consuming from: servlet:/myservice/%7BcompanyID%7D
2019-04-23T12:34:49.872+0000 INFO  [Camel (OBGW-Camel) thread #1 - ShutdownTask] [org.apache.camel.impl.DefaultShutdownStrategy] [] [] [] [] [] [] [] [] [] [] Route: route1 shutdown complete, was consuming from: direct://myservice-myroute

Everything is exactly the same in the Open Shift environment until the statement Started Application, when it starts shutting down.


Solution

  • Normally the dependency to spring-boot-starter-web is enough to keep the process up and running.

    However, you are using Undertow as Camel's HTTP server instead of Spring Boot's standard Tomcat. Therefore you probably need to put

    camel.springboot.main-run-controller=true
    

    into your application properties (as already suggested by a comment). This is also mentioned on the Camel SpringBoot page of the docs.