3

I'm creating a Spring Integration prototype using Spring Boot.

I have a 'hub' that accepts console input and sends that to an separate socket/tcp application.

The tcp application echos what it was sent in its reply to the hub.

The hub then takes the tcp response & sends it to a separate restful/http application. The http application echos what is was sent back to the hub.

I'm stuck on the hub's int-http:outbound-gateway which send a request to http. When i omit the 'reply-channel', i can enter more than one bit of text and send to the tcp application. That reply is forwarded to the http application & printed in the console. However, when i include a reply-channel, i can send one message to the tcp application (the http app receives it) and then the hub application 'stalls'; i type messages in console, hit 'enter' but nothing happens.

Here's my config:

    <!-- 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>

In its final form, i want the HTTP response to be printed somewhere AND forwarded to a separate AMQP application.

maspen
  • 301
  • 1
  • 6
  • 17

1 Answers1

0

Your description isn't clear, however, I guess, you mean some issue in here:

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

It would be great to see the printFromHttp() source code, but according your fears it seems for that the method is void.

To send message back to the replyChannel in the headers you should return something from your service method. Looks like in your case it is just enough the same payload or message if that.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • that resolved the 'stall' issue (i added a String return type to printFromHttp(). What i'm seeing now, is that the reply from TCP is not recorded in my "main" where i'm sending the message but after the round-trip from the http client. – maspen Jan 22 '16 at 19:03
  • As I said: your description isn't clear. Maybe we'll consider to close this one for the `stalls` issue and open an new one, closer to your current problem and already with its environment? Consider also to share some logs/Exceptions on the matter. Sorry, I just don't understand you with such an info in the question. – Artem Bilan Jan 22 '16 at 19:06