Project setup

The first step is to create the Kioto project. Create a directory called kioto. Go to that directory and execute the following command:

$ gradle init --type java-library

The output is something like the following:

Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 3s
2 actionable tasks: 2 execute BUILD SUCCESSFUL

Gradle creates a default project in the directory, including two Java files called Library.java and LibraryTest.java; delete both files.

Your directory should be similar to the following:

  • - build.gradle
  • - gradle
  • -- wrapper
  • --- gradle-wrapper.jar
  • --- gradle-vreapper.properties
  • - gradlew
  • - gradle.bat
  • - settings.gradle
  • - src
  • -- main
  • --- java
  • ----- Library.java
  • -- test
  • --- java
  • ----- LibraryTest.java

Modify the build.gradle file and replace it with Listing 4.2.

The following is the content of Listing 4.2, the Kioto Gradle build file:

apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = '1.8'
mainClassName = 'kioto.ProcessingEngine'
repositories {
mavenCentral()
maven { url 'https://packages.confluent.io/maven/' }
}
version = '0.1.0'
dependencies {
compile 'com.github.javafaker:javafaker:0.15'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.7'
compile 'io.confluent:kafka-avro-serializer:5.0.0'
compile 'org.apache.kafka:kafka_2.12:2.0.0'
}
jar {
manifest {
attributes 'Main-Class': mainClassName
} from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}

Some library dependencies added to the application are as follows:

  • kafka_2.12, the necessary dependencies for Apache Kafka
  • javafaker, the necessary dependencies for JavaFaker
  • jackson-core, for JSON parsing and manipulation
  • kafka-avro-serializer, to serialize in Kafka with Apache Avro

Note that to use the kafka-avro-serializer function, we added the Confluent repository in the repositories section.

To compile the project and download the required dependencies, type the following command:

$ gradle compileJava

The output should be similar to the following:

BUILD SUCCESSFUL in 3s
1 actionable task: 1 executed

The project can also be created with Maven, SBT, or even from the IDE. But for simplicity, it was created with Gradle. For more information about these projects, visit the following:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.50.185