Skip to content

Commit 60e5757

Browse files
committed
This causes segmentation fault
Signed-off-by: Hanif Bin Ariffin <[email protected]>
1 parent 631c951 commit 60e5757

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ anyhow = "1.0.38"
3131
thiserror = "1.0.24"
3232
pin-utils = "0.1.0"
3333
async-stream = "0.3.0"
34+
tabwriter = "1.2.1"
3435

3536
[dev-dependencies]
3637
assert_cmd = "1"

src/modes/metadata.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use rdkafka::{
33
config::RDKafkaLogLevel,
44
consumer::{Consumer, StreamConsumer},
55
metadata::Metadata,
6-
ClientConfig,
6+
ClientConfig, TopicPartitionList,
77
};
88
use tabwriter::TabWriter;
99

10-
pub fn get_metadata(config: AppConfig) {
10+
pub fn get_metadata(_config: AppConfig) {
1111
let stream = ClientConfig::new()
1212
// .set("group.id", &config.metadata_kafka.group_id)
1313
// .set("bootstrap.servers", &config.metadata_kafka.brokers)
@@ -19,9 +19,21 @@ pub fn get_metadata(config: AppConfig) {
1919
.create::<StreamConsumer>()
2020
.expect("Consumer creation failed");
2121
let metadata = Consumer::fetch_metadata(&stream, None, rdkafka::util::Timeout::Never).unwrap();
22+
let position = Consumer::position(&stream).unwrap();
23+
print_positions(&position);
2224
print_topics(&metadata);
2325
}
2426

27+
fn print_positions(position: &TopicPartitionList) {
28+
let inner = position
29+
.elements()
30+
.iter()
31+
.map(|x| x.topic().to_string())
32+
.collect::<Vec<_>>()
33+
.join("\n");
34+
println!("{}", inner);
35+
}
36+
2537
fn print_topics(metadata: &Metadata) {
2638
// NOTE: Can be optimized by precalculating the required memory, I think.
2739
let mut tw = TabWriter::new(vec![]);
@@ -33,7 +45,7 @@ fn print_topics(metadata: &Metadata) {
3345
.map(|(idx, metadata_topic)| {
3446
format!(
3547
"{}.\t{}\t{}\t{}",
36-
idx,
48+
idx + 1,
3749
metadata_topic.name(),
3850
metadata_topic.partitions().len(),
3951
metadata_topic.error().map(|_| "true").unwrap_or("false")

0 commit comments

Comments
 (0)