问题
I am just starting with Kafka, it sounds really good for Microservices, but I work essentially in Scala.
I added kafka to my sbt project with this:
libraryDependencies += "org.apache.kafka" %% "kafka" % "2.0.0"
Then I do this:
import org.apache.kafka.clients.producer.{Callback,KafkaProducer, Producer}
...
val producer = new KafkaProducer[String, String](props)
val record = new ProducerRecord[String, String]("my-topic", "key", "value")
val fut = producer.send(record, callBack)
...
My problem here is that I am not getting a Scala Future
when I call producer.send
, it is a Java Future
. I don't know how Java Futures work, and I would prefer to skip that learning curve. This time it is Future, but I mean Java in general.
So I am wondering if there is a full Scala api to work with Kafka. It should normally be the case since Kafka is written in Scala.
回答1:
From Kafka notable changes in 2.0.0
The Scala consumers, which have been deprecated since 0.11.0.0, have been removed. The Java consumer has been the recommended option since 0.10.0.0. Note that the Scala consumers in 1.1.0 (and older) will continue to work even if the brokers are upgraded to 2.0.0.
The Scala producers, which have been deprecated since 0.10.0.0, have been removed. The Java producer has been the recommended option since 0.9.0.0. Note that the behaviour of the default partitioner in the Java producer differs from the default partitioner in the Scala producers. Users migrating should consider configuring a custom partitioner that retains the previous behaviour. Note that the Scala producers in 1.1.0 (and older) will continue to work even if the brokers are upgraded to 2.0.0.
来源:https://stackoverflow.com/questions/56180566/kafka-is-there-a-kalfa-clients-api-for-scala