You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/05/23 04:52:22 UTC

[camel] branch camel-3.x updated: CAMEL-19359: camel-spring - Graceful shutdown in Spring Boot better s… (#10184)

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

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


The following commit(s) were added to refs/heads/camel-3.x by this push:
     new 9ef187008d1 CAMEL-19359: camel-spring - Graceful shutdown in Spring Boot better s… (#10184)
9ef187008d1 is described below

commit 9ef187008d141eed7febd08b3f73131df6476a47
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue May 23 06:24:01 2023 +0200

    CAMEL-19359: camel-spring - Graceful shutdown in Spring Boot better s… (#10184)
    
    * CAMEL-19359: camel-spring - Graceful shutdown in Spring Boot better supported. Changed the shutdown phase in SpringCamelContext to be a bit later.
---
 .../main/java/org/apache/camel/spring/SpringCamelContext.java    | 6 +++++-
 .../modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc          | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
index be794664550..16e90b994d2 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
@@ -292,7 +292,11 @@ public class SpringCamelContext extends DefaultCamelContext
         // (explained in comment in the onApplicationEvent method)
         // we use LOWEST_PRECEDENCE here as this is taken into account
         // only when stopping and then in reversed order
-        return LOWEST_PRECEDENCE;
+        return Integer.MAX_VALUE - 2049;
+        // we need to be less than max value as spring-boot comes with
+        // graceful shutdown services (the http server in spring boot)
+        // that must shutdown before camel, and they have max value - 2048,
+        // so we use 2049 to have a higher gap
     }
 
     @Override
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
index fee1b06b194..5aa10563ed5 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
@@ -104,6 +104,15 @@ For example as shown below for the context health check:
 }
 ----
 
+=== Graceful Shutdown
+
+Camel now shutdowns a bit later during Spring Boot shutdown. This allows Spring Boot graceful shutdown
+to complete first (stopping Spring Boot HTTP server gracefully),
+and then afterward Camel is doing its own xref:graceful-shutdown.adoc[].
+
+Technically `camel-spring` has changed `getPhase()` from returning `Integer.MAX_VALUE` to
+`Integer.MAX_VALUE - 2049`. This gives room for Spring Boot services to shut down first.
+
 === camel-java-joor-dsl
 
 The `camel-java-joor-dsl` cannot anymore load routes defined in class files as we consider it no more needed, consequently the ability to configure the compile directory and the compile load first flag using the corresponding `camel-main` properties is no longer possible.