|
| 1 | +# CLAUDE.md - volo-grpc |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +`volo-grpc` is the gRPC implementation of the Volo framework, providing async gRPC client and server based on HTTP/2 (hyper). Supports unary, client streaming, server streaming, and bidirectional streaming calls with gzip/zlib/zstd compression, gRPC-Web, and TLS. |
| 6 | + |
| 7 | +**Documentation:** https://docs.rs/volo-grpc |
| 8 | + |
| 9 | +## Directory Structure |
| 10 | + |
| 11 | +``` |
| 12 | +volo-grpc/src/ |
| 13 | +├── lib.rs # Public API exports |
| 14 | +├── body.rs # BoxBody type |
| 15 | +├── codegen.rs # Code generation helpers |
| 16 | +├── context.rs # ClientContext, ServerContext (RpcInfo, stats, extensions) |
| 17 | +├── message.rs # RecvEntryMessage, SendEntryMessage traits (prost::Message) |
| 18 | +├── request.rs # Request<T> wrapper (metadata + message/Streaming) |
| 19 | +├── response.rs # Response<T> wrapper (metadata + message/Streaming) |
| 20 | +├── status.rs # gRPC Status (code, message, details, metadata) and Code enum |
| 21 | +├── tracing.rs # Span provider |
| 22 | +├── client/ # ClientBuilder, Client ("clone and use" pattern) |
| 23 | +│ ├── callopt.rs # Per-call options (CallOpt) |
| 24 | +│ ├── dns.rs # DNS resolution |
| 25 | +│ ├── meta.rs # MetaService (metadata handling) |
| 26 | +│ └── layer/timeout.rs |
| 27 | +├── server/ # Server, Router, ServiceBuilder, NamedService |
| 28 | +│ ├── router.rs # Multi-service routing |
| 29 | +│ ├── service.rs # ServiceBuilder::new(svc).build() |
| 30 | +│ ├── incoming.rs # Connection acceptance |
| 31 | +│ ├── meta.rs # MetaService |
| 32 | +│ └── layer/timeout.rs |
| 33 | +├── codec/ # Codec trait, encode/decode, compression (gzip/zlib/zstd) |
| 34 | +├── metadata/ # MetadataMap, MetadataKey, MetadataValue (binary keys use `-bin` suffix) |
| 35 | +├── layer/ # Shared layers: loadbalance, grpc_timeout, grpc_web, user_agent, CORS |
| 36 | +└── transport/ # Client transport, connection, TLS config |
| 37 | +``` |
| 38 | + |
| 39 | +## Key Components |
| 40 | + |
| 41 | +**Client** -- `ClientBuilder` configures: `rpc_timeout`, `connect_timeout`, `discover`, `load_balance`, `layer`/`layer_front`, `compression`. |
| 42 | + |
| 43 | +**Server** -- Built on hyper HTTP/2. Methods: `add_service`, `layer`/`layer_front`/`layer_tower`, `run`/`run_with_shutdown`, `tls_config`, plus HTTP/2 tuning options. |
| 44 | + |
| 45 | +**Router** -- Supports multiple gRPC services via `add_service`: |
| 46 | + |
| 47 | +```rust |
| 48 | +Server::new() |
| 49 | + .add_service(ServiceBuilder::new(service_a).build()) |
| 50 | + .add_service(ServiceBuilder::new(service_b).build()) |
| 51 | + .run(addr).await?; |
| 52 | +``` |
| 53 | + |
| 54 | +**NamedService** -- Services implement this trait (provides `const NAME`) for routing. |
| 55 | + |
| 56 | +**Codec** -- Encoder/Decoder abstraction. Compression: gzip and zlib enabled by default, zstd optional. |
| 57 | + |
| 58 | +**Metadata** -- `MetadataMap` stores key-value pairs. Binary keys use `-bin` suffix. |
| 59 | + |
| 60 | +## Feature Flags |
| 61 | + |
| 62 | +| Feature | Description | |
| 63 | +| --------------------- | ------------------------ | |
| 64 | +| `default` | Enables gzip and zlib | |
| 65 | +| `gzip` | gzip compression | |
| 66 | +| `zlib` | zlib compression | |
| 67 | +| `zstd` | zstd compression | |
| 68 | +| `compress` | Compression base support | |
| 69 | +| `rustls` | Rustls TLS | |
| 70 | +| `native-tls` | Native TLS | |
| 71 | +| `native-tls-vendored` | Vendored Native TLS | |
| 72 | +| `grpc-web` | gRPC-Web support | |
| 73 | + |
| 74 | +## HTTP/2 Configuration Options |
| 75 | + |
| 76 | +Server HTTP/2 settings: |
| 77 | + |
| 78 | +- `http2_init_stream_window_size` / `http2_init_connection_window_size` (default 1MB) |
| 79 | +- `http2_adaptive_window` |
| 80 | +- `http2_max_concurrent_streams` |
| 81 | +- `http2_keepalive_interval` / `http2_keepalive_timeout` (default 20s) |
| 82 | +- `http2_max_frame_size` |
| 83 | +- `http2_max_send_buf_size` |
| 84 | +- `http2_max_header_list_size` (default 16MB) |
| 85 | +- `accept_http1`: Accept HTTP/1 (required for gRPC-Web) |
| 86 | + |
| 87 | +## Notes |
| 88 | + |
| 89 | +1. **Users should not use volo-grpc directly**: Use code generated by `volo-build` |
| 90 | +2. **gRPC-Web requires additional configuration**: Enable `grpc-web` feature and set `accept_http1(true)` |
| 91 | +3. **Compression is optional**: gzip and zlib enabled by default, zstd requires manual enabling |
| 92 | +4. **TLS requires backend selection**: rustls or native-tls |
0 commit comments