英文:
Failed to publish TcpConnectionOpenEvent Or TcpConnectionOpenEvent, Dispatcher failed to deliver Message
问题
In spring integration i am using event Listener to handle TcpConnectionOpenEvent or TcpConnectionCloseEvent.
When i use code blog below, i can handle connection open close application event but i am receiving Warning log like
> 2020-08-11 11:15:46.857 WARN 7104 --- [ XNIO-1 task-1] o.s.i.i.tcp.connection.TcpNetConnection : Failed to publish TcpConnectionOpenEvent [SOME DETAIL] OPENED:Dispatcher failed to deliver Message; nested exception is 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());
}
}
This does not break my flow but i want to understand why i am taking this warnig and how can i clear it. Without @EventListener it disappers...
Thanks for helping
英文:
In spring integration i am using event Listener to handle TcpConnectionOpenEvent or TcpConnectionCloseEvent.
When i use code blog below, i can handle connection open close application event but i am receiving Warning log like
> 2020-08-11 11:15:46.857 WARN 7104 --- [ XNIO-1 task-1] o.s.i.i.tcp.connection.TcpNetConnection : Failed to publish TcpConnectionOpenEvent [SOME DETAIL] OPENED:Dispatcher failed to deliver Message; nested exception is 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());
}
}
This does not break my flow but i want to understand why i am taking this warnig and how can i clear it. Without @EventListener it disappers...
Thanks for helping
答案1
得分: 1
你无法使用 new
关键字来访问应用程序上下文中的某个 bean。
我的意思是这样的:
directChannel.subscribe(new ServerConnectionStatusHandler());
这样,如果你的类需要自动装配现有的 bean,你将创建一个非受管理的实例:
@Bean
public MessageChannel connectionStatusChannel(ServerConnectionStatusHandler handler) {
DirectChannel directChannel = new DirectChannel();
directChannel.subscribe(handler);
return directChannel;
}
英文:
You can’t say new
if you would like to get access to some bean in the application context.
I mean this:
directChannel.subscribe(new ServerConnectionStatusHandler());
So you create a non-managed instance if your class. Meanwhile you need to auto wire existing bean:
@Bean
public MessageChannel connectionStatusChannel(ServerConnectionStatusHandler handler) {
DirectChannel directChannel = new DirectChannel();
directChannel.subscribe(handler);
return directChannel;
}
答案2
得分: 0
在 listen(...) 事件中,event.getConnectionFactoryName() 为 null,或者可能是 connectionStatusHandler() 返回 null。
英文:
Seems to me in listen(...) event.getConnectionFactoryName() is null, or possibly connectionStatusHandler() is returning null
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论