简体   繁体   English

MQTT over WebSocket和SSE(服务器发送事件)之间的区别

[英]Difference between MQTT over WebSocket and SSE(Server Send Event)

When publish/subscribe to messages directly from a web server to a web browser or vice versa we can use MQTT over WebSockets. 当直接从Web服务器发布/订阅消息到Web浏览器或反之时,我们可以在WebSockets上使用MQTT。 At the same time, SSE(half duplex) can be used to push data from web server to web browser. 同时,SSE(半双工)可用于将数据从Web服务器推送到Web浏览器。 What are the other major differences? 其他主要差异是什么? Especially related security and consistency of the application. 特别是应用程序的安全性和一致性。

WebSocket is a low-level (framing) transport standardized by the IETF and a JavaScript API standardized by the W3C. WebSocket是由IETF标准化的低级(框架)传输和由W3C标准化的JavaScript API。 It is not publish/subscribe. 它不是发布/订阅。 You can have publish/subscribe protocols that sit "on top" of WebSocket. 您可以拥有位于WebSocket“顶部”的发布/订阅协议。 For example, AMQP is a pub/sub protocol that can be implemented with WebSocket. 例如,AMQP是可以使用WebSocket实现的发布/订阅协议。 Another example is Java Message Service (JMS); 另一个例子是Java消息服务(JMS); while JMS is an API and not a bit protocol, it can be implemented over a pub/sub protocol that, in turn, is implemented with WS. 虽然JMS是API而不是位协议,但它可以通过pub / sub协议实现,而pub / sub协议又通过WS实现。 I mention both AMQP and JMS because both the AMQP protocol and the JMS API provide for "acknowledgements", which will give you a high degree of reliability unlike other mechanisms. 我提到了AMQP和JMS,因为AMQP协议和JMS API都提供了“确认”,与其他机制不同,它将为您提供高度可靠性。

MQTT is a publish/subscribe protocol that can be implemented over a low-level transport. MQTT是一种发布/订阅协议,可以通过低级传输实现。 MQTT can run over TCP/IP or WebSocket for example. 例如,MQTT可以在TCP / IP或WebSocket上运行。 MQTT has QoS levels which also give you acknowledgements (ie, for reliability). MQTT具有QoS级别,也可以为您提供确认(即可靠性)。 MQTT is not normally native to a browser, so MQTT messages have to be made web-friendly before connecting to a browser... usually WebSocket, since WS is a 'fat pipe' and similar to TCP in a way. MQTT通常不是浏览器的原生代码,因此在连接到浏览器之前必须使MQTT消息成为Web友好的...通常是WebSocket,因为WS在某种程度上是一个“胖管”并且类似于TCP。

Server-Sent Events (SSE) is a HTML5 formalization of "Comet" (or "reverse AJAX) techniques. "Comet" was a loose collection of informal techniques; different implementations did not work together. SSE is not publish/subscribe. It is an HTTP mechanism to broadcast data from a server to the browser client(s). Essentially its a fire-and-forget technique. 服务器发送事件(SSE)是“Comet”(或“反向AJAX”)技术的HTML5形式化。“Comet”是非正式技术的松散集合;不同的实现不能一起工作.SSE不是发布/订阅。它是一种HTTP机制,用于将数据从服务器广播到浏览器客户端。本质上是一种即发即弃的技术。

Most modern browsers understand SSE and WS (IE/EDGE does not currently support SSE); 大多数现代浏览器都了解SSE和WS(IE / EDGE目前不支持SSE); they usually all understand Secure WebSocket (WSS) too. 他们通常都了解Secure WebSocket(WSS)。 Practically all webservers and appservers understand SSE and WS/WSS. 实际上,所有Web服务器和应用程序服务器都了解SSE和WS / WSS。 If you use WSS, your data will be encrypted in transit. 如果您使用WSS,您的数据将在传输过程中加密。 The particular encryption cipher is setup on the connection; 在连接上设置特定的加密密码; you'll have to investigate what ciphers your browser clients and web/app-servers understand. 您将不得不调查您的浏览器客户端和Web /应用程序服务器所了解的密码。

MQTT offers 3 different QOS levels that control delivery of messages MQTT提供3种不同的QOS级别来控制消息的传递

QOS 0 - Best effort QOS 1 - At least once QOS 2 - Once only QOS 0 - 尽力而为QOS 1 - 至少一次QOS 2 - 仅一次

MQTT supports User authentication and topic level ACL so you can ensure users only see what they need to see even when using wildcard subscriptions MQTT支持用户身份验证和主题级ACL,因此您可以确保用户只能看到即使使用通配符订阅也需要查看的内容

MQTT also allows for direct connection to the backend systems without the need for bridging in the WebApp MQTT还允许直接连接到后端系统,而无需在WebApp中进行桥接

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

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