Skip to content

honourednihilist/gradle-kafka-deserializers-example

Repository files navigation

gradle-kafka-deserializers-example

This project is an example of how the gradle-kafka-deserializers plugin can be used.

The example consists of two modules:

  1. thrift-model - contains thrift classes definitions.
  2. kafka-deserializers - generates jar with thrift java classes and kafka deserializers for them.

thrift-gradle-plugin is used to generate thrift java classes. Here is how the plugins interaction is configured:

Task compileThriftTask = project(':thrift-model').tasks.getByName('compileThrift')

kafkaDeserializers {
    sourceItems = compileThriftTask.getOutputs().files
}

generateThriftKafkaDeserializers.dependsOn(compileThriftTask)

Set the THRIFT environment variable to let the build know where a thrift compiler is located:

$ export THRIFT=~/Programs/thrift-0.9.3/compiler/cpp/thrift

Assemble the project:

$ ./gradlew clean build

Put the created jar file into Kafka libs directory:

$ cp kafka-deserializers/build/libs/kafka-deserializers-0.1.0-SNAPSHOT.jar ~/Programs/kafka_2.10-0.10.1.0/libs/

Now you can use Kafka console consumer with generated deserializers:

$ ./kafka-console-consumer.sh --bootstrap-server localhost:6667 --topic test --max-messages 10 --property value.deserializer=com.github.honourednihilist.gradle.kafka.deserializers.example.model.gen.YourBaseStructThriftBinaryToJsonDeserializer