connectrpc 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +57 -21
- data/docs/design.md +245 -52
- data/docs/development.md +102 -14
- data/docs/grpc-web.md +30 -13
- data/docs/grpc.md +98 -5
- data/docs/rbs.md +56 -19
- data/docs/streaming.md +80 -34
- data/docs/unary.md +269 -45
- data/lib/connectrpc/bindings/google_protobuf.rb +20 -7
- data/lib/connectrpc/client.rb +47 -22
- data/lib/connectrpc/deadline.rb +27 -6
- data/lib/connectrpc/error.rb +2 -2
- data/lib/connectrpc/generator/names.rb +17 -0
- data/lib/connectrpc/generator/rbs_renderer.rb +4 -3
- data/lib/connectrpc/generator/renderer.rb +35 -3
- data/lib/connectrpc/generator/runtime_names.rb +23 -5
- data/lib/connectrpc/generator/schema.rb +14 -7
- data/lib/connectrpc/grpc.rb +7 -4
- data/lib/connectrpc/grpc_client.rb +2 -2
- data/lib/connectrpc/grpc_server.rb +14 -14
- data/lib/connectrpc/grpc_web_cors.rb +12 -4
- data/lib/connectrpc/grpc_web_server.rb +19 -13
- data/lib/connectrpc/instrumentation.rb +47 -7
- data/lib/connectrpc/keepalive.rb +40 -0
- data/lib/connectrpc/method.rb +8 -8
- data/lib/connectrpc/metrics/connection_observer.rb +46 -17
- data/lib/connectrpc/metrics/definitions.rb +6 -2
- data/lib/connectrpc/protocol.rb +64 -11
- data/lib/connectrpc/proxy.rb +425 -0
- data/lib/connectrpc/server.rb +97 -13
- data/lib/connectrpc/streaming/client.rb +22 -25
- data/lib/connectrpc/streaming/client_execution.rb +2 -1
- data/lib/connectrpc/streaming/client_scope.rb +14 -7
- data/lib/connectrpc/streaming/server.rb +1 -0
- data/lib/connectrpc/streaming/server_terminal.rb +57 -14
- data/lib/connectrpc/streaming/session_messages.rb +12 -5
- data/lib/connectrpc/streaming/streams.rb +17 -6
- data/lib/connectrpc/streaming/terminal.rb +3 -5
- data/lib/connectrpc/transports/net_http.rb +512 -52
- data/lib/connectrpc/version.rb +1 -1
- data/lib/connectrpc.rb +1 -0
- data/sig/connectrpc.rbs +63 -17
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b774d664edbbc8a045dcb2f84206ffdde6df1d2e69f9aeea39553c8470531e1
|
|
4
|
+
data.tar.gz: 20f8c2adf51517cf1ca5b82d1460a306416d2105c3a18cd310a6d2dadee9e189
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec46f318678de30fd59ddee620c1b366c629b09d545b7f76342adc2f9d9af8f1457e2ef15cf1d800c2cca9307f8fd03362d6ebcd49b89f267d8b5171a89e7de2
|
|
7
|
+
data.tar.gz: 96e389d925fc56a24c391872bad3dbc685c408cad5a991b7f3a3fe86809162bccc81859edcb75190c243f25cc8bb884dd36c001763d62e9d8fafb1f000f16389
|
data/README.md
CHANGED
|
@@ -56,8 +56,8 @@ verifies with protoc 36.2.
|
|
|
56
56
|
Rack server to your Gemfile, then run `bundle install`:
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
|
-
gem "connectrpc", "~> 0.
|
|
60
|
-
gem "connectrpc-rack", "~> 0.
|
|
59
|
+
gem "connectrpc", "~> 0.3.0"
|
|
60
|
+
gem "connectrpc-rack", "~> 0.3.0"
|
|
61
61
|
gem "google-protobuf", ">= 4.36.2", "< 5"
|
|
62
62
|
gem "rackup"
|
|
63
63
|
gem "webrick"
|
|
@@ -100,21 +100,28 @@ verifies with protoc 36.2.
|
|
|
100
100
|
```ruby
|
|
101
101
|
$LOAD_PATH.unshift(File.expand_path("lib", __dir__))
|
|
102
102
|
require "connectrpc/rack"
|
|
103
|
-
require "connectrpc/bindings/google_protobuf"
|
|
104
103
|
require "greet/v1/greet_connect"
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
class Greeter
|
|
106
|
+
def greet(request, _context)
|
|
107
|
+
Greet::V1::GreetResponse.new(greeting: "Hello, #{request.name}!")
|
|
108
|
+
end
|
|
109
109
|
end
|
|
110
|
+
|
|
111
|
+
service = Greet::V1::GreetService
|
|
110
112
|
server = ConnectRPC::Server.new(
|
|
111
113
|
services: [service::SERVICE],
|
|
112
|
-
|
|
113
|
-
handlers: service.handlers(greet: greet)
|
|
114
|
+
handlers: service.handlers_for(Greeter.new, strict: true)
|
|
114
115
|
)
|
|
115
116
|
run ConnectRPC::Rack.new(server: server)
|
|
116
117
|
```
|
|
117
118
|
|
|
119
|
+
Since 0.3.0, the generated file loads the Google protobuf binding, so the
|
|
120
|
+
Server and Client use it without a `binding:` argument, and
|
|
121
|
+
`handlers_for` maps each RPC to the object's method of the same snake-case
|
|
122
|
+
name. `service.handlers(greet: ->(request, context) { ... })` takes one
|
|
123
|
+
callable per RPC instead.
|
|
124
|
+
|
|
118
125
|
5. Start the server:
|
|
119
126
|
|
|
120
127
|
```sh
|
|
@@ -136,13 +143,9 @@ verifies with protoc 36.2.
|
|
|
136
143
|
```ruby
|
|
137
144
|
$LOAD_PATH.unshift(File.expand_path("lib", __dir__))
|
|
138
145
|
require "connectrpc"
|
|
139
|
-
require "connectrpc/bindings/google_protobuf"
|
|
140
146
|
require "greet/v1/greet_connect"
|
|
141
147
|
|
|
142
|
-
core = ConnectRPC::Client.new(
|
|
143
|
-
base_url: "http://127.0.0.1:9292",
|
|
144
|
-
binding: ConnectRPC::Bindings::GoogleProtobuf.new
|
|
145
|
-
)
|
|
148
|
+
core = ConnectRPC::Client.new(base_url: "http://127.0.0.1:9292")
|
|
146
149
|
client = Greet::V1::GreetService::Client.new(client: core)
|
|
147
150
|
response = client.greet(Greet::V1::GreetRequest.new(name: "Ruby"), timeout: 2)
|
|
148
151
|
puts response.message.greeting # => Hello, Ruby!
|
|
@@ -150,13 +153,18 @@ verifies with protoc 36.2.
|
|
|
150
153
|
|
|
151
154
|
The core client uses Net::HTTP and binary protobuf by default. Pass
|
|
152
155
|
`codec: :json` for JSON, or `transport:` to use another transport. Each call
|
|
153
|
-
accepts `metadata:`, `timeout:` (30 seconds by default) and
|
|
156
|
+
accepts `metadata:`, `timeout:` (30 seconds by default), `deadline:` and
|
|
157
|
+
`cancellation:`. Since 0.3.0, a handler that calls another service passes
|
|
158
|
+
`deadline: context.deadline` so the downstream call ends no later than its own.
|
|
154
159
|
Handlers raise `ConnectRPC::Error` to return a typed error code to the caller.
|
|
155
160
|
|
|
156
161
|
Next steps:
|
|
157
162
|
|
|
158
163
|
- The [unary guide](docs/unary.md) covers generation options, GET, gzip,
|
|
159
164
|
metadata, errors, limits, deadlines and cancellation.
|
|
165
|
+
- Unexpected handler exceptions reach the client only as a generic `internal`
|
|
166
|
+
error. Since 0.3.0, pass `on_error:` to the Server to log or report them;
|
|
167
|
+
see [errors](docs/unary.md#errors).
|
|
160
168
|
- The [runnable examples](examples/README.md) pair Rack, Rails, Async and
|
|
161
169
|
Falcon servers with Net::HTTP and Async clients, including mutual TLS.
|
|
162
170
|
- The [streaming guide](docs/streaming.md) covers server, client and
|
|
@@ -180,12 +188,30 @@ integrations you use:
|
|
|
180
188
|
| [`connectrpc-yabeda`](gems/connectrpc-yabeda/README.md) | You want the same metrics through Yabeda and any of its adapters | `connectrpc/yabeda` |
|
|
181
189
|
| [`connectrpc-health`](gems/connectrpc-health/README.md) | You want the standard `grpc.health.v1` service (Check, List and Watch) for Kubernetes probes, `grpc_health_probe` and load balancers | `connectrpc/health` |
|
|
182
190
|
| [`connectrpc-sentry`](gems/connectrpc-sentry/README.md) | You use the Sentry Ruby SDK and want one native Sentry transaction or span per RPC side, plus reports of unexpected handler exceptions | `connectrpc/sentry` |
|
|
191
|
+
| [`connectrpc-hyper`](gems/connectrpc-hyper/README.md) | Since 0.3.0: you want a pooled HTTP/2 client for any thread, with every call shape and native gRPC, without an Async reactor. A Rust extension, with prebuilt platform gems | `connectrpc/hyper` |
|
|
183
192
|
|
|
184
193
|
Use the same version of `connectrpc` and every ConnectRPC gem in an
|
|
185
194
|
application. Their `~>` dependency ranges allow patch versions to differ, but the
|
|
186
195
|
[support policy](docs/support.md#match-the-connectrpc-package-versions)
|
|
187
196
|
requires matching versions.
|
|
188
197
|
|
|
198
|
+
### Pick packages by scenario
|
|
199
|
+
|
|
200
|
+
Every scenario also needs `connectrpc`, and `google-protobuf` for generated
|
|
201
|
+
code. The [protocol and host matrix](#protocol-and-host-support) lists exactly
|
|
202
|
+
what each host and transport supports.
|
|
203
|
+
|
|
204
|
+
| Scenario | Add | How |
|
|
205
|
+
| --- | --- | --- |
|
|
206
|
+
| A Rails app serves RPCs | `connectrpc-on-rails` | [Rails controller usage](gems/connectrpc-on-rails/README.md#usage). Rails serves Connect and gRPC-Web unary only, not native gRPC or streaming. |
|
|
207
|
+
| Puma or Sidekiq calls a Go service (connect-go or grpc-go) | `connectrpc-async` | [`ThreadedTransport`](gems/connectrpc-async/README.md#ordinary-threads) from any thread, with `protocol: :grpc` for grpc-go. Core's Net::HTTP transport is enough for Connect unary calls to connect-go. Since 0.3.0, [`connectrpc-hyper`](gems/connectrpc-hyper/README.md#which-transport) covers every call shape from any thread. |
|
|
208
|
+
| You run a gRPC server | `connectrpc-async` | The [gRPC quick start](docs/grpc.md#quick-start) serves Connect and native gRPC from one Async `Host`. |
|
|
209
|
+
| Kubernetes health checks | `connectrpc-health`, plus `connectrpc-async` or `connectrpc-falcon` | [Health hosts](gems/connectrpc-health/README.md#hosts). Kubernetes `grpc:` probes need native gRPC over HTTP/2. |
|
|
210
|
+
| RPCs run next to a Rack or Rails app on Falcon | `connectrpc-falcon` | [Run a service](gems/connectrpc-falcon/README.md#run-a-service) with the app as the Rack fallback. |
|
|
211
|
+
| Browser clients call the server | The host's package | [gRPC-Web](docs/grpc-web.md) for grpc-web clients. Cross-origin Connect clients such as connect-es need [outer CORS middleware](docs/grpc-web.md#cors-and-rails). |
|
|
212
|
+
| Tests call handlers without sockets | `connectrpc-testing` | [Testing usage](gems/connectrpc-testing/README.md#usage). |
|
|
213
|
+
| You need traces, metrics or error reports | `connectrpc-otel`, `connectrpc-prometheus` or `connectrpc-yabeda`, `connectrpc-sentry` | Each package README, linked in the table above. |
|
|
214
|
+
|
|
189
215
|
## Protocol and host support
|
|
190
216
|
|
|
191
217
|
U means unary, SS server streaming, CS client streaming and bidi bidirectional
|
|
@@ -201,10 +227,11 @@ streaming. H1 is HTTP/1.1 and H2 is HTTP/2.
|
|
|
201
227
|
|
|
202
228
|
| Client transport | Connect | Native gRPC |
|
|
203
229
|
| --- | --- | --- |
|
|
204
|
-
| Net::HTTP (core default) | U over H1,
|
|
230
|
+
| Net::HTTP (core default) | U over H1, one connection per call (TCP, TLS, mTLS, HTTP proxies) | No |
|
|
205
231
|
| Async `Transport` | U/SS/CS/bidi over H2 (h2c, TLS, mTLS) | U/SS/CS/bidi |
|
|
206
232
|
| Async `ThreadedTransport` | U/SS over H2, callable from any thread | U/SS |
|
|
207
233
|
| Async `HTTP1Transport` | U/SS/CS over H1 (TCP, TLS, mTLS) | No |
|
|
234
|
+
| Hyper `Transport` (since 0.3.0) | U/SS/CS/bidi over H2 (h2c, TLS, mTLS), U/SS/CS over H1, from any thread | U/SS/CS/bidi |
|
|
208
235
|
|
|
209
236
|
Connect is the default protocol. Connect supports binary protobuf
|
|
210
237
|
(`application/proto`) and protobuf JSON (`application/json`), identity or
|
|
@@ -214,13 +241,16 @@ explicitly; there is no Ruby gRPC-Web client.
|
|
|
214
241
|
|
|
215
242
|
These limits apply across the matrix:
|
|
216
243
|
|
|
217
|
-
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
244
|
+
- connectrpc-async's `ThreadedTransport` covers unary and server streaming
|
|
245
|
+
from ordinary threads, for Connect and native gRPC; client and bidi
|
|
246
|
+
streaming there are tracked in
|
|
247
|
+
[issue #29](https://github.com/jimeh/connectrpc-ruby/issues/29). Since
|
|
248
|
+
0.3.0, connectrpc-hyper's `Transport` makes every call shape from any
|
|
249
|
+
thread.
|
|
221
250
|
- The standalone Async `Host` is H2-only. Falcon is the Ruby H1 streaming host.
|
|
222
|
-
- Native Connect streaming clients apply a one-second HTTP tail
|
|
223
|
-
without an RPC deadline. See the
|
|
251
|
+
- Native Connect streaming clients apply a provisional one-second HTTP tail
|
|
252
|
+
policy, even without an RPC deadline. See the
|
|
253
|
+
[streaming guide](docs/streaming.md).
|
|
224
254
|
- There is no H1 bidi, HTTP/3, protocol fallback or RPC replay. Faraday is
|
|
225
255
|
unsupported. The Async H2 `Transport` resends a Connect unary call once only
|
|
226
256
|
when the server provably never processed its stream; see
|
|
@@ -233,6 +263,11 @@ targets Ruby 3.4.12 and 4.0.9 on Linux x64.
|
|
|
233
263
|
|
|
234
264
|
## Documentation
|
|
235
265
|
|
|
266
|
+
Guides on `main` describe the next release. "Since X.Y.Z" marks a feature,
|
|
267
|
+
option or metric that older installs lack. To read the guides for an installed
|
|
268
|
+
version, browse the repository at its tag, such as
|
|
269
|
+
[`v0.2.1`](https://github.com/jimeh/connectrpc-ruby/tree/v0.2.1).
|
|
270
|
+
|
|
236
271
|
| Guide | Covers |
|
|
237
272
|
| --- | --- |
|
|
238
273
|
| [Unary RPC](docs/unary.md) | Code generation, manual declarations, GET, gzip, metadata, errors, limits, deadlines, cancellation and instrumentation |
|
|
@@ -241,6 +276,7 @@ targets Ruby 3.4.12 and 4.0.9 on Linux x64.
|
|
|
241
276
|
| [gRPC-Web](docs/grpc-web.md) | Server-side gRPC-Web, CORS and browser clients |
|
|
242
277
|
| [Signatures (RBS)](docs/rbs.md) | Shipped RBS signatures, generated `.rbs` files and Steep setup |
|
|
243
278
|
| [Support contract](docs/support.md) | Target 0.x protocol, host, platform and API compatibility |
|
|
279
|
+
| [Upgrading](docs/upgrading.md) | Migration notes for releases with breaking changes |
|
|
244
280
|
| [Design](docs/design.md) | Internal boundaries, wire behavior and extension seams |
|
|
245
281
|
| [Runnable examples](examples/README.md) | Two-terminal servers and clients for every host and transport |
|
|
246
282
|
| [Development](docs/development.md) | Setup, verification tiers, coverage, updates and PR guidance |
|