Skip to content

Commit 8411393

Browse files
authored
[ISSUE #8096]♻️Replace legacy logger setup in root examples (#8097)
1 parent e799062 commit 8411393

19 files changed

Lines changed: 120 additions & 66 deletions

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rocketmq-client/examples/batch/callback_batch_producer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
2727
pub const TOPIC: &str = "TopicTest";
2828
pub const TAG: &str = "TagA";
2929

30-
#[allow(deprecated)]
3130
#[rocketmq::main]
3231
pub async fn main() -> RocketMQResult<()> {
33-
//init logger
34-
rocketmq_common::log::init_logger()?;
35-
32+
let telemetry_guard =
33+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
34+
.expect("telemetry logging bootstrap should initialize");
3635
// create a producer builder with default configuration
3736
let builder = DefaultMQProducer::builder();
3837

@@ -120,5 +119,10 @@ pub async fn main() -> RocketMQResult<()> {
120119
sleep(std::time::Duration::from_secs(6));
121120
let i = counter.load(std::sync::atomic::Ordering::SeqCst);
122121
println!("send message count: {}", i);
122+
telemetry_guard
123+
.shutdown()
124+
.into_result()
125+
.expect("telemetry logging shutdown should succeed");
126+
123127
Ok(())
124128
}

rocketmq-client/examples/batch/simple_batch_producer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
2222
pub const TOPIC: &str = "TopicTest";
2323
pub const TAG: &str = "TagA";
2424

25-
#[allow(deprecated)]
2625
#[rocketmq::main]
2726
pub async fn main() -> RocketMQResult<()> {
28-
//init logger
29-
rocketmq_common::log::init_logger()?;
30-
27+
let telemetry_guard =
28+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
29+
.expect("telemetry logging bootstrap should initialize");
3130
// create a producer builder with default configuration
3231
let builder = DefaultMQProducer::builder();
3332

@@ -59,5 +58,10 @@ pub async fn main() -> RocketMQResult<()> {
5958
];
6059
let send_result = producer.send_batch(messages).await?;
6160
println!("send result: {}", send_result);
61+
telemetry_guard
62+
.shutdown()
63+
.into_result()
64+
.expect("telemetry logging shutdown should succeed");
65+
6266
Ok(())
6367
}

rocketmq-client/examples/broadcast/push_consumer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ pub const TOPIC: &str = "TopicTest";
3333
//pub const SUB_EXPRESSION: &str = "TagA || TagC || TagD";
3434
pub const SUB_EXPRESSION: &str = "*";
3535

36-
#[allow(deprecated)]
3736
#[rocketmq::main]
3837
pub async fn main() -> RocketMQResult<()> {
39-
//init logger
40-
rocketmq_common::log::init_logger()?;
41-
38+
let telemetry_guard =
39+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
40+
.expect("telemetry logging bootstrap should initialize");
4241
// create a producer builder with default configuration
4342
let builder = DefaultMQPushConsumer::builder();
4443

@@ -52,6 +51,11 @@ pub async fn main() -> RocketMQResult<()> {
5251
consumer.register_message_listener_concurrently(MyMessageListener);
5352
consumer.start().await?;
5453
let _ = tokio::signal::ctrl_c().await;
54+
telemetry_guard
55+
.shutdown()
56+
.into_result()
57+
.expect("telemetry logging shutdown should succeed");
58+
5559
Ok(())
5660
}
5761

rocketmq-client/examples/consumer/pop_consumer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
3030
pub const TOPIC: &str = "TopicTest";
3131
pub const TAG: &str = "*";
3232

33-
#[allow(deprecated)]
3433
#[rocketmq::main]
3534
pub async fn main() -> RocketMQResult<()> {
36-
//init logger
37-
rocketmq_common::log::init_logger()?;
38-
35+
let telemetry_guard =
36+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
37+
.expect("telemetry logging bootstrap should initialize");
3938
// create a producer builder with default configuration
4039
let builder = DefaultMQPushConsumer::builder();
4140

@@ -49,6 +48,11 @@ pub async fn main() -> RocketMQResult<()> {
4948
consumer.register_message_listener_concurrently(MyMessageListener);
5049
consumer.start().await?;
5150
let _ = tokio::signal::ctrl_c().await;
51+
telemetry_guard
52+
.shutdown()
53+
.into_result()
54+
.expect("telemetry logging shutdown should succeed");
55+
5256
Ok(())
5357
}
5458

rocketmq-client/examples/ordermessage/ordermessage_consumer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
3737
pub const TOPIC: &str = "TopicTest";
3838
pub const TAG: &str = "*";
3939

40-
#[allow(deprecated)]
4140
#[rocketmq::main]
4241
pub async fn main() -> RocketMQResult<()> {
43-
//init logger
44-
rocketmq_common::log::init_logger()?;
45-
42+
let telemetry_guard =
43+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
44+
.expect("telemetry logging bootstrap should initialize");
4645
// create a producer builder with default configuration
4746
let builder = DefaultMQPushConsumer::builder();
4847

@@ -56,6 +55,11 @@ pub async fn main() -> RocketMQResult<()> {
5655
consumer.register_message_listener_orderly(MyMessageListener::new());
5756
consumer.start().await?;
5857
let _ = tokio::signal::ctrl_c().await;
58+
telemetry_guard
59+
.shutdown()
60+
.into_result()
61+
.expect("telemetry logging shutdown should succeed");
62+
5963
Ok(())
6064
}
6165

rocketmq-client/examples/ordermessage/ordermessage_producer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ pub const PRODUCER_GROUP: &str = "please_rename_unique_group_name";
2222
pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
2323
pub const TOPIC: &str = "TopicTest";
2424

25-
#[allow(deprecated)]
2625
#[rocketmq::main]
2726
pub async fn main() -> RocketMQResult<()> {
28-
//init logger
29-
rocketmq_common::log::init_logger()?;
30-
27+
let telemetry_guard =
28+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
29+
.expect("telemetry logging bootstrap should initialize");
3130
// create a producer builder with default configuration
3231
let builder = DefaultMQProducer::builder();
3332

@@ -65,5 +64,10 @@ pub async fn main() -> RocketMQResult<()> {
6564
}
6665
producer.shutdown().await;
6766

67+
telemetry_guard
68+
.shutdown()
69+
.into_result()
70+
.expect("telemetry logging shutdown should succeed");
71+
6872
Ok(())
6973
}

rocketmq-client/examples/quickstart/consumer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
3030
pub const TOPIC: &str = "TopicTest";
3131
pub const TAG: &str = "*";
3232

33-
#[allow(deprecated)]
3433
#[rocketmq::main]
3534
pub async fn main() -> RocketMQResult<()> {
36-
//init logger
37-
rocketmq_common::log::init_logger()?;
38-
35+
let telemetry_guard =
36+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
37+
.expect("telemetry logging bootstrap should initialize");
3938
// create a producer builder with default configuration
4039
let builder = DefaultMQPushConsumer::builder();
4140

@@ -47,6 +46,11 @@ pub async fn main() -> RocketMQResult<()> {
4746
consumer.register_message_listener_concurrently(MyMessageListener);
4847
consumer.start().await?;
4948
let _ = tokio::signal::ctrl_c().await;
49+
telemetry_guard
50+
.shutdown()
51+
.into_result()
52+
.expect("telemetry logging shutdown should succeed");
53+
5054
Ok(())
5155
}
5256

rocketmq-client/examples/quickstart/producer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
2323
pub const TOPIC: &str = "TopicTest";
2424
pub const TAG: &str = "TagA";
2525

26-
#[allow(deprecated)]
2726
#[rocketmq::main]
2827
pub async fn main() -> RocketMQResult<()> {
29-
//init logger
30-
rocketmq_common::log::init_logger()?;
31-
28+
let telemetry_guard =
29+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
30+
.expect("telemetry logging bootstrap should initialize");
3231
// create a producer builder with default configuration
3332
let builder = DefaultMQProducer::builder();
3433

@@ -51,5 +50,10 @@ pub async fn main() -> RocketMQResult<()> {
5150
}
5251
producer.shutdown().await;
5352

53+
telemetry_guard
54+
.shutdown()
55+
.into_result()
56+
.expect("telemetry logging shutdown should succeed");
57+
5458
Ok(())
5559
}

rocketmq-client/examples/rpc/request_callback_producer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ pub const DEFAULT_NAMESRVADDR: &str = "127.0.0.1:9876";
2323
pub const TOPIC: &str = "RequestTopic";
2424
pub const TAG: &str = "TagA";
2525

26-
#[allow(deprecated)]
2726
#[rocketmq::main]
2827
pub async fn main() -> RocketMQResult<()> {
29-
//init logger
30-
rocketmq_common::log::init_logger()?;
31-
28+
let telemetry_guard =
29+
rocketmq_observability::install_global(&rocketmq_observability::TelemetryBootstrapConfig::default())
30+
.expect("telemetry logging bootstrap should initialize");
3231
// create a producer builder with default configuration
3332
let builder = DefaultMQProducer::builder();
3433

@@ -58,5 +57,10 @@ pub async fn main() -> RocketMQResult<()> {
5857
let _ = rx.recv().await;
5958
producer.shutdown().await;
6059

60+
telemetry_guard
61+
.shutdown()
62+
.into_result()
63+
.expect("telemetry logging shutdown should succeed");
64+
6165
Ok(())
6266
}

0 commit comments

Comments
 (0)