Skip to main content

DanubeClientBuilder

Struct DanubeClientBuilder 

Source
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 the DanubeClient.
  • 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

Source

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.
Source

pub fn with_tls(self, ca_cert: impl AsRef<Path>) -> Result<Self>

Sets the TLS configuration for the client in the builder.

Source

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.

Source

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.

Source

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?;
Source

pub 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

Deprecated: Use with_token() instead. This method treats the input as a JWT token.

Source

pub fn with_internal_broker(self, broker_name: impl Into<String>) -> Self

Sets the internal broker identity for the client in the builder.

Source

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 of DanubeClient configured with the specified options.
  • Err(e): An error if the configuration is invalid or incomplete.

Trait Implementations§

Source§

impl Clone for DanubeClientBuilder

Source§

fn clone(&self) -> DanubeClientBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DanubeClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DanubeClientBuilder

Source§

fn default() -> DanubeClientBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more