此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1spring-doc.cadn.net.cn

向端点添加行为

在 Spring Integration 2.2 之前,您可以通过将 AOP Advice 添加到轮询器的<advice-chain/>元素。 但是,假设您只想重试 REST Web 服务调用,而不是任何下游端点。spring-doc.cadn.net.cn

例如,考虑以程:spring-doc.cadn.net.cn

inbound-adapter->poller->http-gateway1->http-gateway2->jdbc-outbound-adapter

如果您在轮询器上的通知链中配置了一些重试逻辑,并且调用http-gateway2由于网络故障而失败,重试会导致http-gateway1http-gateway2第二次被叫。 同样,在 jdbc-outbound-adapter 中发生暂时性故障后,在再次调用jdbc-outbound-adapter.spring-doc.cadn.net.cn

Spring Integration 2.2 添加了向单个端点添加行为的功能。 这是通过添加<request-handler-advice-chain/>元素到许多端点。 以下示例演示了如何将<request-handler-advice-chain/>元素outbound-gateway:spring-doc.cadn.net.cn

<int-http:outbound-gateway id="withAdvice"
    url-expression="'http://localhost/test1'"
    request-channel="requests"
    reply-channel="nextChannel">
    <int-http:request-handler-advice-chain>
        <ref bean="myRetryAdvice" />
    </int-http:request-handler-advice-chain>
</int-http:outbound-gateway>

在这种情况下,myRetryAdvice仅在本地应用于此网关,不适用于在将回复发送到nextChannel. 建议的范围仅限于端点本身。spring-doc.cadn.net.cn

目前,您无法建议整个<chain/>的端点。 架构不允许<request-handler-advice-chain>作为链本身的子元素。spring-doc.cadn.net.cn

但是,一个<request-handler-advice-chain>可以添加到<chain>元素。 一个例外是,在不产生回复的链中,因为链中的最后一个元素是outbound-channel-adapter,最后一个元素不能被建议。 如果您需要建议这样的元素,则必须将其移动到链之外(使用output-channel链的input-channel适配器的)。 然后可以像往常一样建议适配器。 对于生成回复的链,可以建议每个子元素。spring-doc.cadn.net.cn