首页 > 解决方案 > Websocket没有收到超过2条消息

问题描述

我们有一个后端 Java 应用程序,它会定期在石英作业上发布消息。Quartz 作业是按时间间隔安排的,并且运行良好。每条消息有 1 个作业,因为每条消息的间隔不同。如果有 3 条消息,则完美触发 3 个作业。

但我无法在前端接收消息,因为它只接收 2 而不是 3。

请问有什么预感吗??

我的工作代码:

public void execute(JobExecutionContext context) throws JobExecutionException {

    JobDataMap dataMap = context.getMergedJobDataMap();
    service = new BannerNotificationService();

    String notificationId = dataMap.getString(NOTIFICATION_ID);

    String INVALID_JOB = "-1";
    if(!notificationId.equals(INVALID_JOB)){
        try {
            WebsocketEndPointHandler.sendMessageToAll(service.getNotificationDto(sendNotif));
        } catch (IOException | EncodeException e) {
            e.printStackTrace();
        }
    }

}

我的套接字处理程序代码:

public static void sendMessageToAll(NotificationDto message) throws IOException, EncodeException {
     UserSessionHandler.endPoints.forEach(endpoint -> {
        try {
            endpoint.getBasicRemote().sendObject(new NotificationMessage().build(message)); 

        } catch (IOException | EncodeException e) {
            e.printStackTrace();
        }
    });
}

标签: javaspringwebsocketjersey

解决方案


推荐阅读