I created the following producer using rust -
use rdkafka::config::ClientConfig;
use rdkafka::producer::{BaseProducer, BaseRecord, Producer};
use std::time::Duration;
fn main()
{
println!("starting ... ");
let producer: BaseProducer = ClientConfig::new()
.set("bootstrap.servers", "localhost:9092")
.create()
.expect("invalid producer config");
producer
.send(
BaseRecord::to("destination_topic")
.payload("this is the payload")
.key("this is the key"),
).expect("Failed to enque");
for _ in 0..10
{
producer.poll(Duration::from_millis(100));
}
producer.flush(Duration::from_secs(1));
}
With the .toml file as follows -
[package]
name = "kafka-demo-3"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html || rdkafka = "^0.8.1"
[dependencies]
rdkafka = "0.25"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rand = "0.8.3"
After writing this code I then -
- Started zookeeper
$ bin/zookeeper-server-start.sh config/zookeeper.properties
- Started kafka broker service
$ bin/kafka-server-start.sh config/server.properties
Ran the above rust producer code
Then I tried to consume the messege sent by the producer
$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic rust --from-beginning
However on doing so I am getting the following message -
[2022-05-04 14:19:31,874] WARN [Consumer clientId=console-consumer, groupId=console-consumer-46832] Error while fetching metadata with correlation id 2 : {rust=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
^CProcessed a total of 0 messages
Not sure whats going wrong