无法发布TcpConnectionOpenEvent或TcpConnectionOpenEvent,调度程序未能传递消息。

huangapple go评论134阅读模式
英文:

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

  1. @Bean
  2. public MessageChannel connectionStatusChannel() {
  3. DirectChannel directChannel = new DirectChannel();
  4. directChannel.subscribe(new ServerConnectionStatusHandler());
  5. return directChannel;
  6. }
  7. @EventListener
  8. public void listen(TcpConnectionOpenEvent event) {
  9. String eventName = "TcpConnectionOpenEvent";
  10. String destination = event.getConnectionFactoryName();
  11. connectionStatusChannel().send(new GenericMessage<>(eventName + "-" + destination));
  12. }
  13. @Component
  14. public class ServerConnectionStatusHandler implements MessageHandler {
  15. private final Logger log = LoggerFactory.getLogger(ServerConnectionStatusHandler.class);
  16. @Autowired
  17. private SimpMessageSendingOperations messagingTemplate;
  18. public ServerConnectionStatusHandler() {
  19. }
  20. @Override
  21. public void handleMessage(Message<?> message) throws MessagingException {
  22. log.debug("ServerConnectionStatusHandler # handleMessage message : {} ", message.getPayload());
  23. messagingTemplate.convertAndSend("/topic/agent/connection/tracker", message.getPayload());
  24. }
  25. }

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

  1. @Bean
  2. public MessageChannel connectionStatusChannel() {
  3. DirectChannel directChannel = new DirectChannel();
  4. directChannel.subscribe(new ServerConnectionStatusHandler());
  5. return directChannel;
  6. }
  7. @EventListener
  8. public void listen(TcpConnectionOpenEvent event) {
  9. String eventName = "TcpConnectionOpenEvent";
  10. String destination = event.getConnectionFactoryName();
  11. connectionStatusChannel().send(new GenericMessage<>(eventName + "-" + destination));
  12. }
  13. @Component
  14. public class ServerConnectionStatusHandler implements MessageHandler {
  15. private final Logger log = LoggerFactory.getLogger(ServerConnectionStatusHandler.class);
  16. @Autowired
  17. private SimpMessageSendingOperations messagingTemplate;
  18. public ServerConnectionStatusHandler() {
  19. }
  20. @Override
  21. public void handleMessage(Message<?> message) throws MessagingException {
  22. log.debug("ServerConnectionStatusHandler # handleMessage message : {} ", message.getPayload());
  23. messagingTemplate.convertAndSend("/topic/agent/connection/tracker", message.getPayload());
  24. }
  25. }

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。

我的意思是这样的:

  1. directChannel.subscribe(new ServerConnectionStatusHandler());

这样,如果你的类需要自动装配现有的 bean,你将创建一个非受管理的实例:

  1. @Bean
  2. public MessageChannel connectionStatusChannel(ServerConnectionStatusHandler handler) {
  3. DirectChannel directChannel = new DirectChannel();
  4. directChannel.subscribe(handler);
  5. return directChannel;
  6. }
英文:

You can’t say new if you would like to get access to some bean in the application context.

I mean this:

  1. directChannel.subscribe(new ServerConnectionStatusHandler());

So you create a non-managed instance if your class. Meanwhile you need to auto wire existing bean:

  1. @Bean
  2. public MessageChannel connectionStatusChannel(ServerConnectionStatusHandler handler) {
  3. DirectChannel directChannel = new DirectChannel();
  4. directChannel.subscribe(handler);
  5. return directChannel;
  6. }

答案2

得分: 0

在 listen(...) 事件中,event.getConnectionFactoryName() 为 null,或者可能是 connectionStatusHandler() 返回 null。

英文:

Seems to me in listen(...) event.getConnectionFactoryName() is null, or possibly connectionStatusHandler() is returning null

huangapple
  • 本文由 发表于 2020年8月11日 16:24:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63354306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定