Отправка и получение данных с использованием сокета Spring Integration TCP IP - PullRequest
0 голосов
/ 05 декабря 2018

Я создаю простое весеннее загрузочное приложение (PoC) для отправки идентификаторов продукта (строки) с клиента на сервер через сокет с использованием Spring интеграции TCP.Если на сервере указаны правильные данные о продукте, сервер ответит информацией о продукте, которую мне нужно распечатать.Просто нужно установить соединение и получить ответ, отправив нужные данные.

Скажите, пожалуйста, какие классы я должен реализовать?исходящие / входящие шлюзы, каналы сообщений, tcplisteners?Должен ли я пойти с конфигурацией XML или аннотации?Я новичок в SI и был бы очень полезен, если бы вы могли дать мне представление о том, как его реализовать.


Вот мой обновленный xml интеграции.

<int-ip:tcp-connection-factory id="client" type="client" host="XX.XX.XX.99" port="9XXX" single-use="true" so-timeout="10000" />

<int:channel id="input"/>

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

<int:service-activator input-channel="clientBytes2StringChannel" ref="echoService" method="test"/> 

<bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/>

<int:channel id="toSA"/>

Но это все еще печатает отраженный результат.Кроме того, когда я вызываю getHost для abstractClientConnectionfactory из основного класса, он показывает «localhost».Как я могу подтвердить, что соединение активно?


<int:gateway id="gw"
             service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
             default-request-channel="input"/>

<int-ip:tcp-connection-factory id="client" type="client" host="xx.xx.xx.99"
                         port="9xxx"
                         single-use="false" so-timeout="300000" using-nio="false"
                         so-keep-alive="true" serializer="byteArrayRawSerializer"
                             deserializer="byteArrayRawSerializer"/>


<bean id="byteArrayRawSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer" />


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

<int:object-to-string-transformer id="clientBytes2String"
                                  input-channel="responseBytes2StringChannel" output-channel="toSA"/>


<int:service-activator input-channel="toSA" ref="echoService" method="test"/> 

<bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/>

<int:channel id="toSA"/> 

<int:transformer id="errorHandler" input-channel="errorChannel" expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
<int:channel id="responseBytes2StringChannel"></int:channel>

**** Обновить SI xml ****

<int:gateway id="gw"
             service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
             default-request-channel="objectIn"/>

<int:channel id="objectIn" />

<int-ip:tcp-connection-factory id="client"
                               type="client"
                               host="xx.xx.xx.99"
                               port="9xxx"
                               single-use="true"
                               so-timeout="50000"
                               using-nio="false"
                               so-keep-alive="true"/>
                               <!-- 
                               serializer="byteArrayLengthSerializer"
                               deserializer="byteArrayLengthSerializer"

<bean id="byteArrayLengthSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer " />
-->
<int:payload-serializing-transformer input-channel="objectIn" output-channel="objectOut"/>

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

<int:payload-deserializing-transformer input-channel="bytesIn" output-channel="objectOut" />

<int:object-to-string-transformer id="clientBytes2String"
                                  input-channel="objectOut" output-channel="toSA"/>



<int:service-activator input-channel="toSA" ref="echoService" method="test"/> 

<bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/>

<int:channel id="objectOut"/> 
<int:channel id="toSA"/> 
<int:channel id="bytesIn"/> 

1 Ответ

0 голосов
/ 05 декабря 2018

Я предлагаю вам сначала пройти путь документации: https://docs.spring.io/spring-integration/docs/current/reference/html/ip.html, чтобы выяснить, что Spring Integration предоставляет вам в отношении TCP / IP.Тогда было бы здорово перейти к образцам проектов, чтобы увидеть, что мы предлагаем для конфигурации и вариантов использования: https://github.com/spring-projects/spring-integration-samples

...