You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by "신수웅(Sean Sin)" <wo...@gmail.com> on 2023/11/14 06:14:05 UTC
Fwd: [Question] About Kafka producer design decision making
Dear Apache Kakfa Developers,
I'm 4-year SWE in South Korea.
I have some questions while watching Kafka Producer API.
*Why Use "Future" and Not "CompletableFuture"?*
In the case of "Future", blocking occurs when calling "*get()*", so I
thought "Computable Future" would be better when doing more asynchronous
operations.
I looked at the Java API document
<https://kafka.apache.org/36/javadoc/org/apache/kafka/common/KafkaFuture.html#thenApply(org.apache.kafka.common.KafkaFuture.BaseFunction)>
based on the latest version, version 3.6.x.
If you look at that version, you can see that the Future object provides
the "toCompletionStage() "method, which can convert "KafkaFuture" to
"ComputableFuture".
In response to this, I think that in the initial design decision process,
we considered compatibility issues under JDK 1.8 and the level of knowledge
of the learning curve or developer when introducing ComputableFuture, but I
wonder if this is correct.
In addition, I wonder if it is recommended to use the "toCompletionStage()"
method to produce more non-blocking if we assume JDK 1.8 or higher.
Thanks.
Su-Ung Shin.
Re: [Question] About Kafka producer design decision making
Posted by Haruki Okada <oc...@gmail.com>.
Hi.
I also guess the main reason for using Future was for JDK1.7 support which
is no longer necessary in the current Kafka version.
Actually, there's a KIP about this:
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=100829459
but it seems it's not active now.
> I wonder if it is recommended to use
For now, the practical way for asynchronous produce is to use producer
callback. We can easily create CompletableFuture using it:
CompletableFuture<RecordMetadata> future = new CompletableFuture<>();
producer.send(record, (r, e) -> {
if (e != null) {
future.completeExceptionally(e);
} else {
future.complete(r);
}
});
2023年11月14日(火) 18:30 신수웅(Sean Sin) <wo...@gmail.com>:
> Dear Apache Kakfa Developers,
>
> I'm 4-year SWE in South Korea.
> I have some questions while watching Kafka Producer API.
>
> *Why Use "Future" and Not "CompletableFuture"?*
>
> In the case of "Future", blocking occurs when calling "*get()*", so I
> thought "Computable Future" would be better when doing more asynchronous
> operations.
>
> I looked at the Java API document
> <
> https://kafka.apache.org/36/javadoc/org/apache/kafka/common/KafkaFuture.html#thenApply(org.apache.kafka.common.KafkaFuture.BaseFunction)
> >
> based on the latest version, version 3.6.x.
>
> If you look at that version, you can see that the Future object provides
> the "toCompletionStage() "method, which can convert "KafkaFuture" to
> "ComputableFuture".
>
> In response to this, I think that in the initial design decision process,
> we considered compatibility issues under JDK 1.8 and the level of knowledge
> of the learning curve or developer when introducing ComputableFuture, but I
> wonder if this is correct.
>
> In addition, I wonder if it is recommended to use the "toCompletionStage()"
> method to produce more non-blocking if we assume JDK 1.8 or higher.
>
> Thanks.
> Su-Ung Shin.
>
--
========================
Okada Haruki
ocadaruma@gmail.com
========================