首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QueueChannel在Spring集成中的应用

QueueChannel在Spring集成中的应用
EN

Stack Overflow用户
提问于 2017-06-27 21:22:27
回答 1查看 571关注 0票数 1

我正在做下面的案例研究。

  1. 创建接受引用id的Rest服务。
  2. 使用引用Id从数据库获取数据(CLOB)。
  3. 将数据(CLOB)放入通道(队列)中,以便进一步处理。
  4. 用JSON格式的响应数据回复rest客户端{"status":true,"message":"RECEIVED"}

我已经创建了Rest服务,并且使用Ref Id从数据库获取数据,但是在将消息放入通道(队列)后,我无法将响应发送回rest客户端。Rest客户端接收的输出为:在超时中没有收到答复

基本上,我希望在数据(CLOB)被推送到通道(队列)后立即返回请求线程。

下面是配置。

代码语言:javascript
复制
<int:channel id="responseChannel"/>
<int:channel id="initCalculation">
   <int:queue/>
</int:channel>


<!-- GET -->
<int-http:inbound-gateway 
    request-channel="httpGetChannel"
    reply-channel="responseChannel"
    supported-methods="GET"
    path="/init/{refId}"
    payload-expression="#pathVariables.refId">

    <int-http:request-mapping  produces="application/json"/>

</int-http:inbound-gateway>


<int:chain input-channel="httpGetChannel" output-channel="initCalculation">
    <int-jdbc:stored-proc-outbound-gateway
            id="outbound-gateway-storedproc-get-forma" data-source="dataSource"
            is-function="false"
            stored-procedure-name="XX_EMPROC.GET_FRMA"
            ignore-column-meta-data="true"
            expect-single-result="true">

        <int-jdbc:sql-parameter-definition name="V_REF_ID" direction="IN" />
        <int-jdbc:sql-parameter-definition name="V_FRMA"   direction="OUT" type="#{T(oracle.jdbc.OracleTypes).CLOB}"/>

        <int-jdbc:parameter name="V_REF_ID" expression="payload" />
    </int-jdbc:stored-proc-outbound-gateway>

    <!- Convert to JSON Format -->
    <int:service-activator ref="brInitGateway" method="getResponse"/>

</int:chain>


<int:outbound-channel-adapter channel="initCalculation"  ref="brInitGateway"   method="process"/>

请告知以上所需的更正。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-27 21:38:51

看,没有人会将消息作为回复发送给<int-http:inbound-gateway>。您已经声明了responseChannel,但是谁将使用它作为output-channel

我建议你这样做:

代码语言:javascript
复制
<publish-subscribe-channel id="responseChannel"/>

<int:chain input-channel="httpGetChannel" output-channel="responseChannel">


 <int:bridge input-channel="responseChannel" output-channel="initCalculation"/>

那么,这里发生了什么:

作为订阅者之一,用于publish-subscribe-channelreply-channelreplyChannel报头建立了一个内部桥。

您可以从<chain>向该频道发送一个结果。因此,<int-http:inbound-gateway>将得到它的答复。

有了对<int:bridge>的响应,您就有了第二个订阅服务器,因此,会向所需的队列发送一条消息。

如果您对brInitGateway.getResponse()请求的答复不感兴趣,则应该考虑根本没有该reply-channel="responseChannel",但仍然使用一些<publish-subscribe-channel>发送到队列,使用一些转换器来准备答复,例如:

代码语言:javascript
复制
<transformer input-channel="prepareProcess" expression="' {"status": true,"message": "RECEIVED"}'"/>

此转换器没有output-channel,因为它将将其结果发送到replyChannel头,因此发送到<int-http:inbound-gateway>启动器。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44790143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档