简体   繁体   中英

KafkaProducer not sending Record

I'm completely new to Kafka and i have some troubles using the KafkaProducer. The send Method of the producer blocks exactly 1min and then the application proceeds without an exception. This is obviously some timeout but no Exception is thrown.

I can also see nothing really in the logs.

The servers seam to be setup correctly. If i use the bin/kafka-console-consumer and producer applications i can send and receive messages correctly. Also the code seams to work to some extend. If i want to write to a topic which does not exist yet i can see in the /tmp/kafka-logs folder the new entry and also in the console output of the KafkaServer. Here is the Code i use:

    Properties props = ResourceUtils.loadProperties("kafka.properties");
    Producer<String, String> producer = new KafkaProducer<>(props);

    for (String line : lines)
    {
        producer.send(new ProducerRecord<>("topic", Id, line));
        producer.flush();
    }
    producer.close();

The properties in the kafka.properties file:

bootstrap.servers=localhost:9092
key.serializer=org.apache.kafka.common.serialization.StringSerializer
value.serializer=org.apache.kafka.common.serialization.StringSerializer
acks=all
retries=0
batch.size=16384
linger.ms=1
buffer.memory=33554432

So, producer.send blocks for 1minute and then it continues. At the end nothing is stored in Kafka, but the new topic is created. Thank you for any help!

尝试将bootstrap.servers设置为127.0.0.1:9092

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM