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

查看:24
本文介绍了如何确保 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 session

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天全站免登陆