http - 内部 http :outbound-gateway reply-channel 'stalls'

标签 http spring-integration gateway reply outbound

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

我有一个“集线器”,它接受控制台输入并将其发送到单独的套接字/tcp 应用程序。

tcp 应用程序在其对集线器的回复中回显它发送的内容。

集线器然后获取 tcp 响应并将其发送到单独的 restful/http 应用程序。 http 应用程序回应发送回集线器的内容。

我卡在集线器的 int-http:outbound-gateway 上,它向 http 发送请求。当我省略“回复 channel ”时,我可以输入多于一位的文本并发送到 tcp 应用程序。该回复被转发到 http 应用程序并打印在控制台中。 但是,当我包含回复 channel 时,我可以向 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 应用程序。

最佳答案

你的描述不清楚,不过,我想你的意思是这里有些问题:

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

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

要将消息发送回 header 中的 replyChannel,您应该从服务方法中返回一些内容。看起来在你的情况下它就足够了相同的 payloadmessage 如果是的话。

关于http - 内部 http :outbound-gateway reply-channel 'stalls' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34932194/

相关文章:

http - 如何根据 HTTP 请求获取响应 header ?

java - HttpURLConnection总是返回错误500

java - Spring 集成和接收日期问题

php - 对加拿大 SMS 网关提供商的建议

java - Spring Integration Gateway 中的静态和动态 header

java - 如何在jsp中查找默认网关ip地址

java - HTTP 错误 401.2 尝试使用 DefaultHttpClient 调用具有用户名和密码的 URL 时

sqlite - NodeJS 上下文问题

spring-integration - 使用 DSL 的 Spring Integration JDBC 出站 channel 适配器

java - Spring集成自定义处理步骤