Kafka client for Scala

341 views
Skip to first unread message

chelios....@gmail.com

unread,
Jun 13, 2016, 8:17:44 AM6/13/16
to kafka-clients
Hi Guys,

Which is the recommend client in Scala for Kafka ?

I've found the following two 


I don't know which one to use ? Can someone please suggest!

Cheers
Chel

Alan Reiner

unread,
Jun 17, 2016, 2:10:39 PM6/17/16
to kafka-clients
FYI, an indirect answer to your question is that I use the base java client code ("kafka-clients" maven module) from Scala.   Further, the lower-level API ("kafka_2.10" module, as of this writing) is actually in Scala already, though they are both straightforward to use in Scala:

This is what my pom.xml looks like (if you're using maven):

        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>0.9.0.1</version>
        </dependency>

        <dependency>
           <groupId>org.apache.kafka</groupId>
           <artifactId>kafka_2.10</artifactId>
           <version>0.9.0.1</version>
        </dependency>

Then I can access the libraries via:

// The following imports are for kafka tools in the "kafka-clients" maven dependency
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.ByteArraySerializer
import org.apache.kafka.common.serialization.StringSerializer
import org.apache.kafka.common.TopicPartition

// The following imports are from kafka tools in the kafka_2.10 maven dependency
import kafka.consumer._
import kafka.api.{PartitionOffsetRequestInfo, OffsetRequest}
import kafka.common.TopicAndPartition
import kafka.client.ClientUtils
import kafka.utils.{ToolsUtils, CommandLineUtils}


These are the import that I happen to use in my project.  Note that the kafka_2.10 module imports are low-level tools that most people probably wouldn't need.  Stick with the high-level "kafka-clients" module.

I can't speak to the maturity of the "native" scala libraries, though I suspect most are just wrappers around the java library.
Reply all
Reply to author
Forward
0 new messages