【发布时间】:2020-08-11 08:24:17
【问题描述】:
在 spring 集成中,我使用事件监听器来处理 TcpConnectionOpenEvent 或 TcpConnectionCloseEvent。
当我使用下面的代码博客时,我可以处理连接打开关闭应用程序事件,但我收到类似警告日志
2020-08-11 11:15:46.857 WARN 7104 --- [XNIO-1 task-1] o.s.i.i.tcp.connection.TcpNetConnection :无法发布 TcpConnectionOpenEvent [一些细节] 已打开: Dispatcher 无法传递消息;嵌套异常是 java.lang.NullPointerException
@Bean
public MessageChannel connectionStatusChannel() {
DirectChannel directChannel = new DirectChannel();
directChannel.subscribe(new ServerConnectionStatusHandler());
return directChannel;
}
@EventListener
public void listen(TcpConnectionOpenEvent event) {
String eventName = "TcpConnectionOpenEvent";
String destination = event.getConnectionFactoryName();
connectionStatusChannel().send(new GenericMessage<>(eventName + "-" + destination));
}
@Component
public class ServerConnectionStatusHandler implements MessageHandler {
private final Logger log = LoggerFactory.getLogger(ServerConnectionStatusHandler.class);
@Autowired
private SimpMessageSendingOperations messagingTemplate;
public ServerConnectionStatusHandler() {
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
log.debug("ServerConnectionStatusHandler # handleMessage message : {} ", message.getPayload());
messagingTemplate.convertAndSend("/topic/agent/connection/tracker", message.getPayload());
}
}
这不会破坏我的流程,但我想了解我为什么要接受此警告以及如何清除它。没有@EventListener,它就会消失......
感谢您的帮助
【问题讨论】:
标签: java spring spring-boot tcp spring-integration