Creating a Kafka Streaming Application
Apache Kafka is a distributed streaming platform. You can use Kafka to stream data directly from an application into HeavyDB.
This example is a bare-bones click-through application that captures user activity.
This example assumes you have already installed and configured Apache Kafka. See the Kafka website. The FlavorPicker example also has dependencies on Swing/AWT classes. See the Oracle Java SE website.
Creating a Kafka Producer
FlavorPicker.java sends the choice of Chocolate, Strawberry, or Vanilla to the Kafka broker. This example uses only one column of information, but the mechanism is the same for records of any size.
Creating a Kafka Consumer
FlavorConsumer.java polls the Kafka broker periodically, pulls any new topics added since the last poll, and loads them to HeavyDB. Ideally, each batch should be fairly substantial in size, minimally 1,000 rows or more, so as not to overburden the server.
Running the Kafka Click-through Application
To run the application, you need to perform the following tasks:
Compile FlavorConsumer.java and FlavorPicker.java.
Create a table in HeavyDB.
Start the Zookeeper server.
Start the Kafka server.
Start the Kafka consumer.
Start the Kafka producer.
View the results using
heavysqland Heavy Immerse.
Compile FlavorConsumer.java and FlavorPicker.java, storing the resulting class files in
$HEAVYAI_PATH/SampleCode/kafka-clickthrough/bin.Using heavysql, create the table flavors with one column, flavor, in HeavyDB. See heavysql for more information.
Open a new terminal window.
Go to your
kafkadirectory.Start the Zookeeper server with the following command.
Open a new terminal window.
Go to the
kafkadirectory.Start the Kafka server with the following command.
Open a new terminal window.
Go to the
kafkadirectory.Create a new Kafka topic with the following command. This starts a basic broker with only one replica and one partition. See the Kafka documentation for more information.
Open a new terminal window.
Launch FlavorConsumer with the following command, substituting the actual path to the Kafka directory and your HeavyDB password.
Launch FlavorPicker with the following command.
Click to create several records for Chocolate, Strawberry, and Vanilla. Each click generates 1,000 records.

16. Use heavysql to see that the results have arrived in HeavyDB.

17. Use Immerse to visualize the results.

Last updated