我正在尝试使用TcpOutboundGateway通过TCP与传统(非弹簧)系统进行通信并处理响应,但是我收到以下错误:DestinationResolutionException:没有可用的输出通道或replyChannel标头
代码踢示例遗留侦听器,然后启动spring boot应用程序。
我正在努力弄清楚我做错了什么 - 或者我是否采取了正确的方法。任何建议将不胜感激。
(我在这里发布了带有注释的格式问题,因此删除了@) TY
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Test {
private static MessageChannel sendChannel;
@Bean
public MessageChannel replyChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel sendChannel() {
MessageChannel directChannel = new DirectChannel();
sendChannel = directChannel;
return directChannel;
}
@Bean
TcpNetClientConnectionFactory tcpNetClientConnectionFactory() {
TcpNetClientConnectionFactory tcpNetClientConnectionFactory = new TcpNetClientConnectionFactory("me.me", 9003);
return tcpNetClientConnectionFactory;
}
@Bean
@ServiceActivator(inputChannel = "sendChannel", outputChannel = "replyChannel", requiresReply = "true")
TcpOutboundGateway tcpOutboundGateway() {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(tcpNetClientConnectionFactory());
tcpOutboundGateway.start();
return tcpOutboundGateway;
}
public static void main(String args[]) {
new LegacyApplication();
SpringApplication.run(Test.class, args);
Test.sendChannel.send(new GenericMessage("mgr?task=-1"));
}
}
@MessageEndpoint
class ReplyListener {
@ServiceActivator(inputChannel = "replyChannel")
public void telemetryHandler(String message) {
System.out.println(message);
}
}
class LegacyApplication implements Runnable {
public LegacyApplication() {
(new Thread(this)).start();
}
@Override
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(9003);
Socket clientSocket = serverSocket.accept();
System.out.println("LegacyApplication: Accepted");
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
System.out.println("LegacyApplication: " + in.readLine());
out.write("OK\r\n");
out.flush();
System.out.println("LegacyApplication: Done");
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:2)
请参阅the documentation中的注释。使用@Bean
注释@ServiceActivator
时,输出通道需要继续使用消息处理程序(网关bean),而不是注释。
您还应不致电start()
。让上下文做到这一点。