简体   繁体   English

确保收到消息

[英]Ensure that a message is received

I need to write a application that can send push notifications at clients. 我需要编写一个可以在客户端发送推送通知的应用程序。 But sometimes clients are disconnected, so I'd like to store notifications and send them to clients when they reconnect. 但有时客户端断开连接,所以我想存储通知并在重新连接时将它们发送给客户端。

Is there a way to achieve this ? 有没有办法实现这个目标? I need a way to know if client is present before sending, OR a way to know if a notification is well received. 我需要一种方法来在发送之前知道客户端是否存在,或者知道通知是否得到好评。 And my notifications are client specific. 我的通知是客户特定的。

I can't show off a lot of code, but I'd like to use something like this : 我不能炫耀很多代码,但我想使用这样的东西:

@Autowired
private SimpMessagingTemplate messagingTemplate;

public void sendPush(Long clientId) {

    messagingTemplate.convertAndSendToUser(clientId, "/queue/reply", myMessage);
    // -> how do I know if message is received ?
}

I use spring-websocket and stomp-endpoint. 我使用spring-websocket和stomp-endpoint。

Thank you ! 谢谢 !

Maybe you can expect to get an "ack" message from the user. 也许你可以期望从用户那里得到“确认”消息。 You can keep all the message in a data structure and remove them from it only when you get the ack. 您可以将所有消息保留在数据结构中,并仅在获得确认时将其从中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM