带断路器的弹簧集成服务激活器的后撤设计



当断路器通知被触发时,这会注意不要使失败的集成服务过载。

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

是否有一种方法来实现这个框架?或者写一些自定义代码

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

<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" />

最新更新