11= Graceful Shutdown
22
33Camel supports a pluggable shutdown strategy using
4- `org.apache.camel.spi.ShutdownStrategy` . Its responsible for shutting
4+ `org.apache.camel.spi.ShutdownStrategy` . It's responsible for shutting
55down routes in a graceful manner. The other resources will still be
6- handled by xref:camelcontext.adoc[CamelContext] to shutdown . This leaves
6+ handled by xref:camelcontext.adoc[CamelContext] to shut down . This leaves
77the problem at hand with properly shutting down all the routes reliably
88to the `ShutdownStrategy` .
99
@@ -13,12 +13,11 @@ doing that.
1313
1414== Default Shutdown Strategy
1515
16- The default strategy (`DefaultShutdownStrategy`) will gracefully shutdown routes:
16+ The default strategy (`DefaultShutdownStrategy`) will gracefully shut down routes:
1717
1818* in the reverse order they were started
19- * let pending and current in flight exchanges run to completion before
20- shutting down
21- * using a timeout of 45 seconds which then forces a _hard_ shutdown
19+ * let pending and current in flight exchanges run to completion before shutting down
20+ * using a timeout of 45 seconds (can be configured) which then forces a _hard_ shutdown
2221
2322The settings are configurable, so you can change the timeout, and
2423whether in case of timeout to force a _hard_ shutdown or ignore.
@@ -40,24 +39,40 @@ When shutting down the strategy will output to log the progress:
4039---------------------------------
4140
4241Notice how the strategy waits while there are inflight exchanges still being
43- processed before it shutdown the routes and after that Camel itself.
42+ processed before it shut down the routes and after that Camel itself.
4443
4544=== Suppressing logging due to timeout not allowing all inflight messages to complete
4645
4746If a graceful shutdown could not shutdown cleanly within the given
4847timeout period, then Camel performs a more aggressive shutdown (hard) by
4948forcing routes and thread pools etc to shut down, and the routing
50- engine will reject continue processing xref:exchange.adoc[Exchange]s . If
51- this happens you may see WARN logs about xref:exchange.adoc[Exchange]s
49+ engine will reject continue processing xref:exchange.adoc[Exchange](s) . If
50+ this happens you may see WARN logs about xref:exchange.adoc[Exchange](s)
5251being rejected and other failures due the forced shutdown.
5352
5453If you do not want to see these logs, you can suppress this by setting
55- the option suppressLoggingOnTimeout to true.
54+ the option ` suppressLoggingOnTimeout` to true.
5655
56+
57+ [tabs]
58+ ====
59+
60+ Java::
61+ +
5762[source,java]
58- ---------------------------------
63+ ----
5964context.getShutdownStrategy().setSuppressLoggingOnTimeout(true);
60- ---------------------------------
65+ ----
66+
67+ Application Properties::
68+ +
69+ Or in `application.properties`:
70+ +
71+ [source,properties]
72+ ----
73+ camel.main.shutdownSuppressLoggingOnTimeout = true
74+ ----
75+ ====
6176
6277Notice that suppression is _a best effort_ attempt and there may still be some
6378logging from 3rd party libraries, which Camel cannot control.
@@ -66,7 +81,7 @@ logging from 3rd party libraries, which Camel cannot control.
6681
6782If a graceful shutdown could not shutdown cleanly within the given
6883timeout period, then Camel performs a more aggressive shutdown by
69- forcing routes and thread pools etc to shut down. When the timeout
84+ forcing routes and thread pools etc. to shut down. When the timeout
7085happens, then Camel logs information about the current inflight
7186exchanges, which shows from which route the exchange origins, and where
7287it currently is being routed. For example the logging below, shows that
@@ -91,11 +106,26 @@ duration=2017]
91106If you do not want to see these logs, you can turn this off by setting
92107the option logInflightExchangesOnTimeout to false.
93108
109+ [tabs]
110+ ====
111+
112+ Java::
113+ +
94114[source,java]
95115---------------------------------
96116context.getShutdownStrategy().setLogInflightExchangesOnTimeout(false);
97117---------------------------------
98118
119+ Application Properties::
120+ +
121+ Or in `application.properties`:
122+ +
123+ [source,properties]
124+ ----
125+ camel.main.logInflightExchangesOnTimeout = false
126+ ----
127+ ====
128+
99129=== JMX managed
100130
101131The `ShutdownStrategy` is JMX aware, so you can manage it from a
@@ -161,7 +191,7 @@ It is possible to stop (will do a gracefully shut down) an individual route usin
161191camelContext.getRouteController().stopRoute(routeId);
162192----
163193
164- Routes can also be stopped via JMX.
194+ TIP: Routes can also be stopped via JMX or external tools such as https://hawt.io/[Hawtio] .
165195
166196=== Stopping and marking routes as failed due to an exception
167197
@@ -180,7 +210,7 @@ NOTE: The Camel xref:health-check.adoc[Health Check] detect the route as failed
180210If the route is manually stopped, then the route is not marked as failed,
181211and the xref:health-check.adoc[Health Check] will report the status as UNKNOWN.
182212
183- Routes can also be stopped and failed via JMX.
213+ TIP: Routes can also be stopped and failed via JMX or external tools such as https://hawt.io/[Hawtio] .
184214
185215== Implementing custom component or ShutdownStrategy
186216
@@ -196,7 +226,7 @@ on the `CamelContext` using the `setShutdownStrategy` method.
196226=== ShutdownAware
197227
198228The interface `org.apache.camel.spi.ShutdownAware` is an optional
199- interface consumers can implement to have fine grained control during
229+ interface consumers can implement to have fine- grained control during
200230shutdown. The `ShutdownStrategy` must be able to deal with consumers
201231which implement this interface. This interface was introduced to cater
202232for in memory consumers such as xref:components::seda-component.adoc[SEDA] which potentially
0 commit comments