旧版本的文档说这是基本属性之一。
新版本的文档根本没有提到它。
较新版本的 Kafka 生产者仍然有 Producer.type
吗?
或者,新的生产者总是异步
,我应该调用future.get()
使其同步
?
最佳答案
新的生产者总是异步的,你应该调用 future.get() 来使其同步。当像添加 future.get() 这样简单的事情为您提供基本相同的功能时,不值得创建两个 api 方法。
来自此处的 send() 文档
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();
关于java - 新版本的 Kafka 生产者是否仍然有 "producer.type"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45873907/