繁体   English   中英

Spring Integration HTTP入站网关请求重叠

[英]Spring Integration HTTP Inbound Gateway Request Overlap

我的集成应用程序中有一个HTTP入站网关,在某些保存操作期间将调用它。 就像这样。 如果我有一个产品,我将调用一次API,如果我有多个产品,则将调用多次。 问题是,对于单次调用,SI可以正常工作。 但是对于多个呼叫,请求和响应变得混乱。 我以为Spring Integration Channels就像MQ一样,但是不是吗?

让我解释一下。 假设我有2种产品。 首先,我先对产品A调用SI,然后对产品B调用。A的响应已映射到请求B! 它一直在发生。 我不想使用一些肮脏的技巧,例如等待第一个响应出现并再次调用。 这意味着系统必须等待很长时间。 我想我们可以使用任务执行程序在Spring Integration中做到这一点,但由于那里有所有基本示例,所以我找不到合适的示例。 因此,请帮助我找出如何解决此问题!

我的配置是:

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

i2nInvokeFromPOS网关是我们从Web应用程序调用的位置,它将在其中创建所有产品。 该Integration API将获取该数据,并将其发布到后端系统,以便也将其更新到其他POS位置!

脚步 :

  1. 我将productId发送到i2nInvokeFromPOS。

  2. apiTransformer-> RetrieveProductJson()方法将根据ID从数据库中获取产品详细信息

  3. 使用http:outbound-gateway将请求JSON发送到后端系统

  4. 从后端获取响应,并更新数据库中上传的产品状态。 发生在apiService-> productResponse()中

收到A的响应后,我得到的只是请求B的HTTP 500错误! 但是后端API很好。

该框架是完全线程安全的-如果您看到不同的请求/响应之间存在串扰,则该框架正在调用的一个(或多个)组件不是线程安全的。

您不能在例如从服务激活器调用的代码中的字段中保持状态。

暂无
暂无

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

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