Spring 如何避免MessageDeliveryException?
我试图通过tcp发送一条简单的消息,但我甚至无法使用spring集成来管理它。。。我真的厌倦了 因此,我尝试在客户端模式下使用TcpOutboundGateway和TcpInboudGateway,但得到了MessageDeliveryException 这是我的密码:Spring 如何避免MessageDeliveryException?,spring,tcp,spring-integration,Spring,Tcp,Spring Integration,我试图通过tcp发送一条简单的消息,但我甚至无法使用spring集成来管理它。。。我真的厌倦了 因此,我尝试在客户端模式下使用TcpOutboundGateway和TcpInboudGateway,但得到了MessageDeliveryException 这是我的密码: @EnableIntegration @IntegrationComponentScan @Configuration public class TcpClientConfiguration { @Bean p
@EnableIntegration
@IntegrationComponentScan
@Configuration
public class TcpClientConfiguration {
@Bean
public TcpNetClientConnectionFactory clientConnectionFactory() {
TcpNetClientConnectionFactory factory = new TcpNetClientConnectionFactory("localhost", 7015);
return factory;
}
@Bean
public DirectChannel outputChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel replyChannel() {
return new DirectChannel();
}
// @Bean
// public TcpOutboundGateway tcpOutGateway(AbstractClientConnectionFactory clientConnectionFactory) {
// TcpOutboundGateway outGateway = new TcpOutboundGateway();
// outGateway.setConnectionFactory(clientConnectionFactory);
// outGateway.setOutputChannel(outputChannel());
// return outGateway;
// }
@Bean
public TcpInboundGateway tcpInboundGateway(AbstractClientConnectionFactory clientConnectionFactory) {
TcpInboundGateway inGateway = new TcpInboundGateway();
inGateway.setConnectionFactory(clientConnectionFactory);
inGateway.setClientMode(true);
inGateway.setRequestChannel(outputChannel());
inGateway.setReplyChannel(replyChannel());
return inGateway;
}
}
以及发送消息的计划方法:
@Component
public class SimulatorTask {
@Autowired
DirectChannel outputChannel;
@Scheduled( fixedDelay = 3000 )
public void sendMsg() {
outputChannel.send(new GenericMessage<>("Hello world!"));
}
}
我真的对春天感到厌倦了…所以,发生的事情是你成功地发送了消息。消息确实成功到达您选择为DirectChannel的
outputChannel
。
根据定义,DirectChannel需要订阅者,而我在您的配置中没有看到订阅者(例如@Transformer
或@ServiceActivator
或任何其他类型的MessageHandler
),异常情况正好告诉您这一点。
因此,如果您只想验证消息是否已发送,您可能需要选择不同的通道实现。例如,您可以选择QueueChannel
,它将缓冲消息直到从中轮询消息,或者选择publishsubscribebechnel
,如果没有订阅者,它将丢弃消息。
或者,添加订阅服务器
@ServiceActivator(inputChannel="outputChannel", outputChannel="replyChannel")
public Message echo(Message message) {
return message;
}
所以,发生的情况是您成功地发送了消息。消息确实成功到达您选择为DirectChannel的
outputChannel
。
根据定义,DirectChannel需要订阅者,而我在您的配置中没有看到订阅者(例如@Transformer
或@ServiceActivator
或任何其他类型的MessageHandler
),异常情况正好告诉您这一点。
因此,如果您只想验证消息是否已发送,您可能需要选择不同的通道实现。例如,您可以选择QueueChannel
,它将缓冲消息直到从中轮询消息,或者选择publishsubscribebechnel
,如果没有订阅者,它将丢弃消息。
或者,添加订阅服务器
@ServiceActivator(inputChannel="outputChannel", outputChannel="replyChannel")
public Message echo(Message message) {
return message;
}
我还可以建议你玩一些从基础到非常高级的样本,它们可以让你更快地掌握事物。谢谢你快速完整的回答:)我还可以建议你玩一些从基础到非常高级的样本,它们可以让你更快地掌握事物。谢谢你的帮助快速而完整的回答:)它有效