Apache Camel - 22 - Controlling route startup and shutdown(Camel控制路由的启动/关闭顺序)

Apache Camel 控制路由的启动/关闭顺序

When integration logic is composed of routes depending on other routes via direct:, it is important that they start up in such a way that dependencies are available before exchanges start flowing.

If not, you are likely to see this sort of exception being thrown:

org.apache.camel.CamelExchangeException: No consumers available on endpoint: Endpoint[direct://someMissingEndpoint]

控制路由启动和关闭

当集成逻辑直接依赖于其他路由的路由组成时,重要的是它们以在交换开始流动之前可用的依赖性的方式启动。

如果没有,您可能会看到抛出此类异常:

org.apache.camel.CamelExchangeException:端点上没有可用的消费者:端点[direct://someMissingEndpoint]

Conversely, on application shutdown, messages should complete processing gracefully rather than fail because a dependent route is no longer available. Camel provides a mechanism to define an order for startup and shutdown that addresses both of these issues at the same time.

This recipe will show you how to control the startup and shutdown order of your routes.

相反,在应用程序关闭时,消息应该正常完成处理而不是失败,因为依赖路由不再可用。

Camel提供了一种机制来定义启动和关闭的顺序,同时解决这两个问题。

此配方将向您展示如何控制路线的启动和关闭顺序。

个人理解就是:

多个路由互相依赖,在程序启动/关闭的时候,如果不控制其启动顺序,那么它们可能会出现异常信息。

可能由于一个端点初始化、关闭时间较长,导致其他依赖它的端点取不到数据,而抛出异常信息。

 

如何实现Apache Camel 路由启动顺序的控制?

在Spring XML SDL 中:

<route startupOrder="20">
	<from uri="jms:queue:orders"/>
	<to uri="direct:processOrder"/>
</route>

在route节点上增加一个属性即可(里面具体的值,等下再说)

在Java SDL中:

from("jms:queue:orders").startupOrder(20).to("direct:processOrder");

在Java API中,startupOrder(int order)的注释:

配置此路由的启动顺序

Camel将重新排序路线,并按0..N排序它们,其中0是最低编号,N是最高编号。 当它停止时,Camel将以相反的顺序停止路线。

启动时:从低到高顺序执行;

停止时:从高到低书序执行;

When you shut down the application, Camel will turn off the routes in the reverse orderto that in which it started them. Routes are turned off in descendingorder.

When a route shuts down, the endpoint consumer is first turned off, and any messages that are flowing through the route ("in-flight") are allowed to complete before the route itself is shut down. Any messages that remain in-flight will be discarded after a timeout of 300 seconds.

The timeout is configurable on the Camel context's associated ShutdownStrategy.

当您关闭应用程序时,Camel将关闭与其启动它们相反的路径。 路由以降序关闭。

当路由关闭时,首先关闭端点消费者,并且允许在路由本身关闭之前完成流经该路由的任何消息(“in-flight”)。 在300秒超时后,任何保留在飞行中的消息都将被丢弃。

可以在Camel上下文的关联ShutdownStrategy上配置超时。

猜你喜欢

转载自blog.csdn.net/Simba_cheng/article/details/81366143