Skip to content

Commit

Permalink
refine example
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao-su committed May 2, 2024
1 parent 4397a46 commit 2f8d22a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Rewritten in Rust from https://github.com/aws/aws-msk-iam-sasl-signer-go. Copyright RisingWave Labs. All Rights Reserved.
Rewritten in Rust from https://github.com/aws/aws-msk-iam-sasl-signer-go. Copyright RisingWave Labs. All Rights Reserved.
11 changes: 8 additions & 3 deletions examples/consumer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::thread;
use std::time::Duration;

use aws_config::Region;
use aws_msk_iam_sasl_signer_rs::generate_auth_token;
use rdkafka::client::OAuthToken;
use rdkafka::consumer::{Consumer, ConsumerContext, StreamConsumer};
use rdkafka::{ClientConfig, ClientContext, Message};
use tokio::runtime::Handle;
use tokio::time::timeout;
use tracing_subscriber;

const REGION: &str = "us-east-2";
Expand Down Expand Up @@ -35,9 +37,12 @@ impl ClientContext for IamConsumerContext {
let region = self.region.clone();
let handle = self.rt.clone();
let (token, expiration_time_ms) = {
let handle =
thread::spawn(move || handle.block_on(generate_auth_token(region.clone())));
handle.join().unwrap()?
let handle = thread::spawn(move || {
handle.block_on(async {
timeout(Duration::from_secs(10), generate_auth_token(region.clone())).await
})
});
handle.join().unwrap()??
};
Ok(OAuthToken {
token,
Expand Down

0 comments on commit 2f8d22a

Please sign in to comment.