Spring Integration - 如果value为null,则中断流

时间:2016-11-28 04:58:03

标签: java spring spring-integration

所以我在Spring Integration中有一个配置,如下所示:

POS - >通过传递ID调用SI - >获取该ID的详细信息 - >点击API网址

现在我想要实现的是,

POS - >通过传递ID调用SI - >获取该ID的详细信息 - > 如果不为null(如果为null,则打破流程) - >点击API网址

我的配置文件如下所示:

<int-http:inbound-gateway id="CNInvokeFromPOS" 
    supported-methods="GET"
    request-channel="CNInvokeRequest"
    reply-channel="CNInvokeResponse"
    path="/postToCN/{CNId}"
    mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
    reply-timeout="10000" >
    <int-http:header name="CNId" expression="#pathVariables.CNId"/>
</int-http:inbound-gateway>

<int:service-activator id="motorCNInvokeActivator"
                input-channel="CNInvokeRequest"
                output-channel="CNInvokeResponse"
                ref="apiCNService"
                method="getCNDetailsById"
                requires-reply="true"
                send-timeout="10000"/>

<int:transformer input-channel="CNInvokeResponse"
        ref="apiCNTransformer"
        method="retrieveJson" 
        output-channel="CNInvokeRequest"/>

<int-http:outbound-gateway request-channel="CNInvokeRequest" reply-channel="CNInvoketransformerOut"
    url="http://someurl" http-method="POST"
    expected-response-type="java.lang.String">
</int-http:outbound-gateway>    

<int:service-activator 
            input-channel="CNInvoketransformerOut" 
            output-channel="CNInvokeobjTransformerOut"
            ref="apiCNService" 
            method="responseCN"
            send-timeout="10000"/>

我知道错误通道,但问题是,如果返回的值为null,我不想继续或重试!打破它,停止流动。有人能指出我可能采取的方法吗?

1 个答案:

答案 0 :(得分:1)

返回null结束流程;不会采取进一步的操作,但是在您的配置下,入站网关线程将在超时前等待10秒钟。

然后将500状态返回给调用者;您可以使用reply-timeout-status-code-expression更改该行为。

由于您只使用直接通道,因此可以安全地将回复超时设置为零 - 在线程返回网关之前,计时器不会启动。

相关问题