简体   繁体   中英

Spring Integration - Break the flow if value is null

So I have a configuration in my Spring Integration like below :

POS -> invoke SI by passing ID -> Get Details of that ID -> Hit the 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

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! Just break it and stop the flow. Can someone point me towards the possible ways to do this?

Returning null ends the flow; no further action is taken, although with your configuration, the inbound gateway thread will wait 10 seconds for the reply before timing out.

Then a 500 status is returned to the caller; you can change that behavior with the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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