This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6f7b1439a2c84aba3ca179b3d17e6bf14a976c58
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu Jun 6 12:43:47 2019 +0200

    CAMEL-12868: Detect if camel on spring-boot shutdown very quickly because 
there is no main controller or starter-web dependency to keep the JVM alive.
---
 .../camel-spring-boot/src/main/docs/spring-boot.adoc       |  3 ++-
 .../apache/camel/spring/boot/CamelAutoConfiguration.java   |  2 +-
 .../camel/spring/boot/CamelConfigurationProperties.java    | 14 ++++++++++++++
 .../apache/camel/spring/boot/SpringBootCamelContext.java   |  8 +++++---
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/components/camel-spring-boot/src/main/docs/spring-boot.adoc 
b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
index 8218937..1f4f2ce 100644
--- a/components/camel-spring-boot/src/main/docs/spring-boot.adoc
+++ b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
@@ -91,7 +91,7 @@ When using Spring Boot make sure to use the following Maven 
dependency to have s
 ----
 
 
-The component supports 140 options, which are listed below.
+The component supports 141 options, which are listed below.
 
 
 
@@ -206,6 +206,7 @@ The component supports 140 options, which are listed below.
 | *camel.springboot.use-breadcrumb* | Set whether breadcrumb is enabled. The 
default value is false. | false | Boolean
 | *camel.springboot.use-data-type* | Whether to enable using data type on 
Camel messages. Data type are automatic turned on if one ore more routes has 
been explicit configured with input and output types. Otherwise data type is 
default off. | false | Boolean
 | *camel.springboot.use-mdc-logging* | To turn on MDC logging | false | Boolean
+| *camel.springboot.warn-on-early-shutdown* | Whether to log a WARN if Camel 
on Spring Boot was immediately shutdown after starting which very likely is 
because there is no JVM thread to keep the application running. | true | Boolean
 | *camel.springboot.xml-rests* | Directory to scan for adding additional XML 
rests. You can turn this off by setting the value to false. Files can be loaded 
from either classpath or file by prefixing with classpath: or file: Wildcards 
is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml Multiple directories can be specified 
and separated by comma, such as: 
file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml | 
classpath:camel-rest/*.x [...]
 | *camel.springboot.xml-routes* | Directory to scan for adding additional XML 
routes. You can turn this off by setting the value to false. Files can be 
loaded from either classpath or file by prefixing with classpath: or file: 
Wildcards is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml Multiple directories can be specified 
and separated by comma, such as: 
file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml | 
classpath:camel/*.xml  [...]
 | *camel.springboot.xml-routes-reload-directory* | To watch the directory for 
file changes which triggers a live reload of the Camel routes on-the-fly. For 
example configure this to point to the source code where the Camel XML files 
are located such as: src/main/resources/camel/ |  | String
diff --git 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 070bc68..a3c4c85 100644
--- 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -113,7 +113,7 @@ public class CamelAutoConfiguration {
     @ConditionalOnMissingBean(CamelContext.class)
     CamelContext camelContext(ApplicationContext applicationContext,
                               CamelConfigurationProperties config) throws 
Exception {
-        CamelContext camelContext = new 
SpringBootCamelContext(applicationContext);
+        CamelContext camelContext = new 
SpringBootCamelContext(applicationContext, config.isWarnOnEarlyShutdown());
         return doConfigureCamelContext(applicationContext, camelContext, 
config);
     }
 
diff --git 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
index 1e87c32f..d50b189 100644
--- 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
+++ 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
@@ -35,6 +35,12 @@ public class CamelConfigurationProperties {
     private int shutdownTimeout = 300;
 
     /**
+     * Whether to log a WARN if Camel on Spring Boot was immediately shutdown 
after starting which
+     * very likely is because there is no JVM thread to keep the application 
running.
+     */
+    private boolean warnOnEarlyShutdown = true;
+
+    /**
      * Whether Camel should try to suppress logging during shutdown and 
timeout was triggered,
      * meaning forced shutdown is happening. And during forced shutdown we 
want to avoid logging
      * errors/warnings et all in the logs as a side-effect of the forced 
timeout.
@@ -508,6 +514,14 @@ public class CamelConfigurationProperties {
         this.shutdownTimeout = shutdownTimeout;
     }
 
+    public boolean isWarnOnEarlyShutdown() {
+        return warnOnEarlyShutdown;
+    }
+
+    public void setWarnOnEarlyShutdown(boolean warnOnEarlyShutdown) {
+        this.warnOnEarlyShutdown = warnOnEarlyShutdown;
+    }
+
     public boolean isShutdownSuppressLoggingOnTimeout() {
         return shutdownSuppressLoggingOnTimeout;
     }
diff --git 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootCamelContext.java
 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootCamelContext.java
index bbcd395..1b32495 100644
--- 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootCamelContext.java
+++ 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootCamelContext.java
@@ -26,9 +26,11 @@ import org.springframework.context.ApplicationContext;
 public class SpringBootCamelContext extends SpringCamelContext {
 
     private final StopWatch stopWatch = new StopWatch();
+    private final boolean warnOnEarlyShutdown;
 
-    public SpringBootCamelContext(ApplicationContext applicationContext) {
+    public SpringBootCamelContext(ApplicationContext applicationContext, 
boolean warnOnEarlyShutdown) {
         super(applicationContext);
+        this.warnOnEarlyShutdown = warnOnEarlyShutdown;
     }
 
     @Override
@@ -42,10 +44,10 @@ public class SpringBootCamelContext extends 
SpringCamelContext {
         // if we are stopping very quickly then its likely because the user 
may not have either spring-boot-web
         // or enabled Camel's main controller, so lets log a WARN about this.
         long taken = stopWatch.taken();
-        if (taken < 1200) { // give it a bit of slack
+        if (warnOnEarlyShutdown && taken < 1200) { // give it a bit of slack
             String cp = System.getProperty("java.class.path");
-            boolean starterWeb = cp != null && 
cp.contains("spring-boot-starter-web");
             boolean junit = cp != null && cp.contains("junit-");
+            boolean starterWeb = cp != null && 
cp.contains("spring-boot-starter-web");
             if (!junit && !starterWeb) {
                 log.warn("CamelContext has only been running for less than a 
second. If you intend to run Camel for a longer time "
                         + "then you can set the property 
camel.springboot.main-run-controller=true in application.properties"

Reply via email to