Skip to Content
流架构
book

流架构

by James Urquhart
November 2022
Intermediate to advanced
276 pages
3h 51m
Chinese
China Electric Power Press Ltd.
Content preview from 流架构
112
4
4.2.2 HTTP
WebSocket
最后介绍的这两个
IoT
协议是超文本传输协议
(Hypertext Transfer Protocol
HTTP)
WebSocket
,它们在
IoT
开发人员中的采用率实际上比
MQTT
略高。
1
HTTP
本质上是一个请求
应答协议(不是发布
订阅协议,如
MQTT
),
因此不支持连接方之间的任意双向对话。但是,它可以作为具有
HTTP/2
的一些功能的流式解决方案,这是当今大多数客户端(如
Web
浏览器)和服
务器使用的
HTTP
版本。
另一方面,
WebSocket
是一种通信协议,旨在允许在
TCP
连接上进行双向对话。
它与
HTTP
不同,但被设计成可以与
HTTP
无缝衔接。如今,许多分布式系
统使用
WebSocket
作为核心连接协议,这些分布式系统必须来回发送信息以
完成任务。
HTTP
WebSocket
中的信息交换比
MQTT
更加“点对点”。这两种协议都
没有发布
订阅语义。没有用于连接和接收特定数据的“主题”概念。消费
者只需通过一个标准的
HTTP
WebSocket
请求消息向生产者发出一个请求,
然后服务器就会打开并维持一个不确定时间的连接。在
HTTP
的情况下,将
优化连接以供生产者流式传输到消费者。另一方面,
WebSocket
将很容易支
持双向流式传输。
基于
HTTP
和基于
WebSocket
的事件连接如图
4-5
所示。
生产者
HTTP请求
流数据(一种方式)
WebSocket请求
流数据(两种方式,如果需要)
消费者A
消费者B
4
-
5
HTTP WebSocket ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham

Publisher Resources

ISBN: 9787519869649