int-http:outbound-gateway reply-channel'stalls'

时间:2016-01-21 19:02:47

标签: http spring-integration gateway reply outbound

我正在使用Spring Boot创建一个Spring Integration原型。

我有一个'hub'接受控制台输入并将其发送到单独的socket / tcp应用程序。

tcp应用程序回应它在回复中心时发送的内容。

然后集线器接受tcp响应&将它发送到一个单独的restful / http应用程序。 http应用程序回应了发送回集线器的内容。

我被困在集线器的int-http:outbound-gateway上,它向http发送请求。当我省略'reply-channel'时,我可以输入多个文本并发送到tcp应用程序。该回复被转发到http应用程序&打印在控制台中。 但是,当我包含一个回复频道时,我可以向tcp应用程序发送一条消息(http应用程序接收它),然后集线器应用程序“停止”;我在控制台中键入消息,点击“输入”但没有任何反应。

这是我的配置:

    <!-- TO tcp application/server -->
    <int:channel id="input" />

    <int:gateway id="simple.gateway"
        service-interface="com.foo.SimpleGateway"
        default-request-channel="input"/>

    <int-ip:tcp-connection-factory id="client"
        type="client"
        host="localhost"
        port="4444"
        single-use="true"
        so-timeout="10000"/>

    <int-ip:tcp-outbound-gateway id="outGateway"
        request-channel="input"
        reply-channel="clientBytes2StringChannel"
        connection-factory="client"
        request-timeout="10000"
        reply-timeout="10000"/>     

    <int:object-to-string-transformer id="clientBytes2String"
        input-channel="clientBytes2StringChannel"
        output-channel="broadcast.channel" />

    <int:channel id="broadcast.channel" />

    <int:recipient-list-router id="tcp.broadcast.list"
        input-channel="broadcast.channel">
        <int:recipient channel="to.http" />
        <!-- other channels to broadcast to -->
    </int:recipient-list-router>

    <!-- TO HTTP restful endpoint -->
    <!-- this sends the requests -->
    <int:channel id="to.http" />

<!--    <int-http:outbound-gateway id="http-outbound-gateway"  -->
<!--        request-channel="to.http" -->
<!--        url="http://localhost:8080/howdy?message={msg}" -->
<!--        http-method="GET" -->
<!--        expected-response-type="java.lang.String" -->
<!--        charset="UTF-8"> -->
<!--        <int-http:uri-variable name="msg" expression="payload"/> -->
<!--    </int-http:outbound-gateway> -->

    <int-http:outbound-gateway id="http-outbound-gateway" 
        request-channel="to.http"
        url="http://localhost:8080/howdy?message={msg}"
        http-method="GET"
        expected-response-type="java.lang.String"
        charset="UTF-8"
        reply-channel="from.http.pubsub.channel">
        <int-http:uri-variable name="msg" expression="payload"/>
    </int-http:outbound-gateway>

<!-- http://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html -->
<int:publish-subscribe-channel id="from.http.pubsub.channel" />

<bean id="inboundHTTPPrinterService"
        class="com.foo.service.InboundHTTPPrinterService"/> 

<int:service-activator id="inboutdHttpPrintServiceActivator"
    ref="inboundHTTPPrinterService"
    input-channel="from.http.pubsub.channel"
    method="printFromHttp"/>

</beans>

在最终形式中,我希望在某处打印HTTP响应并转发到单独的AMQP应用程序。

1 个答案:

答案 0 :(得分:0)

您的说明并不清楚,但是,我想,您的意思是这里有一些问题:

<int:service-activator id="inboutdHttpPrintServiceActivator"
    ref="inboundHTTPPrinterService"
    input-channel="from.http.pubsub.channel"
    method="printFromHttp"/>

很高兴看到printFromHttp()源代码,但根据您的担心,该方法似乎是void

要将邮件发送回标题中的replyChannel,您应该从服务方法中返回一些内容。在您的情况下,如果是payloadmessage就足够了。