如何确保websockets的可靠消息传递? [英] How to assure reliable message delivery of websockets?

查看:605
本文介绍了如何确保websockets的可靠消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的服务器,其主要任务是向用户推送通知,例如典型的推送通知服务器。我使用 java websockets 通过websocket会话将通知推送给用户。在开发相同的内容时,我列出了一些要求,其中可靠的消息传递是其中一项要求。

I am developing a simple server whose primary task is to push notifications to users like a typical Push Notification Server. I have used java websockets for pushing the notification to the users through websocket session. While developing the same I have a list of some requirements in which reliable message delivery is one of the requirement.

我正在将通知推送到特殊用户如下,

I am pushing the notification to particular user like below,

session.getBasicRemote().sendObject(notification);

但上面的方法返回 void ,这就是为什么我无法断定通知是否已送达另一端。
其中一个选项是,预期用户会将反馈发送到我的服务器以获得相同的通知,我会将相同的通知标记为已成功发送。但它可能会导致网络流量增加。

but above method returns void, thats why I am not able to conclude whether the notification is delivered to the other end or not. One of the option was, intended user will send feedback to my server for the same notification and I will mark the same notification as delivered successfully. But it could cause a increase in network traffic.

是否有任何标准方法可确保通过 websocket会话发送通知成功传递通知

Is there any standard way to make sure that the notification is delivered successfully while sending it through websocket session

推荐答案

websockets规范实际上是低级别的,并不提供发送消息的确认。您必须自己将其作为应用程序级协议实现,或者在websockets之上使用现有协议。

The websockets specification is really low level and does not provide a confirmation for send messages. You have to either implement this yourself as an application-level protocol or use an existing protocol on top of websockets.

Stomp是一种流行的协议,定义了ACK回复消费消息: Stomp规范

Stomp is a popular protocol which defines an "ACK" reply for consumed messages: Stomp specification

这篇关于如何确保websockets的可靠消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆