2
votes

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!

1
#1: I don't see any logging messages in here, so how do you know that it's the send() that's taking a minute? - kdgregory
#2: what happens when you call get() on the Future that send() returns? - kdgregory
then i see the following exception: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms. i also tried and i get this exception when i call on the producder the partitionsFor("topic") method. - metabolic
Try to create our topic manually before you write into it. - Matthias J. Sax
no, error still occures... it is very strange. everything is running on localhost on linux. for test cases i set everything up on windows too. there it works... could it maybe be some permission issue? - metabolic

1 Answers

0
votes

Try set the bootstrap.servers to 127.0.0.1:9092