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

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

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

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:

确定