通知WebSocket在PUBSUB中未接收到任何消息时

huangapple 未分类评论47阅读模式
英文:

Notifying the Websocket when no message received in PUBSUB

问题

以下是我的信息监听器,用于监听Redis的PUBSUB。它正常工作。我需要实现这样一个功能,即如果在阈值/指定时间之后没有收到任何消息,那么我必须向WebSocket发送适当的消息(订阅URL与PUBSUB频道相同)。我目前没有找到任何方法可以实现这一点,因为会有许多客户端在不同的时间订阅不同的频道。

任何帮助或建议都将不胜感激。

public class PubSubListener implements MessageListener {		
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate ;	

    @Override
    public void onMessage(Message message, byte[] pattern) {
        logger.info("从PUBSUB接收到消息");
        simpMessagingTemplate.convertAndSend(new String(pattern), message.toString());
    }
}
英文:

Below is my Message Listener which listens to Redis PUBSUB. It is working fine. I have to implement a feature in such a way that if no messages are received after threshold/specified time, then I have to send a proper message to websocket(subscription URL same as PUBSUB channel). I don't see any way to that as there will be many clients which subscribes to different channels at different times.

Any help or suggestion would be appreciable.

public class PubSubListener implements MessageListener {		
	@Autowired
	private SimpMessagingTemplate simpMessagingTemplate ;	

	@Override
	public void onMessage(Message message, byte[] pattern) {
		logger.info(" MESSAGE RECEIVED FROM PUBSUB ");
        simpMessagingTemplate.convertAndSend(new String(pattern), message.toString());
	}
}

huangapple
  • 本文由 发表于 2020年5月29日 16:16:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/62081553.html
匿名

发表评论

匿名网友

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

确定