-
Notifications
You must be signed in to change notification settings - Fork 9
Description
SDK
Rust
Description
The Rust SDK currently has a hard dependency on tonic::transport::Channel for gRPC communication. In the future when we have internal services written in Rust that want to ingest using Zerobus, they will use RAF (Rust Application Framework) for inter-process communication. RAF provides its own GrpcChannel — a tonic channel wrapped with tower middleware layers for context propagation, metrics, tracing, and health events (analogous to how Scala services use Armeria's GrpcChannel instead of raw gRPC-Java channels).
To support this, the SDK needs to allow swapping the underlying gRPC channel implementation without breaking the existing OSS API.
Proposed Solution
One potential solution:
- Make the SDK generic over the channel type — Replace
ZerobusClient<Channel>withZerobusClient<C>whereC: GrpcService<BoxBody> + Clone + Send + Sync + 'static, usingC = Channelas the default so existing usage is unaffected. - Extract a
ChannelFactorytrait — Move channel construction (Endpoint::from_shared,.connect_lazy(), TLS, proxy setup) behind a trait. ProvideTonicChannelFactoryas the default OSS implementation. Internal consumers provide their own factory (e.g. wrapping RAF'sGrpcChannelwithClientConfig). - Feature-gate the
tonictransport — PutTonicChannelFactoryand directtonictransport code behind atonic-transportfeature (enabled by default). Internal consumers can disable this feature and supply their own channel factory.
No breaking changes — the default type parameter and default feature flag preserve full backwards compatibility for OSS users.
Additional Context
- RAF's
GrpcChannelalready satisfiestonic::client::GrpcService<BoxBody>since it's a tower layer stack on top oftonicChannel, soZerobusClient<GrpcChannel>works without additional adaptation. - The
HeadersProvidertrait for auth/header injection can coexist with RAF'sCtxPropagationLayer; internal consumers would likely skip custom header injection and let RAF's middleware handle it. - The Arrow Flight experimental path (
arrow_stream.rs) has similar coupling and would benefit from the same treatment if needed later.