如何设计带断路器的弹簧集成服务激活器的后备?

时间:2014-08-12 15:44:47

标签: spring spring-integration

当触发断路器建议时,注意不要使失效的集成服务过载。

当电路打开时,我如何回退到不同的服务激活器?当电路闭合时需要回退到主激活器

有没有办法用框架实现这个?或者必须编写一些自定义代码

1 个答案:

答案 0 :(得分:0)

您可以使用内联网关捕获异常并将其发送到错误通道;然后,您可以在错误流上使用路由器来决定如何继续进行。希望以下内容相当容易理解......

<int:service-activator input-channel="inbound" ref="gw" />

<int:gateway id="gw" default-request-channel="toPrimary"
    error-channel="failures" 
    default-reply-timeout="0" />

<int:service-activator input-channel="toPrimary" expression=" 1 / 0 ">
    <int:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.RequestHandlerCircuitBreakerAdvice">
            <property name="threshold" value="2" />
            <property name="halfOpenAfter" value="10000" />
        </bean>
    </int:request-handler-advice-chain>
</int:service-activator>

<!-- Error flow -->

<int:publish-subscribe-channel id="failures" />

<int:logging-channel-adapter id="failing" channel="failures" />

<int:recipient-list-router input-channel="failures" default-output-channel="nullChannel" >
    <int:recipient channel="circuitFailures" selector-expression="payload.message.contains('Expression evaluation failed:  1 / 0') || payload.cause.message.contains('Circuit Breaker is Open')" />
</int:recipient-list-router>

<int:chain input-channel="circuitFailures" output-channel="loggingChannel">
    <int:transformer expression="payload.failedMessage" />
    <int:service-activator expression="payload + ' failed'" />
</int:chain>

<int:logging-channel-adapter id="loggingChannel" log-full-message="false" logger-name="tapInbound"
    level="INFO" />