Kafka:是否有用于 scala 的 Kalfa 客户端 API?
Kafka: Is there a Kalfa clients API for scala?
我刚开始使用 Kafka,它听起来非常适合微服务,但我主要在 Scala 中工作。
我用这个将 kafka 添加到我的 sbt 项目中:
libraryDependencies += "org.apache.kafka" %% "kafka" % "2.0.0"
然后我这样做:
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)
...
我的问题是当我调用 producer.send
时我没有得到 Scala Future
,它是 Java Future
。我不知道 Java Futures 是如何工作的,我宁愿跳过那个学习曲线。这次是 Future,但我指的是一般 Java。
所以我想知道是否有完整的 Scala api 可以与 Kafka 一起使用。通常情况下应该是这样,因为 Kafka 是用 Scala 编写的。
来自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.
我刚开始使用 Kafka,它听起来非常适合微服务,但我主要在 Scala 中工作。
我用这个将 kafka 添加到我的 sbt 项目中:
libraryDependencies += "org.apache.kafka" %% "kafka" % "2.0.0"
然后我这样做:
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)
...
我的问题是当我调用 producer.send
时我没有得到 Scala Future
,它是 Java Future
。我不知道 Java Futures 是如何工作的,我宁愿跳过那个学习曲线。这次是 Future,但我指的是一般 Java。
所以我想知道是否有完整的 Scala api 可以与 Kafka 一起使用。通常情况下应该是这样,因为 Kafka 是用 Scala 编写的。
来自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.