Connect
约 2 分钟阅读
标签:协议
- connect.build
- gRPC 竞品
- 兼容 gRPC, gRPC-Web 协议
- 支持 bi-streaming - 使用 gRPC 协议
- 支持 JSON- 和 binary-encoded Protobuf
- Connect 自身协议 - 基于 POST - application/connect+proto
- 支持 Stream - 一行一个请求,类似 SSE
- 协议和实现更简单
- 支持 HTTP1
- 目前支持 Go, Web, Node.js, Swift, Kotlin
- grpc: application/grpc, application/grpc+proto, application/grpc+json
- grpc-web: pplication/grpc-web, application/grpc-web+proto, application/grpc-web+json
- connect
- unary: application/proto, application/json
- striming: application/connect+proto, application/connect+json
- Python Implementation connectrpc/connectrpc.com#71GitHub PRconnectrpc/connectrpc.com#71
- 如果需要 REST / google.api.http 注解支持,可以使用 connectrpc/vanguard-goGitHubconnectrpc/vanguard-goconnectrpc/vanguard-go · Apache-2.0, Go, Connect, gRPC, REST · Vanguard 是一个用于 Go 服务器的库,支持在 REST、gRPC、gRPC-Web 和 Connect 协议之间进行无缝转码。笔记:Vanguard
brew install bufbuild/buf/bufAwesome
- Connect Protocol Reference
- connectrpc/vanguard-goGitHubconnectrpc/vanguard-goconnectrpc/vanguard-go · Apache-2.0, Go, Connect, gRPC, REST · Vanguard 是一个用于 Go 服务器的库,支持在 REST、gRPC、gRPC-Web 和 Connect 协议之间进行无缝转码。笔记:Vanguard
- Apache-2.0, Go
- Gateway
- REST, gRPC, gRPC-Web, and Connect
- bufbuild/protobuf-esGitHubbufbuild/protobuf-esbufbuild/protobuf-es · Apache-2.0, TS · protoc-gen-es · target - 默认为 js+dts · js - 生成 · ts - 生成 · dts - 生成 · importextension - import 的后缀笔记:protobuf-es
- JS PB 实现
- bufbuild/connect-crosstestGitHubbufbuild/connect-crosstest
- 兼容测试
- connectrpc/connect-esGitHubconnectrpc/connect-es
- npm:@connectrpc/connect-node
- 客户端、服务端
- 客户端
- npm:@connectrpc/connect-web
- 服务端
- npm:@connectrpc/connect-next
- npm:@connectrpc/connect-fastify
- npm:@connectrpc/connect-express
- npm:@connectrpc/connect-node
协议
POST /<Package>.<Service>/<Method>connect-es
- router =
{handlers,service(),rpc()}- handlers - universal handler
- 支持所有协议 - grpc, grpcWeb, connect
- 包含元信息
- service 注册整个 service
- rpc 注册一个方法
- handler = 协议协商 -> interceptor -> impl
- interceptor 无法访问当前的 impl
- invokeUnaryImplementation
const next = applyInterceptors(fn,interceptors)return message = next()
- handlers - universal handler
connect-web
- connectrpc/connect-esGitHubconnectrpc/connect-es
- @bufbuild/connect-web -> connectrpc/connect-es
- 16kB/5kB
npm install @bufbuild/protoc-gen-es @bufbuild/protoc-gen-connect-web
PATH=$PATH:$(pwd)/node_modules/.bin依赖包@bufbuild/protoc-gen-esnpm 包@bufbuild/protoc-gen-esNPM@bufbuild/protoc-gen-connect-webnpm 包@bufbuild/protoc-gen-connect-webNPM
connect-go
bufbuild/connect-goGitHubbufbuild/connect-go- 使用 net/http
- 生成使用泛型
- 🌟 Client 和 Server 接口相同 - 方便操作
- connectrpc/connect-goGitHubconnectrpc/connect-go
# 基于 POST 的 connect 协议
curl \
--header "Content-Type: application/json" \
--data '{"sentence": "I feel happy."}' \
https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say
# 兼容 gRPC 协议
grpcurl \
-d '{"sentence": "I feel happy."}' \
demo.connect.build:443 \
buf.connect.demo.eliza.v1.ElizaService/Saygo install github.com/bufbuild/buf/cmd/buf@latest
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@latest
go install github.com/bufbuild/protobuf-es/cmd/protoc-gen-es@latest依赖包github.com/bufbuild/buf/cmd/bufGo 包github.com/bufbuild/buf/cmd/bufGogithub.com/fullstorydev/grpcurl/cmd/grpcurlGo 包github.com/fullstorydev/grpcurl/cmd/grpcurlGogoogle.golang.org/protobuf/cmd/protoc-gen-goGo 包google.golang.org/protobuf/cmd/protoc-gen-goGogithub.com/bufbuild/connect-go/cmd/protoc-gen-connect-goGo 包github.com/bufbuild/connect-go/cmd/protoc-gen-connect-goGogithub.com/bufbuild/protobuf-es/cmd/protoc-gen-esGo 包github.com/bufbuild/protobuf-es/cmd/protoc-gen-esGo
version: v1
plugins:
- name: go
out: gen
opt: paths=source_relative
- name: connect-go
out: gen
opt: paths=source_relative实现
- Handler - 当个 RPC 方法处理
- 实现 Connect, gRPC, gRPC-Web 协议
- 提供 ServeHTTP
- 构造
- NewBidiStreamHandler
- NewClientStreamHandler
- NewServerStreamHandler
- NewUnaryHandler
Why Connect
- gRPC 因为考虑 Google 内部使用和开源社区使用,一些设计上很乱很奇怪
- gRPC 小版本也可能不出现兼容
- gRPC 在 Web 环境非常麻烦
- 要求 HTTP/2 Trailer - 对使用环境、实现要求苛刻
- vs golang grpc
- 不兼容 net/http
- 实现复杂
关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- API Awesome笔记 · connect
灵活 · 静态结构 · 动态结构 · 兼容性 · 性能 · 延时要求 · 服务对服务 · 服务对客户端 · 序列化 · 二进制 · 文本 - JSON · 语言兼容 · 需要支持什么语言 · 自用只需考虑个别语言 · 对外则需要考虑通用 · 接口模式
- protobuf-es笔记 · Connect
bufbuild/protobuf-es · Apache-2.0, TS · protoc-gen-es · target - 默认为 js+dts · js - 生成 · ts - 生成 · dts - 生成 · importextension - import 的后缀
参考资料
GitHub9 条
- connectrpc/connect-esgithub.com/connectrpc/connect-es
- connectrpc/vanguard-gogithub.com/connectrpc/vanguard-go
- bufbuild/connect-crosstestgithub.com/bufbuild/connect-crosstest
- bufbuild/connect-gogithub.com/bufbuild/connect-go
- bufbuild/protobuf-esgithub.com/bufbuild/protobuf-es
- connectrpc/connect-gogithub.com/connectrpc/connect-go
- connectrpc/connectrpc.com#71github.com/connectrpc/connectrpc.com/pull/71
- i2y/connecpygithub.com/i2y/connecpy
- mattrobenolt/connect-pythongithub.com/mattrobenolt/connect-python
其他外链3 条
- buf.build/blog/connect-a-better-grpcbuf.build/blog/connect-a-better-grpc
- connect.buildconnect.build/
- connect.build/docs/protocolconnect.build/docs/protocol