Trait rdkafka::client::ClientContext

source ·
pub trait ClientContext: Send + Sync {
    const ENABLE_REFRESH_OAUTH_TOKEN: bool = false;

    // Provided methods
    fn log(&self, level: RDKafkaLogLevel, fac: &str, log_message: &str) { ... }
    fn stats(&self, statistics: Statistics) { ... }
    fn stats_raw(&self, statistics: &[u8]) { ... }
    fn error(&self, error: KafkaError, reason: &str) { ... }
    fn resolve_broker_addr(
        &self,
        host: &str,
        port: u16,
    ) -> Result<Vec<SocketAddr>, Error> { ... }
    fn generate_oauth_token(
        &self,
        _oauthbearer_config: Option<&str>,
    ) -> Result<OAuthToken, Box<dyn Error>> { ... }
}
Expand description

Client-level context.

Each client (consumers and producers included) has a context object that can be used to customize its behavior. Implementing ClientContext enables the customization of methods common to all clients, while ProducerContext and ConsumerContext are specific to producers and consumers. Refer to the list of methods to see which callbacks can currently be overridden.

Important: implementations of ClientContext must be thread safe, as they might be shared between multiple threads.

Provided Associated Constants§

source

const ENABLE_REFRESH_OAUTH_TOKEN: bool = false

Whether to periodically refresh the SASL OAUTHBEARER token by calling ClientContext::generate_oauth_token.

If disabled, librdkafka’s default token refresh callback is used instead.

This parameter is only relevant when using the OAUTHBEARER SASL mechanism.

Provided Methods§

source

fn log(&self, level: RDKafkaLogLevel, fac: &str, log_message: &str)

Receives log lines from librdkafka.

The default implementation forwards the log lines to the appropriate log crate macro. Consult the RDKafkaLogLevel documentation for details about the log level mapping.

source

fn stats(&self, statistics: Statistics)

Receives the decoded statistics of the librdkafka client. To enable, the statistics.interval.ms configuration parameter must be specified.

The default implementation logs the statistics at the info log level.

source

fn stats_raw(&self, statistics: &[u8])

Receives the JSON-encoded statistics of the librdkafka client. To enable, the statistics.interval.ms configuration parameter must be specified.

The default implementation calls ClientContext::stats with the decoded statistics, logging an error if the decoding fails.

source

fn error(&self, error: KafkaError, reason: &str)

Receives global errors from the librdkafka client.

The default implementation logs the error at the error log level.

source

fn resolve_broker_addr( &self, host: &str, port: u16, ) -> Result<Vec<SocketAddr>, Error>

Performs DNS resolution on a broker address.

This method is invoked by librdkafka to translate a broker hostname and port to a socket address.

The default implementation uses [std::net::ToSocketAddr].

source

fn generate_oauth_token( &self, _oauthbearer_config: Option<&str>, ) -> Result<OAuthToken, Box<dyn Error>>

Generates an OAuth token from the provided configuration.

Override with an appropriate implementation when using the OAUTHBEARER SASL authentication mechanism. For this method to be called, you must also set ClientContext::ENABLE_REFRESH_OAUTH_TOKEN to true.

The fmt::Display implementation of the returned error must not generate a message with an embedded null character.

The default implementation always returns an error and is meant to be overridden.

Object Safety§

This trait is not object safe.

Implementors§