java - Compiling a custom producer for Kafka -


i've downloaded kafka https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.1.1/kafka_2.8.0-0.8.1.1.tgz , set kafka cluster on machine using vms. cluster working fine - tested using console producer , consumer provided kafka package.

now, i've implemented custom producer class kafka. couldn't figure out how compile class , dependencies are.

questions

  • could explain how need go fetching dependencies producer, building class , running it?

  • do need sbt build it? couldn't find online resources explained how go building custom kafka producer class.

following packages imported in producer class:

org.apache.kafka.clients.producer.callback; org.apache.kafka.clients.producer.kafkaproducer; org.apache.kafka.clients.producer.producerconfig; org.apache.kafka.clients.producer.producerrecord; org.apache.kafka.clients.producer.recordmetadata; org.apache.kafka.common.record.records 

thanks in advance

i developed custom kafka producer, maven project, dependency used was:

<dependency>     <groupid>org.apache.kafka</groupid>     <artifactid>kafka-clients</artifactid>     <version>0.8.2.0</version> </dependency> 

imports used:

import org.apache.kafka.clients.producer.kafkaproducer; import org.apache.kafka.clients.producer.producerconfig; import org.apache.kafka.clients.producer.producerrecord; import org.apache.kafka.common.serialization.bytearrayserializer; import org.apache.kafka.common.serialization.stringserializer; 

a snippet of producer message sending code:

properties props = new properties(); props.put(producerconfig.bootstrap_servers_config, zkconnection); props.put(producerconfig.key_serializer_class_config, stringserializer.class); props.put(producerconfig.value_serializer_class_config, bytearrayserializer.class);  byte[] bytedata = null; file myinputfile = new file(...); try (inputstream inputstream = new fileinputstream(myinputfile)) {     bytedata = ioutils.tobytearray(inputstream); }  try (kafkaproducer<string, byte[]> producer = new kafkaproducer<string, byte[]>(props)) {     producer.send(new producerrecord<string, byte[]>(topic, bytedata)); } 

Comments