javaapache-kafkaproducer

Do newer versions of Kafka producers still have "producer.type"?


Older versions' doc says it's one of the essential properties.

Newer versions' doc doesn't mention it at all.

Do newer versions of Kafka producers still have producer.type?

Or, new producers are always async, and I should call future.get() to make it sync?


Solution

  • New producers are always async, and you should call future.get() to make it sync. It's not worth making two apis methods when something as simple as adding future.get() gives you basically the same functionality.

    From the documentation for send() here

    https://kafka.apache.org/0110/javadoc/index.html?org/apache/kafka/clients/producer/KafkaProducer.html

    Since the send call is asynchronous it returns a Future for the RecordMetadata that will be assigned to this record. Invoking get() on this future will block until the associated request completes and then return the metadata for the record or throw any exception that occurred while sending the record.

    If you want to simulate a simple blocking call you can call the get() method immediately:

    byte[] key = "key".getBytes();
    byte[] value = "value".getBytes();  
    ProducerRecord<byte[],byte[]> record = new ProducerRecord<byte[],byte[]>("my-topic", key, value);
    producer.send(record).get();