Inserting Data Using Kafka

Apache Kafka is a distributed streaming platform. It allows you to create publishers, which create data streams, and consumers, which subscribe to and ingest the data streams produced by publishers.

You can use OmniSciDB KafkaImporter C++ program to consume a topic created by running Kafka shell scripts from the command line. Here are the steps to use a Kafka producer to send data and a Kafka consumer to store the data in OmniSciDB.

This example assumes you have already installed and configured Apache Kafka. See the Kafka website.

Creating a Topic

Create a sample topic for your Kafka producer.

  1. Run the script with the following arguments:

    bin/ --create --zookeeper localhost:2181 --replication-factor 1
    --partitions 1 --topic matstream
  2. Create a file named myfile that consists of comma-separated data. For example:

  3. Use omnisql to create a table to store the stream.

    create table stream1(name text, id int);

Using the Producer

Load your file into the Kafka producer.

  1. Create and start a producer using the following command.

    cat myfile | bin/ --broker-list localhost:9097
    --topic matstream

Using the Consumer

Load the data to OmniSciDB using the Kafka console consumer and the KafkaImporter program.

  1. Pull the data from Kafka into the KafkaImporter program.

    ./bin/ --broker-list localhost:6283 
    --topic matstream --from-beginning | /home/omnisci/build/bin/KafkaImporter stream1 omnisci 
      -p HyperInteractive -u omnisci --port 6274 --batch 1
    Field Delimiter: ,
    Line Delimiter: \n
    Null String: \N
    Insert Batch Size: 1
    1 Rows Inserted, 0 rows skipped.
    2 Rows Inserted, 0 rows skipped.
    3 Rows Inserted, 0 rows skipped.
    4 Rows Inserted, 0 rows skipped.
  2. Verify that the data arrived using omnisql.

    omnisql> select * from stream1;