私はSpring統合でTCPクライアントを実装しようとしています。私はソケットにデータをポンピングするリモートTCPサーバを持っています。私のSpringベースのTCPクライアントは、入ってくるソケットからデータを受け取る必要があります。spring-integration TCPゲートウェイは、ソケットからデータを送受信します
クライアント私は自分の側からサーバーにデータを送信していません。接続してデータを受信するだけです。このhttp://forum.spring.io/forum/spring-projects/integration/94696-want-to-configure-simple-tcp-client-to-receive-data-from-java-based-tcp-server?view=threadを見ると、これは不可能であると私は理解していました。しかし、受け取った回答はかなり古いですが、現在利用可能な設定はありますか?
ご質問がある場合はお知らせください。
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:config.xml");
context.registerShutdownHook();
context.refresh();
final SimpleGateway gateway = context.getBean(SimpleGateway.class);
int i=0;
while(i++<10){
String h = gateway.receive();
System.out.println(System.currentTimeMillis()+h);
マイTCPモックサーバー:
while(true) {
try {
System.out.println("Waiting for client on port " +
serverSocket.getLocalPort() + "...");
Socket server = serverSocket.accept();
System.out.println("Just connected to "
+ server.getRemoteSocketAddress());
DataOutputStream out =
new DataOutputStream(server.getOutputStream());
out.write("ACK\r\n".getBytes());
out.flush();
//server.close();
} catch(SocketTimeoutException s) {
System.out.println("Socket timed out!");
break;
} catch(IOException e) {
e.printStackTrace();
break;
}
}
マイゲートウェイクラス:
public interface SimpleGateway {
public String receive();
}
は、コンフィギュレーションここで
<bean id="javaSerializer" class="org.springframework.core.serializer.DefaultSerializer" />
<bean id="javaDeserializer" class="org.springframework.core.serializer.DefaultDeserializer" />
<context:property-placeholder />
<!-- Client side -->
<int:gateway id="gw"
service-interface="com.my.client.SimpleGateway"
default-request-channel="input" default-reply-channel="replies" />
<int-ip:tcp-connection-factory id="client"
type="client" host="localhost" port="5678"
single-use="false" so-timeout="10000" serializer="javaSerializer"
deserializer="javaDeserializer" so-keep-alive="true"/>
<int:channel id="input" />
<int:channel id="replies">
<int:queue />
</int:channel>
<!-- <int-ip:tcp-outbound-gateway id="outGateway" request-channel="input"
reply-channel="reply" connection-factory="client" request-timeout="10000"
reply-timeout="10000" /> -->
<int-ip:tcp-outbound-channel-adapter
id="outboundClient" channel="input" connection-factory="client" />
<int-ip:tcp-inbound-channel-adapter
id="inboundClient" channel="replies" connection-factory="client"
client-mode="true" retry-interval="10000" auto-startup="true" />
である私のリモートTCPクライアントと@updated
ご連絡ありがとうございます。私はこれをGITであなたの例にしています。私は上記の設定を行い、結果を返します。うまくいけば私はそれを手に入れよう! :) –
説明した設定で試しました。しかし、私はサーバーからの応答を参照してください。私は何かを見逃しているのか間違っているのかわからない。メソッドとして定義されたインターフェイスゲートウェイが 'public String receive(String text);'です。 TCPサーバーからデータを受信するだけです。 xmlの設定については、前述のドキュメントを参照してください。上記の設定を確認してください。 My Clientの 'TCPClient'では' receive() 'を呼び出しますが、データは受信されません。 –
上記の設定を更新した後、私はカスタムdesializer、むしろjava deserialilzerを使ってみました。良いことは、私はデータが 'deserialize()'メソッドに入ってくるのを見ていますが、私の 'TCPClient.receive()'にはデータが入っていないことです。 okToRunがtrueであるので、実行メソッドで 'org.springframework.integration.ip.tcp.connection.TcpNetConnection 'に固執しています。私はあなたがこのクラスの著者であるので、これを詳しく書いています。 –