improve log

This commit is contained in:
sheyanjie-qq 2024-08-12 19:05:01 +08:00
parent 0eba0ff308
commit edcc5f5b67
4 changed files with 29 additions and 28 deletions

View File

@ -61,7 +61,7 @@ async fn main() -> anyhow::Result<()> {
// ANCHOR: consume
match consumer.subscribe(["topic_meters"]).await{
Ok(_) => println!("subscribe topics successfully."),
Ok(_) => println!("Subscribe topics successfully."),
Err(err) => {
eprintln!("Failed to subscribe topic_meters, dsn: {}; ErrMessage: {}", dsn, err);
return Err(err.into());
@ -123,7 +123,7 @@ async fn main() -> anyhow::Result<()> {
}
// commit offset manually when you have processed the message.
match consumer.commit(offset).await{
Ok(_) => println!("commit offset manually successfully."),
Ok(_) => println!("Commit offset manually successfully."),
Err(err) => {
eprintln!("Failed to commit offset manually, dsn: {}; ErrMessage: {}", dsn, err);
return Err(err.into());
@ -140,7 +140,7 @@ async fn main() -> anyhow::Result<()> {
// ANCHOR: seek_offset
let assignments = consumer.assignments().await.unwrap();
println!("assignments: {:?}", assignments);
println!("Now assignments: {:?}", assignments);
// seek offset
for topic_vec_assignment in assignments {
@ -163,23 +163,24 @@ async fn main() -> anyhow::Result<()> {
match consumer.offset_seek(topic, vgroup_id, begin).await{
Ok(_) => (),
Err(err) => {
eprintln!("seek example failed; ErrMessage: {}", err);
eprintln!("Seek example failed; ErrMessage: {}", err);
return Err(err.into());
}
}
}
let topic_assignment = consumer.topic_assignment(topic).await;
println!("topic assignment: {:?}", topic_assignment);
println!("Topic assignment: {:?}", topic_assignment);
}
println!("assignment seek to beginning successfully.");
println!("Assignment seek to beginning successfully.");
// after seek offset
let assignments = consumer.assignments().await.unwrap();
println!("after seek offset assignments: {:?}", assignments);
println!("After seek offset assignments: {:?}", assignments);
// ANCHOR_END: seek_offset
// ANCHOR: unsubscribe
consumer.unsubscribe().await;
println!("Consumer unsubscribed successfully.");
// ANCHOR_END: unsubscribe
tokio::time::sleep(Duration::from_secs(1)).await;

View File

@ -172,15 +172,15 @@ async fn main() -> anyhow::Result<()> {
let topic_assignment = consumer.topic_assignment(topic).await;
println!("topic assignment: {:?}", topic_assignment);
}
println!("assignment seek to beginning successfully.");
println!("Assignment seek to beginning successfully.");
// after seek offset
let assignments = consumer.assignments().await.unwrap();
println!("after seek offset assignments: {:?}", assignments);
println!("After seek offset assignments: {:?}", assignments);
// ANCHOR_END: seek_offset
// ANCHOR: unsubscribe
consumer.unsubscribe().await;
println!("consumer unsubscribed successfully.");
println!("Consumer unsubscribed successfully.");
// ANCHOR_END: unsubscribe
tokio::time::sleep(Duration::from_secs(1)).await;

View File

@ -59,7 +59,7 @@ public class ConsumerLoopFull {
// subscribe to the topics
consumer.subscribe(topics);
System.out.println("subscribe topics successfully.");
System.out.println("Subscribe topics successfully.");
for (int i = 0; i < 50; i++) {
// poll data
ConsumerRecords<ResultBean> records = consumer.poll(Duration.ofMillis(100));
@ -88,9 +88,9 @@ public class ConsumerLoopFull {
// subscribe to the topics
consumer.subscribe(topics);
System.out.println("subscribe topics successfully.");
System.out.println("Subscribe topics successfully.");
Set<TopicPartition> assignment = consumer.assignment();
System.out.println("now assignment: " + JSON.toJSONString(assignment));
System.out.println("Now assignment: " + JSON.toJSONString(assignment));
ConsumerRecords<ResultBean> records = ConsumerRecords.emptyRecord();
// make sure we have got some data
@ -99,13 +99,13 @@ public class ConsumerLoopFull {
}
consumer.seekToBeginning(assignment);
System.out.println("assignment seek to beginning successfully.");
System.out.println("Assignment seek to beginning successfully.");
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("seek example failed; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
System.out.println("Seek example failed; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
throw new SQLException("seek example failed", ex);
} catch (Exception ex) {
System.out.println("seek example failed; ErrMessage: " + ex.getMessage());
System.out.println("Seek example failed; ErrMessage: " + ex.getMessage());
throw new SQLException("seek example failed", ex);
}
// ANCHOR_END: consumer_seek
@ -128,7 +128,7 @@ public class ConsumerLoopFull {
if (!records.isEmpty()) {
// after processing the data, commit the offset manually
consumer.commitSync();
System.out.println("commit offset manually successfully.");
System.out.println("Commit offset manually successfully.");
}
}
} catch (SQLException ex) {
@ -149,7 +149,7 @@ public class ConsumerLoopFull {
try {
// unsubscribe the consumer
consumer.unsubscribe();
System.out.println("consumer unsubscribed successfully.");
System.out.println("Consumer unsubscribed successfully.");
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("Failed to unsubscribe consumer. ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
@ -161,7 +161,7 @@ public class ConsumerLoopFull {
finally {
// close the consumer
consumer.close();
System.out.println("consumer closed successfully.");
System.out.println("Consumer closed successfully.");
}
// ANCHOR_END: unsubscribe_data_code_piece
}

View File

@ -57,7 +57,7 @@ public class WsConsumerLoopFull {
// subscribe to the topics
consumer.subscribe(topics);
System.out.println("subscribe topics successfully.");
System.out.println("Subscribe topics successfully.");
for (int i = 0; i < 50; i++) {
// poll data
ConsumerRecords<ResultBean> records = consumer.poll(Duration.ofMillis(100));
@ -86,9 +86,9 @@ public class WsConsumerLoopFull {
// subscribe to the topics
consumer.subscribe(topics);
System.out.println("subscribe topics successfully.");
System.out.println("Subscribe topics successfully.");
Set<TopicPartition> assignment = consumer.assignment();
System.out.println("now assignment: " + JSON.toJSONString(assignment));
System.out.println("Now assignment: " + JSON.toJSONString(assignment));
ConsumerRecords<ResultBean> records = ConsumerRecords.emptyRecord();
// make sure we have got some data
@ -97,13 +97,13 @@ public class WsConsumerLoopFull {
}
consumer.seekToBeginning(assignment);
System.out.println("assignment seek to beginning successfully.");
System.out.println("Assignment seek to beginning successfully.");
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("seek example failed; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
System.out.println("Seek example failed; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
throw new SQLException("seek example failed", ex);
} catch (Exception ex) {
System.out.println("seek example failed; ErrMessage: " + ex.getMessage());
System.out.println("Seek example failed; ErrMessage: " + ex.getMessage());
throw new SQLException("seek example failed", ex);
}
// ANCHOR_END: consumer_seek
@ -126,7 +126,7 @@ public class WsConsumerLoopFull {
if (!records.isEmpty()) {
// after processing the data, commit the offset manually
consumer.commitSync();
System.out.println("commit offset manually successfully.");
System.out.println("Commit offset manually successfully.");
}
}
} catch (SQLException ex) {
@ -147,7 +147,7 @@ public class WsConsumerLoopFull {
try {
// unsubscribe the consumer
consumer.unsubscribe();
System.out.println("consumer unsubscribed successfully.");
System.out.println("Consumer unsubscribed successfully.");
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("Failed to unsubscribe consumer. ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
@ -159,7 +159,7 @@ public class WsConsumerLoopFull {
finally {
// close the consumer
consumer.close();
System.out.println("consumer closed successfully.");
System.out.println("Consumer closed successfully.");
}
// ANCHOR_END: unsubscribe_data_code_piece
}