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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +57 -21
  3. data/docs/design.md +245 -52
  4. data/docs/development.md +102 -14
  5. data/docs/grpc-web.md +30 -13
  6. data/docs/grpc.md +98 -5
  7. data/docs/rbs.md +56 -19
  8. data/docs/streaming.md +80 -34
  9. data/docs/unary.md +269 -45
  10. data/lib/connectrpc/bindings/google_protobuf.rb +20 -7
  11. data/lib/connectrpc/client.rb +47 -22
  12. data/lib/connectrpc/deadline.rb +27 -6
  13. data/lib/connectrpc/error.rb +2 -2
  14. data/lib/connectrpc/generator/names.rb +17 -0
  15. data/lib/connectrpc/generator/rbs_renderer.rb +4 -3
  16. data/lib/connectrpc/generator/renderer.rb +35 -3
  17. data/lib/connectrpc/generator/runtime_names.rb +23 -5
  18. data/lib/connectrpc/generator/schema.rb +14 -7
  19. data/lib/connectrpc/grpc.rb +7 -4
  20. data/lib/connectrpc/grpc_client.rb +2 -2
  21. data/lib/connectrpc/grpc_server.rb +14 -14
  22. data/lib/connectrpc/grpc_web_cors.rb +12 -4
  23. data/lib/connectrpc/grpc_web_server.rb +19 -13
  24. data/lib/connectrpc/instrumentation.rb +47 -7
  25. data/lib/connectrpc/keepalive.rb +40 -0
  26. data/lib/connectrpc/method.rb +8 -8
  27. data/lib/connectrpc/metrics/connection_observer.rb +46 -17
  28. data/lib/connectrpc/metrics/definitions.rb +6 -2
  29. data/lib/connectrpc/protocol.rb +64 -11
  30. data/lib/connectrpc/proxy.rb +425 -0
  31. data/lib/connectrpc/server.rb +97 -13
  32. data/lib/connectrpc/streaming/client.rb +22 -25
  33. data/lib/connectrpc/streaming/client_execution.rb +2 -1
  34. data/lib/connectrpc/streaming/client_scope.rb +14 -7
  35. data/lib/connectrpc/streaming/server.rb +1 -0
  36. data/lib/connectrpc/streaming/server_terminal.rb +57 -14
  37. data/lib/connectrpc/streaming/session_messages.rb +12 -5
  38. data/lib/connectrpc/streaming/streams.rb +17 -6
  39. data/lib/connectrpc/streaming/terminal.rb +3 -5
  40. data/lib/connectrpc/transports/net_http.rb +512 -52
  41. data/lib/connectrpc/version.rb +1 -1
  42. data/lib/connectrpc.rb +1 -0
  43. data/sig/connectrpc.rbs +63 -17
  44. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b63f38115a064ea34b17947232b4945c5600007ba7e8406b84fe4f4f68a2dcc
4
- data.tar.gz: ec4b544f0f1b22bcd293e14cf58f3d70dd4da8fc5a6d2c112e715943413f8aa8
3
+ metadata.gz: 2b774d664edbbc8a045dcb2f84206ffdde6df1d2e69f9aeea39553c8470531e1
4
+ data.tar.gz: 20f8c2adf51517cf1ca5b82d1460a306416d2105c3a18cd310a6d2dadee9e189
5
5
  SHA512:
6
- metadata.gz: 669ed068fcaf1b7aceacd5b8836ef0e4d50a73a5aa152e0befe07c353d9d5718a4747ae9378159f83b592e7141865c06d53073d0b1eab861c4f6fa974db6694c
7
- data.tar.gz: 43f890664e92326a1237e976fc5a33a89ec164339ff9e6e12b2029731ec2e4ebbb3060a02ba12a6e423e7abe76973a54681314d85a0a2e1e5641bf385f4e49e4
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.2.0"
60
- gem "connectrpc-rack", "~> 0.2.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
- service = Greet::V1::GreetService
107
- greet = lambda do |request, _context|
108
- Greet::V1::GreetResponse.new(greeting: "Hello, #{request.name}!")
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
- binding: ConnectRPC::Bindings::GoogleProtobuf.new,
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 `cancellation:`.
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, TCP or verified TLS | No |
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
- - Client and bidi streaming from ordinary threads are not implemented yet; see
218
- [issue #29](https://github.com/jimeh/connectrpc-ruby/issues/29).
219
- `ThreadedTransport` covers unary and server streaming, for Connect and
220
- native gRPC.
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 policy, even
223
- without an RPC deadline. See the [streaming guide](docs/streaming.md).
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 |