简体   繁体   中英

Spring Integration HTTP Inbound Gateway Request Overlap

I have an HTTP Inbound Gateway in my Integration Application, which I will call during some save operation. It's like this. If I have one product, I will call the API once, and if I have more than once, then I will call multiple times. The problem is, for single invoke, SI works just fine. But for multiple calls, request and response get messed up. I thought Spring Integration Channels are just like MQ's, but it is not?

Let me explain this. Let's say I have 2 products. First, I invoke SI for Product A and then for B. Response of A got mapped to request B! It happens all the time. I don't want to use some dirty hacks like wait for the first response to come and invoke again. This means the system has to wait for a long time. I guess we can do it in Spring Integration using task executor, but with all the basic samples out there, I can't find the right one. So please help me find out how can I fix this issue!

My Configuration is :

<int:channel id="n2iMotorCNInvokeRequest" />
<int:channel id="n2iMotorCNInvokeResponse" />
<int:channel id="n2iInvoketransformerOut" />
<int:channel id="n2iInvokeobjTransformerOut" />
<int:channel id="n2iInvokegatewayOut" />

<int-http:inbound-gateway id="i2nInvokeFromPOS" 
    supported-methods="GET"
    request-channel="i2nInvokeRequest"
    reply-channel="i2nInvokeResponse"
    path="/postProduct/{Id}"
    mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
    reply-timeout="50000">
    <int-http:header name="Id" expression="#pathVariables.Id"/>
</int-http:inbound-gateway>

<int:service-activator id="InvokeActivator"
                input-channel="i2nInvokeRequest"
                output-channel="i2nInvokeResponse"
                ref="apiService"
                method="getProductId"
                requires-reply="true"
                send-timeout="60000"/>

<int:transformer input-channel="i2nInvokeResponse"
        ref="apiTransformer"
        method="retrieveProductJson" 
        output-channel="n2iInvokeRequest"/>

<int-http:outbound-gateway request-channel="n2iInvokeRequest" reply-channel="n2iInvoketransformerOut"
    url="http://10.xx.xx.xx/api/index.php" http-method="POST" 
    expected-response-type="java.lang.String">
</int-http:outbound-gateway>


<int:service-activator 
            input-channel="n2iInvoketransformerOut" 
            output-channel="n2iInvokeobjTransformerOut"
            ref="apiService" 
            method="productResponse"
            requires-reply="true"
            send-timeout="60000"/>

The i2nInvokeFromPOS gateway is what we call from Web Application which is where all the products will be created. This Integration API will fetch that data, and post it to the backend system so that it will get updated to the other POS locations too!

Steps :

  1. I will send the productId to i2nInvokeFromPOS.

  2. apiTransformer -> retrieveProductJson() method will fetch the product details from DB based on the ID

  3. Send the Request JSON to Backend system using http:outbound-gateway

  4. Get the response from Backend and update the product status as uploaded in DB. Happens in apiService -> productResponse()

Once the response for A is received, all I'm getting is HTTP 500 Error for the Request B! But the Backend API is just fine.

The framework is completely thread-safe - if you are seeing cross-talk between different requests/responses then one (or more) of your components that the framework is invoking is not thread-safe.

You can't keep state in fields in, for example, code invoked from a service activator.

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