简体   繁体   English

为什么HTTP + Web套接字不适合作为消息传递协议?

[英]Why is HTTP + Web Sockets not suitable as a messaging protocal?

I've read that HTTP is not suitable as a messaging protocol in several places such as here in reference to RabbitMQ. 我已经读到HTTP在许多地方都不适合作为消息传递协议,例如在这里引用RabbitMQ。

I assume that there's a technical reason for this and that it's not a mere opinion. 我认为这是有技术原因的,并非仅出于意见。 I've looked through the AMQP spec for example and can't see any reason why HTTP + Web Sockets can't work. 我已经查看了AMQP 规范 ,但看不到HTTP + Web套接字无法正常工作的任何原因。 In fact, something seems to be in the works for AMQP over Web Sockets. 实际上,基于Web套接字的AMQP似乎正在工作 Furthermore, I've looked at the STOMP protocol which does use HTTP + Web Sockets and can't see any significant limitations (other than a small performance hit). 此外,我研究了STOMP协议,该协议的确使用HTTP + Web套接字,并且看不到任何重大限制(除了对性能造成的小影响之外)。

What technical characteristic does HTTP + Web Sockets lack that makes it unsuitable as a messaging protocol? HTTP + Web套接字缺少什么技术特征使其不适合用作消息传递协议?

UPDATE: This is what I was looking for: Crossbar.IO - a WAMP message broker. 更新:这就是我想要的: Crossbar.IO -WAMP消息代理。 I needed a message broker that I can easily connect to from a browser and have not been satisfied with RabbitMQ (over STOMP) or HiveMQ (MQTT). 我需要一个可以轻松从浏览器连接到并且对RabbitMQ(通过STOMP)或HiveMQ(MQTT)不满意的消息代理。

HTTP is request/response based, what makes it difficult to work in a publisher/subscriber fashion. HTTP基于请求/响应,这使得以发布者/订阅者的方式工作变得困难。 Basically, you can either poll the source of messages for new ones, or create another local endpoint where the other end push messages to you. 基本上,您可以轮询消息源中是否有新消息,或者创建另一个本地终结点,另一端将消息推送给您。

WebSocket is different. WebSocket是不同的。 Despite of starting as a HTTP request, it switches straightaway to a persistent, full-duplex connection, where both end can push data. 尽管开始时是HTTP请求,但它会立即切换到持久的全双工连接,两端都可以推送数据。 Basically, in this case HTTP is only used as protocol to negotiate the connection, once negotiated WebSocket uses its own protocol to transfer data. 基本上,在这种情况下,HTTP仅用作协商连接的协议,协商后的WebSocket使用其自己的协议来传输数据。

UPDATE: We are clear that HTTP is not a messaging protocol, since it is request/response. 更新:我们很清楚,HTTP不是消息协议,因为它是请求/响应。 WebSockets, although it allows pushing data from both ends, it is not a messaging protocol neither. WebSockets尽管允许从两端推送数据,但它也不是消息传递协议。 It defines a way of framing data, but there are not defined semantic or grammar to subscribe to topics or any operation about messaging. 它定义了一种框架数据的方式,但是没有定义语义或语法来订阅主题或有关消息的任何操作。 For example WAMP is an actual messaging protocol for websockets. 例如, WAMP是用于Websocket的实际消息传递协议。

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

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