简体   繁体   English

Spring Integration-如果值为null则中断流程

[英]Spring Integration - Break the flow if value is null

So I have a configuration in my Spring Integration like below : 所以我在Spring Integration中有一个如下配置:

POS -> invoke SI by passing ID -> Get Details of that ID -> Hit the API URL POS->通过传递ID调用SI->获取该ID的详细信息->点击API URL

Now what I'm trying to achieve is, 现在我想要实现的是

POS -> invoke SI by passing ID -> Get Details of that ID -> If not null (If null, then break the flow) -> Hit the API URL POS->通过传递ID调用SI->获取该ID的详细信息-> 如果不为null(如果为null,则中断流程) ->命中API URL

And my config file looks like this : 我的配置文件如下所示:

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

I know about error channel, but the problem here is, if the returned value is null, I don't want to continue or retry! 我知道错误通道的信息,但是这里的问题是,如果返回的值为null,则我不想继续或重试! Just break it and stop the flow. 打破它,停止流动。 Can someone point me towards the possible ways to do this? 有人可以指出我可行的方法吗?

Returning null ends the flow; 返回null结束流程; no further action is taken, although with your configuration, the inbound gateway thread will wait 10 seconds for the reply before timing out. 尽管您进行了配置,但入站网关线程将等待10秒钟等待答复,然后再超时,因此无需采取进一步的措施。

Then a 500 status is returned to the caller; 然后,将500状态返回给呼叫者; you can change that behavior with the reply-timeout-status-code-expression . 您可以使用reply-timeout-status-code-expression更改该行为。

Since you are using only direct channels, you can safely set the reply timeout to zero - the timer does not start until the thread returns to the gateway. 由于仅使用直接通道,因此可以安全地将答复超时设置为零-直到线程返回网关,计时器才会启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM