camel-component-grpc
gRPC component for rust-camel (dynamic producer and consumer with streaming)
Overview
camel-component-grpc provides dynamic gRPC producer and consumer for rust-camel, using runtime proto resolution via prost-reflect. No compile-time code generation required — proto files are resolved at runtime through camel-proto-compiler. Supports unary, server streaming, client streaming, and bidirectional streaming — mode is auto-detected from the proto method descriptor.
Features
- gRPC Server (Consumer): Listen for incoming gRPC requests (unary, server streaming, client streaming, bidi)
- gRPC Client (Producer): Make outgoing gRPC calls (unary, server streaming, client streaming, bidi)
- Dynamic proto resolution: No codegen required at compile time
- JSON pipeline: Automatic protobuf ↔ JSON conversion
- StreamObserver API: Routes send streaming responses via
GrpcStreamObserver(on_next/on_error/on_completed) - Metadata propagation: gRPC metadata → Exchange headers (including binary
-binas base64) - Shared server: One HTTP/2 server per
(host, port), multiple consumers dispatch by path - Feature-gated behind
grpcfeature incamel-cli
Installation
Enable grpc in camel-cli:
= { = "*", = ["grpc"] }
URI Format
grpc://host:port/package.Service/Method?protoFile=path.proto
Parameters
| Parameter | Default | Description |
|---|---|---|
protoFile |
required | Path to .proto file |
reflection |
false | (v2) gRPC reflection |
tls |
false | (v2) TLS support |
deadline_ms |
none | Request deadline |
metadata |
none | Static metadata headers |
Usage
gRPC Server (Consumer)
use RouteBuilder;
use GrpcComponent;
use CamelContext;
let mut ctx = new;
ctx.register_component;
// Listen for gRPC requests, echo response
let route = from
.set_body
.build?;
The consumer:
- Starts an HTTP/2 server on the specified host:port
- Dispatches requests by gRPC path (
/package.Service/Method) - Decodes protobuf → JSON, sends through the pipeline
- Encodes the pipeline response JSON → protobuf
gRPC Client (Producer)
// Timer-triggered gRPC calls
let route = from
.set_body
.to
.to
.build?;
Shared Server
Multiple consumers on the same (host, port) share one HTTP/2 server. Each consumer registers a unique gRPC path:
let route1 = from
.set_body
.build?;
let route2 = from
.set_body
.build?;
Exchange Headers
gRPC Metadata → Exchange Headers (Consumer)
gRPC metadata is forwarded to exchange headers. Binary metadata (keys ending in -bin) is base64-encoded with a bin: prefix.
Streaming
Streaming mode is auto-detected from the proto method descriptor. No configuration needed — if your proto defines a streaming method, the component handles it.
Consumer Streaming (Server Streaming)
Routes access GrpcStreamObserver to send streaming responses:
use take_stream_observer;
// In your route processor:
if let Some = take_stream_observer
Producer Streaming
- Server streaming: Send one request, receive JSON array of responses
- Client streaming: Send JSON array of requests, receive one response
- Bidi streaming: Send JSON array of requests, receive JSON array of responses
License
Apache-2.0