gpt4 book ai didi

java - Spring 集成 : TcpOutboundGateway getting DestinationResolutionException: no output-channel or replyChannel header available

转载 作者:行者123 更新时间:2023-11-30 08:53:33 25 4
gpt4 key购买 nike

我正在尝试使用 TcpOutboundGateway 通过 TCP 与遗留(非 spring)系统通信并处理响应,但我收到以下错误:DestinationResolutionException:没有可用的输出 channel 或 replyChannel header

示例遗留监听器的代码启动,然后启动 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();
}
}
}

最佳答案

请参阅 the documentation 中的注释.当用 @ServiceActivator 注释一个 @Bean 时,输出 channel 需要在消息处理程序(网关 bean)上进行,而不是注释。

您还应该调用start()。让上下文来做。

关于java - Spring 集成 : TcpOutboundGateway getting DestinationResolutionException: no output-channel or replyChannel header available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com