GH-9455: Introduce IntegrationKeepAlive (#9493)

Fixes: #9455
Issue link: https://github.com/spring-projects/spring-integration/issues/9455

* Add an `IntegrationKeepAlive` infrastructure bean to initiate a long-lived non-daemon thread
to keep application alive when it cannot be kept like that for various reason, but has to.
* Expose `spring.integration.keepAlive` global property to disable an `IntegrationKeepAlive` auto-startup
* Test and document the feature
This commit is contained in:
Artem Bilan
2024-09-25 14:31:41 -04:00
committed by GitHub
parent 52e8174c66
commit 8f838d04ce
12 changed files with 374 additions and 1 deletions

View File

@@ -99,6 +99,7 @@
** xref:shutdown.adoc[]
** xref:graph.adoc[]
** xref:integration-graph-controller.adoc[]
** xref:keep-alive.adoc[]
* xref:reactive-streams.adoc[]
* xref:native-aot.adoc[]
* xref:endpoint-summary.adoc[]

View File

@@ -19,6 +19,7 @@ spring.integration.endpoints.noAutoStartup= <7>
spring.integration.channels.error.requireSubscribers=true <8>
spring.integration.channels.error.ignoreFailures=true <9>
spring.integration.endpoints.defaultTimeout=30000 <10>
spring.integration.keepAlive=true <11>
----
<1> When true, `input-channel` instances are automatically declared as `DirectChannel` instances when not explicitly found in the application context.
@@ -57,6 +58,11 @@ Since version 5.5.
Default value is 30 seconds to avoid indefinite blocking.
Can be configured to a negative value to restore infinite blocking behavior in endpoints.
Since version 6.2.
<11> Whether to start the `IntegrationKeepAlive`.
Default is `true`, however depends on the beans in the application context.
See xref:keep-alive.adoc[Keep Alive] for more information.
Since version 6.4.
====
These properties can be overridden by adding a `/META-INF/spring.integration.properties` file to the classpath or an `IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME` bean for the `org.springframework.integration.context.IntegrationProperties` instance.
@@ -77,5 +83,6 @@ spring.integration.channels.maxBroadcastSubscribers=0x7fffffff
spring.integration.readOnly.headers=
spring.integration.messagingTemplate.throwExceptionOnLateReply=true
spring.integration.endpoints.defaultTimeout=30000
spring.integration.keepAlive=false
----

View File

@@ -0,0 +1,17 @@
[[keep-alive]]
= Integration Keep Alive
Starting with version 6.4, Spring Integration provides an `IntegrationKeepAlive` infrastructure bean.
It manages an `spring-integration-keep-alive` non-daemon forever thread which keeps an application running.
In some use-cases, e.g. `WebSocketInboundChannelAdapter` based on the `StandardWebSocketClient` does not use non-daemon thread for session, therefore an application may exit prematurely.
Or an application logic may have only service activators or outbound channel adapters which rely on some other interaction, but not loops from executors like the one from Web server.
Or all the threads in the application are virtual.
The `IntegrationKeepAlive` is started automatically only if `TaskScheduler` is configured for non-daemon threads and there is no `AbstractPollingEndpoint` beans in the application context.
In case of the `TaskScheduler` bean configured for daemon or virtual threads, the `IntegrationKeepAlive` is started regardless of the presence for `AbstractPollingEndpoint` beans.
This component can be disabled by the `spring.integration.keepAlive` global property.
See xref:configuration/global-properties.adoc[Global Properties] for more information.
The `IntegrationKeepAlive` can be injected in some service and stopped manually if there is no need to keep an application alive or such a status is managed somewhere else.
See also Spring Boot https://docs.spring.io/spring-boot/reference/features/spring-application.html#features.spring-application.virtual-threads[Virtual Threads] documentation for a `spring.main.keep-alive` property.

View File

@@ -27,6 +27,10 @@ The SpEL evaluation infrastructure now supports configuration for `IndexAccessor
Also, an out-of-the-box `JsonIndexAccessor` is provided.
See xref:spel.adoc[SpEL Support] for more information.
The `IntegrationKeepAlive` component has been introduced.
See xref:keep-alive.adoc[Integration Keep Alive] for more information.
[[x6.4-general]]
=== General Changes