Skip to content

Commit

Permalink
make ENABLE_REFRESH_OAUTH_TOKEN a function
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed May 7, 2024
1 parent cccdc33 commit cd29c14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion madsim-rdkafka/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-rdkafka"
version = "0.3.4+0.34.0"
version = "0.4.0+0.34.0"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "The rdkafka simulator on madsim."
Expand Down
4 changes: 3 additions & 1 deletion madsim-rdkafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Replace all `rdkafka` entries in your Cargo.toml:

```toml
[dependencies]
rdkafka = { version = "0.3", package = "madsim-rdkafka" }
rdkafka = { version = "0.4", package = "madsim-rdkafka" }
```

## API Modification
Expand Down Expand Up @@ -47,6 +47,8 @@ The following functions are modified to be `async`:

[^1]: wrapped in `tokio::task::spawn_blocking`

The associated constant `ClientContext::ENABLE_REFRESH_OAUTH_TOKEN` is changed to a function in order to make the trait object-safe.

## DNS Resolution

This crate has cherry-picked [a commit] from Materialize to support rewriting broker addresses.
Expand Down
8 changes: 5 additions & 3 deletions madsim-rdkafka/src/std/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ pub trait ClientContext: Send + Sync + 'static {
///
/// This parameter is only relevant when using the `OAUTHBEARER` SASL
/// mechanism.
const ENABLE_REFRESH_OAUTH_TOKEN: bool = false;
fn enable_refresh_oauth_token(&self) -> bool {
false
}

/// Receives log lines from librdkafka.
///
Expand Down Expand Up @@ -134,7 +136,7 @@ pub trait ClientContext: Send + Sync + 'static {
///
/// 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.
/// 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.
Expand Down Expand Up @@ -275,7 +277,7 @@ impl<C: ClientContext> Client<C> {
>,
);
}
if C::ENABLE_REFRESH_OAUTH_TOKEN {
if context.enable_refresh_oauth_token() {
unsafe {
rdsys::rd_kafka_conf_set_oauthbearer_token_refresh_cb(
native_config.ptr(),
Expand Down
4 changes: 3 additions & 1 deletion madsim-rdkafka/src/std/producer/future_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ pub type OwnedDeliveryResult = Result<(i32, i64), (KafkaError, OwnedMessage)>;

// Delegates all the methods calls to the wrapped context.
impl<C: ClientContext + 'static> ClientContext for FutureProducerContext<C> {
const ENABLE_REFRESH_OAUTH_TOKEN: bool = C::ENABLE_REFRESH_OAUTH_TOKEN;
fn enable_refresh_oauth_token(&self) -> bool {
self.wrapped_context.enable_refresh_oauth_token()
}

fn log(&self, level: RDKafkaLogLevel, fac: &str, log_message: &str) {
self.wrapped_context.log(level, fac, log_message);
Expand Down

0 comments on commit cd29c14

Please sign in to comment.