10
私はthisに行っており、接続を受け入れるにはTcpReceivingChannelAdapter
を作成する必要があることを理解しました。 しかし、私はそれを進める方法を知らない。春の起動時に接続を受け入れるTcp接続を作成するには?
誰かが私にこれを案内できますか?
私はthisに行っており、接続を受け入れるにはTcpReceivingChannelAdapter
を作成する必要があることを理解しました。 しかし、私はそれを進める方法を知らない。春の起動時に接続を受け入れるTcp接続を作成するには?
誰かが私にこれを案内できますか?
XML設定を使用するポインタについては、tcp-client-server sampleを参照してください。
Java構成の場合。ここには簡単なSpring Bootアプリがあります。
package com.example;
import java.net.Socket;
import javax.net.SocketFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
import org.springframework.integration.transformer.ObjectToStringTransformer;
import org.springframework.messaging.MessageChannel;
@SpringBootApplication
public class So39290834Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(So39290834Application.class, args);
Socket socket = SocketFactory.getDefault().createSocket("localhost", 9999);
socket.getOutputStream().write("foo\r\n".getBytes());
socket.close();
Thread.sleep(1000);
context.close();
}
@Bean
public TcpNetServerConnectionFactory cf() {
return new TcpNetServerConnectionFactory(9999);
}
@Bean
public TcpReceivingChannelAdapter inbound(AbstractServerConnectionFactory cf) {
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(cf);
adapter.setOutputChannel(tcpIn());
return adapter;
}
@Bean
public MessageChannel tcpIn() {
return new DirectChannel();
}
@Transformer(inputChannel = "tcpIn", outputChannel = "serviceChannel")
@Bean
public ObjectToStringTransformer transformer() {
return new ObjectToStringTransformer();
}
@ServiceActivator(inputChannel = "serviceChannel")
public void service(String in) {
System.out.println(in);
}
}
完璧!あなたは、私がSpringブートのJavaベースの設定に関する文書をどこで見つけることができるかを教えてください。 – amitection
私はあなたが何を意味するか分かりません。起動時にSpring IntegrationコンポーネントのJava設定を意味する場合は、参考マニュアルにいくつかの例がありますが、すべてのモジュールではまだありません。私たちはあなたを導くための[セクション](http://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips)を持っており、ほとんどの場合、基礎となるコンポーネントに関する情報をどこに見つけるかを指しています要素。 –
これはまさに私が意味していたものです。ありがとう、トン! – amitection