kafka client version selection

When using maven to introduce the kafka client, taking the following version as an example, there will be two version numbers 2.10 and 0.10.1.0 which are very confusing.

<dependency>

    <groupId>org.apache.kafka</groupId>

    <artifactId>kafka_2.10</artifactId>

    <version>0.10.1.0</version>

</dependency>

Then two jars will be generated under the dependency lib

The 2.* version is the scala client, and the 1.* version is the java client. Both can be used in the java environment, but the calling methods are different.

scala version of producer

val kafkaConfig =KafkaUtils.buildKafkaConfig("kafkahost",9092)val producer =newProducer[String,String](newProducerConfig(kafkaConfig))// ... somewhere in code 
producer.send(newKeyedMessage[String,String]("my-topic", data))

The java version of the producer

val kafkaConfig =KafkaUtils.buildKafkaConfig("kafkahost",9092)val producer =newKafkaProducer[String,String](kafkaConfig)// ... somewhere in code 
producer.send(newProducerRecord[String,String]("my-topic", data))

 Which way to use instead? It turns out that these two methods are old and new APIs. The scala version is the old api and the java version is the new api. The official recommendation is to use the java version.

The official explanation is as follows

We are in the process of rewritting the JVM clients for Kafka. As of 0.8.2 Kafka includes a newly rewritten Java producer. The next release will include an equivalent Java consumer. These new clients are meant to supplant the existing Scala clients, but for compatability they will co-exist for some time. These clients are available in a seperate jar with minimal dependencies, while the old Scala clients remain packaged with the server.

 

For details, see: http://kafka.apache.org/082/documentation.html#producerapi

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326843364&siteId=291194637