pub struct DanubeClientBuilder { /* private fields */ }Expand description
A builder for configuring and creating a DanubeClient instance.
The DanubeClientBuilder struct provides methods for setting various options needed to construct a DanubeClient. This includes configuring the base URI for the Danube service, connection settings.
§Fields
uri: The base URI for the Danube service. This is a required field and specifies the address of the service that the client will connect to. It is essential for constructing theDanubeClient.connection_options: Optional connection settings that define how the grpc client connects to the Danube service. These settings can include parameters such as timeouts, retries, and other connection-related configurations.
Implementations§
Source§impl DanubeClientBuilder
impl DanubeClientBuilder
Sourcepub fn service_url(self, url: impl Into<String>) -> Self
pub fn service_url(self, url: impl Into<String>) -> Self
Sets the base URI for the Danube service in the builder.
This method configures the base URI that the DanubeClient will use to connect to the Danube service. The base URI is a required parameter for establishing a connection and interacting with the service.
§Parameters
url: The base URI to use for connecting to the Danube service. The URI should include the protocol and address of the Danube service.
Sourcepub fn with_tls(self, ca_cert: impl AsRef<Path>) -> Result<Self>
pub fn with_tls(self, ca_cert: impl AsRef<Path>) -> Result<Self>
Sets the TLS configuration for the client in the builder.
Sourcepub fn with_mtls(
self,
ca_cert: impl AsRef<Path>,
client_cert: impl AsRef<Path>,
client_key: impl AsRef<Path>,
) -> Result<Self>
pub fn with_mtls( self, ca_cert: impl AsRef<Path>, client_cert: impl AsRef<Path>, client_key: impl AsRef<Path>, ) -> Result<Self>
Sets the mutual TLS configuration for the client in the builder.
Sourcepub fn with_token(self, token: impl Into<String>) -> Self
pub fn with_token(self, token: impl Into<String>) -> Self
Sets the authentication token (JWT) for the client.
Use danube-admin security tokens create to generate a token.
Automatically enables TLS. If no TLS config has been set via with_tls() or
with_mtls(), a default TLS config using system root certificates is applied.
For tokens that expire, consider with_token_supplier
instead, which allows runtime token refresh.
Sourcepub fn with_token_supplier(
self,
supplier: impl Fn() -> String + Send + Sync + 'static,
) -> Self
pub fn with_token_supplier( self, supplier: impl Fn() -> String + Send + Sync + 'static, ) -> Self
Sets a dynamic token supplier for the client.
The supplier function is called on every gRPC request to obtain the current token, enabling runtime token refresh without restarting the client. This is useful for:
- File-based tokens: Read from a file that is updated by infrastructure (e.g., K8s projected volumes, sidecar token refreshers)
- Environment-based tokens: Read from an environment variable
- Custom refresh logic: Implement your own token rotation
Automatically enables TLS (same as with_token).
§Examples
// Read token from a file on each request
let client = DanubeClient::builder()
.service_url("https://broker:6650")
.with_token_supplier(|| {
std::fs::read_to_string("/var/run/secrets/danube-token")
.unwrap_or_default()
.trim()
.to_string()
})
.build()
.await?;Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
👎Deprecated since 0.11.0: Use with_token() — Danube now uses JWT tokens instead of API keys
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Use with_token() — Danube now uses JWT tokens instead of API keys
Deprecated: Use with_token() instead. This method treats the input as a JWT token.
Sourcepub fn with_internal_broker(self, broker_name: impl Into<String>) -> Self
pub fn with_internal_broker(self, broker_name: impl Into<String>) -> Self
Sets the internal broker identity for the client in the builder.
Sourcepub async fn build(self) -> Result<DanubeClient>
pub async fn build(self) -> Result<DanubeClient>
Constructs and returns a DanubeClient instance based on the configuration specified in the builder.
This method finalizes the configuration and creates a new DanubeClient instance. It uses the settings and options that were configured using the DanubeClientBuilder methods.
§Returns
Ok(DanubeClient): A new instance ofDanubeClientconfigured with the specified options.Err(e): An error if the configuration is invalid or incomplete.
Trait Implementations§
Source§impl Clone for DanubeClientBuilder
impl Clone for DanubeClientBuilder
Source§fn clone(&self) -> DanubeClientBuilder
fn clone(&self) -> DanubeClientBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DanubeClientBuilder
impl Debug for DanubeClientBuilder
Source§impl Default for DanubeClientBuilder
impl Default for DanubeClientBuilder
Source§fn default() -> DanubeClientBuilder
fn default() -> DanubeClientBuilder
Auto Trait Implementations§
impl !RefUnwindSafe for DanubeClientBuilder
impl !UnwindSafe for DanubeClientBuilder
impl Freeze for DanubeClientBuilder
impl Send for DanubeClientBuilder
impl Sync for DanubeClientBuilder
impl Unpin for DanubeClientBuilder
impl UnsafeUnpin for DanubeClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request