Generic Realtime Intermediary Protocol
转自:https://pushpin.org/docs/protocols/grip/
Introduction
The Generic Realtime Intermediary Protocol (“GRIP”) makes it possible for a web service to delegate realtime push behavior to a proxy component. Listening entities, such as long-lived HTTP or WebSocket connections, are managed by the proxy. The web service backend can instruct the proxy to associate listeners with publish-subscribe channels. The web service backend may publish data to channels, and the proxy will relay the data to all associated listeners. When data is published, the entirety of the transmission is specified, allowing complete control over the application protocol exposed to listeners.

There are many advantages to this approach:
Reusability. The primary goal of GRIP is to isolate the common aspects of realtime push functionality into a reusable proxy component. A GRIP proxy should be able to power any kind of web service, with any kind of API contract, for any kind of application, running at any organization. Adding new endpoints, changing protocol flows, or using different data formats should be possible without modifying the proxy.
Simplified routing. Knowing if or where a listening entity may be connected in a cluster makes for a tricky routing problem. It’s simpler for data sources to publish data to channels rather than to individual listeners. With GRIP, data can be sent to a sole proxy, or to each proxy instance in a cluster (either directly or optionally via a message queue), without having to know whether or not any listeners are present.
High scalability. Many listeners may be associated with a single channel. This means data can be sent to the proxy once and multicasted to a set of listeners. Proxies can be chained to message brokers to form a multi-tiered architecture capable of massive output (e.g. publishing to a million connections at the same time across a set of proxies).
Stateless development. In the case of long-lived HTTP connections such as long-polling or streaming, a GRIP proxy communicates to a backend server using short-lived HTTP requests. This means the backend doesn’t have to maintain long-lived connections and it can generally operate statelessly; it can handle incoming requests statelessly and publish data to the proxy statelessly. In the case of WebSockets, a proxy and backend may optionally choose to communicate statelessly on the backend side (e.g. via HTTP).
Transports
There are two main transports defined: HTTP and WebSocket.
HTTP
The HTTP GRIP transport allows a proxy to hold open HTTP requests on behalf of a backend web service, facilitating realtime data push over those held requests. There are two hold modes: response and stream.
When a request is made to the proxy, the proxy forwards it to a backend server. The proxy may include special headers. The following request headers are defined:
Grip-Sig: A JSON Web Token signed with a key known between the proxy and the backend server. The backend can look for this header if it needs to know whether or not a request came from a known GRIP proxy. The JWT claim SHOULD contain anissfield as a hint for which key is being used (in case there are multiple possible keys). The JWT claim MUST contain anexpfield. If the token cannot be fully verified for any reason, including expiration, then the backend should behave as if the header wasn’t present.
When the backend responds to the request, it MAY specify instructions to the proxy about how to behave, such as the hold mode to use and any channels that should be associated with the request. Once the backend has responded, the transaction between the proxy and the backend is complete. However, the request between the client and the proxy remains open according to the instructions provided.
Instructions are provided via headers. The following response headers are defined:
Grip-Hold: The hold mode, eitherresponseorstream. This header MUST be present in order for the proxy to take GRIP-related action, otherwise it should behave normally (e.g. by relaying the response back to the client).Grip-Channel: A channel to subscribe the request to. MultipleGrip-Channelheaders may be specified in the response, to subscribe multiple channels to the request. At least oneGrip-Channelheader MUST be present ifGrip-Holdis present. This header type may include parameters. The only defined parameter isprev-id, which specifies the ID of data that was last published to the specified channel (used to avoid a race condition). Theprev-idparameter is OPTIONAL and only applies to theresponsemode.Grip-Timeout: The length of time the request should be held open before timing out. This header is OPTIONAL and only applies to theresponsemode. If omitted, the proxy SHOULD use a default of 55 seconds.Grip-Keep-Alive: Data to be sent to the client after a certain amount of activity passes. This header is OPTIONAL and only applies to thestreammode. This header type may include optional parameters. Defined parameters aretimeoutandformat. Thetimeoutparameter specifies the length of time a request must be idle before the keep alive data is sent. If omitted, the proxy SHOULD use a default of 55 seconds. Theformatparameter specifies the format of the keep alive data. Allowed values areraw,cstring, andbase64. If omitted,rawis assumed. For example, if a newline character should be sent to the client after 20 seconds of inactivity, the following header could be used:Grip-Keep-Alive: \n; format=cstring; timeout=20.
To publish data to any held open connections, http-response and/or http-streampayloads must be transmitted to the proxy using the Control Service. Examples:
"http-response": {
"code": int,
"status", str,
"headers": {
name: str,
...
},
"body": str,
"body-bin": base64 str
}
"http-stream": {
"content": str,
"content-bin": base64 str
}
WebSocket
The WebSocket GRIP transport allows a proxy to associate channels with WebSocket connections, so that data may be published to these connections.
When a client makes a WebSocket connection to the proxy, the proxy makes a WebSocket connection to the backend server. In this connection request, the proxy includes the grip extension in the Sec-WebSocket-Extensions header. The proxy SHOULD also include a Grip-Sig header as described in the HTTP section:
GET /websocket/path/ HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Grip-Sig: [... JWT ...]
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ=
Sec-WebSocket-Extensions: grip
...
The backend server then accepts the connection with the proxy by responding with status code 101. In order to enable GRIP functionality, the backend must include the grip extension in its response. If the backend does not include this extension, then the proxy MUST assume that the backend server is not GRIP capable and treat the session as a passthrough.
If the backend server provides the grip extension, then the proxy will know that the backend is GRIP capable and the backend may send special control messages to the proxy. In order to disambiguate control messages from normal messages, the backend denotes the type of message by including a prefix in the payload of the message. If the message spans multiple frames, then the prefix would be included in the first frame only. By default, the prefix for normal messages is m: and the prefix for control messages is c:. The proxy MUST strip off the prefix before relaying or processing.
The grip extension has an optional parameter called message-prefix that the backend server can use to override the prefix for normal messages. The backend can even specify a blank string for this value, to indicate that there should be no prefix at all. This can be useful if the backend speaks entirely in JSON, in which case there is no chance of conflict with control messages (a JSON payload would never begin with c:). For example:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Extensions: grip; message-prefix=""
...
Control messages are JSON format, encoded as an object with a type field indicating the type of control message. All other fields in the object are specific to the control message type. The following control messages are defined:
{ "type": "subscribe", "channel": "{channel}" }{ "type": "unsubscribe", "channel": "{channel}" }{ "type": "detach" }
Note that control messages are only ever sent by the backend server to the proxy. The proxy does not send control messages to the backend, and the client has no awareness of GRIP. The backend uses the subscribe and unsubscribe messages to control the GRIP channels that the client’s WebSocket connection is subscribed to.
The detach message is used to disconnect the backend from the proxy without the proxy disconnecting from the client. Once a connection is detached, any further messages the proxy receives from the client are dropped. Detached mode only makes sense if the connection has been subscribed to at least one channel and the client is not expected to send anything further. This is useful if the connection is used only for one-way transmission.
The backend server may publish data to the proxy using the ws-message format, transmitted to the proxy using the Control Service. Example:
"ws-message": {
"content": str,
"content-bin": base64 str
}
This format contains just one child field, content or content-bin, containing an entire message to be relayed to all clients subscribed to the channel being published to. The content field is a string containing a text message. The content-bin field is a string containing a binary message encoded in Base64.
Control Service
A GRIP proxy may be controlled via the Extensible Pubsub Control Protocol (EPCP). GRIP requires support for the publish endpoint, which is used to send items over HTTP or WebSocket connections that have been bound to channels.
EPCP defines a generalized and extensible way of publishing data through a publish-subscribe service using HTTP. A pubsub service offering an EPCP interface must make a REST API available at a known base URI. For example, if the base URI of the EPCP service is http://localhost:9000/epcp, then method endpoints would be appended onto that. For example, the publish endpoint would be available at http://localhost:9000/epcp/publish/.
Publishing
For example, a publish request may look like this:
POST /publish/ HTTP/1.1
Host: localhost:5561
Content-Type: application/json
{
"items": [
{
"channel": str,
"id": str,
"prev-id": str,
format_1: {},
format_2: {},
...
},
...
]
}
More than one item may be published in a single request. Each item may contain one or more formats by providing field names for each format along with their values. Item formats may be specified in further specifications. EPCP alone does not define any item formats. GRIP defines the following item formats: http-response (see HTTP), http-stream (see HTTP, and ws-message (see WebSocket).
Generic Realtime Intermediary Protocol的更多相关文章
- WebSocket-Over-HTTP Protocol
转自:https://pushpin.org/docs/protocols/websocket-over-http/ WebSocket-Over-HTTP Protocol The WebSocke ...
- RFC 2616
Network Working Group R. Fielding Request for Comments: 2616 UC Irvine Obsoletes: 2068 J. Gettys Cat ...
- RFC3261--sip
本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...
- RFC-RTSP
Network Working Group H. Schulzrinne Request for Comments: 2326 Columbia U. Category: Standards Trac ...
- RTSP Spectification
Refer: https://www.ietf.org/rfc/rfc2326.txt Network Working Group H. SchulzrinneRequest for Comments ...
- wifi display代码 分析
转自:http://blog.csdn.net/lilian0118/article/details/23168531 这一章中我们来看Wifi Display连接过程的建立,包含P2P的部分和RTS ...
- A Study of WebRTC Security
转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...
- Cisco IOS Debug Command Reference I through L
debug iapp through debug ip ftp debug iapp : to begin debugging of IAPP operations(in privileged EXE ...
- H.264视频的RTP荷载格式
Status of This Memo This document specifies an Internet standards track protocol for the Internet ...
随机推荐
- 《Python》网络编程之客户端/服务端框架、套接字(socket)初使用
一.软件开发的机构 我们了解的涉及到两个程序之间通讯的应用大致可以分为两种: 第一种是应用类:QQ.微信.网盘等这一类是属于需要安装的桌面应用 第二种是web类:比如百度.知乎.博客园等使用浏览器访问 ...
- 深入理解java虚拟机---对象的结构(九)
注意: 我们可以看到的就是InstanceData的数据. 先转载一篇文章作为开头,因为讲的非常详细,我就简单加工下放到这里: 对象结构 在HotSpot虚拟机中,对象在内存中存储的布局可以分为3块区 ...
- Zabbix4.0监控URL
一:新建群组 1.1:web monitor 二:新建模板 2.1:配置-模板-模板 2.3:创建应用集 配置-模板-web monitor-应用集 2.4:创建web场景 2.5:创建场景步骤: 以 ...
- Zabbix4.0添加端口和进程监控
一:Zabbix设置主动模式: vim /etc/zabbix/zabbix_agent.conf Server=192.168.1.10 #被动模式的serverip地址,如果设置纯被动模式,可以注 ...
- idea没有错误出现红色波浪线怎么去掉?
在有波浪线的代码上Alt+Enter,弹出的菜单中第一项的子菜单选择disable inspection
- SharePoint Framework 企业向导(六)
博客地址:http://blog.csdn.net/FoxDave 接上一讲 部署SPFx解决方案 部署SPFx解决方案可以用两个步骤完成:1. 将脚本组件打成的包部署到一个CDN(内容分发网络) ...
- <Java><类与对象><OOP>
Overview 类 封装(encapsulation): 也称为数据隐藏.从形式上看,是将数据与行为组合起来,并对对象的使用者隐藏了数据的实现方式.封装给对象赋予了黑盒特征,提高重用性和可靠性. 继 ...
- mysql引擎事物支持
事务的特性事务具体四大特性,也就是经常说的ACID 1. 原子性(Atomicity) 原子性是指事务包含的所有操作要么全部成功,要么全部失败回滚,因此事务的操作如果成功就必须要完全应用到数据库,如果 ...
- 30行python让图灵机器人和茉莉机器人无止尽的瞎扯蛋
首先注册申请图灵机器人的API: http://www.tuling123.com/ 查看一下API的格式,很简单: { "key": "APIKEY", &q ...
- Java技术体系
Shell 解释型编程语言(脚本语言都是解释型语言) Shell通过解释器/bin/bash 解释,运行在进程中 Java 编译型解释型语言(先编译再解释) Java通过编译器转换成字节码语言,再用过 ...