CAMEL-10619: Add spring boot configuration for configuring shutdown options
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dcd6ab1b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dcd6ab1b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dcd6ab1b Branch: refs/heads/camel-2.18.x Commit: dcd6ab1bf4140cabde687250c78beb7251ec9b65 Parents: 7b4b77a Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Dec 19 19:44:14 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Dec 19 19:50:06 2016 +0100 ---------------------------------------------------------------------- .../spring/boot/CamelAutoConfiguration.java | 8 ++ .../boot/CamelConfigurationProperties.java | 78 ++++++++++++++++++++ .../src/main/resources/application.yml | 1 + 3 files changed, 87 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/dcd6ab1b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java ---------------------------------------------------------------------- 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 d4335a4..579a384 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 @@ -102,6 +102,14 @@ public class CamelAutoConfiguration { ((SpringCamelContext) camelContext).setName(config.getName()); } + if (config.getShutdownTimeout() > 0) { + camelContext.getShutdownStrategy().setTimeout(config.getShutdownTimeout()); + } + camelContext.getShutdownStrategy().setSuppressLoggingOnTimeout(config.isShutdownSuppressLoggingOnTimeout()); + camelContext.getShutdownStrategy().setShutdownNowOnTimeout(config.isShutdownNowOnTimeout()); + camelContext.getShutdownStrategy().setShutdownRoutesInReverseOrder(config.isShutdownRoutesInReverseOrder()); + camelContext.getShutdownStrategy().setLogInflightExchangesOnTimeout(config.isShutdownLogInflightExchangesOnTimeout()); + if (config.getLogDebugMaxChars() > 0) { camelContext.getProperties().put(Exchange.LOG_DEBUG_BODY_MAX_CHARS, "" + config.getLogDebugMaxChars()); } http://git-wip-us.apache.org/repos/asf/camel/blob/dcd6ab1b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java ---------------------------------------------------------------------- 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 100aa18..146aefc 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 @@ -16,6 +16,7 @@ */ package org.apache.camel.spring.boot; +import org.apache.camel.CamelContext; import org.apache.camel.ManagementStatisticsLevel; import org.apache.camel.api.management.ManagedAttribute; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -31,6 +32,43 @@ public class CamelConfigurationProperties { private String name; /** + * Timeout in seconds to graceful shutdown Camel. + */ + private int shutdownTimeout = 300; + + /** + * 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. + * <p/> + * By default this is <tt>false</tt> + * <p/> + * Notice the suppress is a <i>best effort</i> as there may still be some logs coming + * from 3rd party libraries and whatnot, which Camel cannot control. + */ + private boolean shutdownSuppressLoggingOnTimeout; + + /** + * Sets whether to force shutdown of all consumers when a timeout occurred and thus + * not all consumers was shutdown within that period. + * <p/> + * You should have good reasons to set this option to <tt>false</tt> as it means that the routes + * keep running and is halted abruptly when CamelContext has been shutdown. + */ + private boolean shutdownNowOnTimeout = true; + + /** + * Sets whether routes should be shutdown in reverse or the same order as they where started. + */ + private boolean shutdownRoutesInReverseOrder = true; + + /** + * Sets whether to log information about the inflight Exchanges which are still running + * during a shutdown which didn't complete without the given timeout. + */ + private boolean shutdownLogInflightExchangesOnTimeout = true; + + /** * Enable JMX in your Camel application. */ private boolean jmxEnabled = true; @@ -326,6 +364,46 @@ public class CamelConfigurationProperties { this.name = name; } + public int getShutdownTimeout() { + return shutdownTimeout; + } + + public void setShutdownTimeout(int shutdownTimeout) { + this.shutdownTimeout = shutdownTimeout; + } + + public boolean isShutdownSuppressLoggingOnTimeout() { + return shutdownSuppressLoggingOnTimeout; + } + + public void setShutdownSuppressLoggingOnTimeout(boolean shutdownSuppressLoggingOnTimeout) { + this.shutdownSuppressLoggingOnTimeout = shutdownSuppressLoggingOnTimeout; + } + + public boolean isShutdownNowOnTimeout() { + return shutdownNowOnTimeout; + } + + public void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout) { + this.shutdownNowOnTimeout = shutdownNowOnTimeout; + } + + public boolean isShutdownRoutesInReverseOrder() { + return shutdownRoutesInReverseOrder; + } + + public void setShutdownRoutesInReverseOrder(boolean shutdownRoutesInReverseOrder) { + this.shutdownRoutesInReverseOrder = shutdownRoutesInReverseOrder; + } + + public boolean isShutdownLogInflightExchangesOnTimeout() { + return shutdownLogInflightExchangesOnTimeout; + } + + public void setShutdownLogInflightExchangesOnTimeout(boolean shutdownLogInflightExchangesOnTimeout) { + this.shutdownLogInflightExchangesOnTimeout = shutdownLogInflightExchangesOnTimeout; + } + public boolean isJmxEnabled() { return jmxEnabled; } http://git-wip-us.apache.org/repos/asf/camel/blob/dcd6ab1b/examples/camel-example-spring-boot/src/main/resources/application.yml ---------------------------------------------------------------------- diff --git a/examples/camel-example-spring-boot/src/main/resources/application.yml b/examples/camel-example-spring-boot/src/main/resources/application.yml index dc362f5..6ee4f40 100644 --- a/examples/camel-example-spring-boot/src/main/resources/application.yml +++ b/examples/camel-example-spring-boot/src/main/resources/application.yml @@ -21,3 +21,4 @@ shell.auth.simple.user.password: password camel: springboot: allow-use-original-message: false + shutdown-timeout: 15