Orderly Shutdown

如 "MBean Exporter" 中所述,MBean 导出器提供一个名为 `stopActiveComponents`的 JMX 操作,用于以有序方式停止应用程序。该操作有一个 `Long`参数。该参数表示该操作等待以完成正在传输消息所需的时间(以毫秒为单位)。操作方法如下:

As described in "MBean Exporter", the MBean exporter provides a JMX operation called stopActiveComponents, which is used to stop the application in an orderly manner. The operation has a single Long parameter. The parameter indicates how long (in milliseconds) the operation waits to allow in-flight messages to complete. The operation works as follows:

  1. Call beforeShutdown() on all beans that implement OrderlyShutdownCapable.[.iokays-translated-6fb2b154e850a637844a9936dabc489a] 这样做可以使此类组件为关闭做准备。实现此接口的组件及其使用此调用的功能的示例包括:停止其侦听器容器的 JMS 和 AMQP 消息驱动的适配器、停止接受新连接(同时保持现有连接打开)的 TCP 服务器连接工厂、放弃(记录)任何接收到的新消息的 TCP 入站端点以及为任何新请求返回 “503 - 服务不可用” 的 HTTP 入站端点。

Doing so lets such components prepare for shutdown. Examples of components that implement this interface and what they do with this call include JMS and AMQP message-driven adapters that stop their listener containers, TCP server connection factories that stop accepting new connections (while keeping existing connections open), TCP inbound endpoints that drop (log) any new messages received, and HTTP inbound endpoints that return 503 - Service Unavailable for any new requests. . Stop any active channels, such as JMS- or AMQP-backed channels. . Stop all MessageSource instances. . Stop all inbound MessageProducer s (that are not OrderlyShutdownCapable). . Wait for any remaining time left, as defined by the value of the Long parameter passed in to the operation.[.iokays-translated-ce956089282cc5edaedd9c5a07f873c7] 这样做可以使任何正在进行的消息完成其进程。因此,在调用此操作时选择一个合适的超时非常重要。

Doing so lets any in-flight messages complete their journeys. It is therefore important to select an appropriate timeout when invoking this operation. . Call afterShutdown() on all OrderlyShutdownCapable components.[.iokays-translated-d998f20b83c266de05b8dcdde6b3369b] 这样做可以使此类组件执行最终关闭任务(例如,关闭所有打开的套接字)。

Doing so lets such components perform final shutdown tasks (closing all open sockets, for example).

Orderly Shutdown Managed Operation中所述,该操作可以通过使用 JMX 来调用。如果您希望以编程方式调用方法,您需要注入 IntegrationMBeanExporter`或其他获得它的引用。如果未在 `<int-jmx:mbean-export/>`定义中提供 `id`特性,则该 bean 有一个生成名称。该名称中包含一个随机组件,以避免如果同一个 JVM 中有多个 Spring Integration 上下文 (`MBeanServer),出现 `ObjectName`冲突。

As discussed in Orderly Shutdown Managed Operation, this operation can be invoked by using JMX. If you wish to programmatically invoke the method, you need to inject or otherwise get a reference to the IntegrationMBeanExporter. If no id attribute is provided on the <int-jmx:mbean-export/> definition, the bean has a generated name. This name contains a random component to avoid ObjectName collisions if multiple Spring Integration contexts exist in the same JVM (MBeanServer).

因此,如果你希望通过编程方式调用该方法,我们建议你向该 Exporter 提供一个 “id” 属性,以便你可以在应用程序上下文中轻松访问它。

For this reason, if you wish to invoke the method programmatically, we recommend that you provide the exporter with an id attribute so that you can easily access it in the application context.

最后,可以使用 <control-bus> 元素调用该操作。有关详细信息,请参阅 monitoring Spring Integration sample application

Finally, the operation can be invoked by using the <control-bus> element. See the monitoring Spring Integration sample application for details.

先前改进的算法在 4.1 版本得到优化,以前所有任务执行程序和计划程序都会停止,这可能导致 QueueChannel 实例中的中间流程消息保留下来。现在,关闭会让轮询器保持运行,以便让这些消息被抽取并处理。

The algorithm described earlier was improved in version 4.1. Previously, all task executors and schedulers were stopped. This could cause mid-flow messages in QueueChannel instances to remain. Now the shutdown leaves pollers running, to let these messages be drained and processed.