Yandex Cloud
Documentation
PresentationContact UsTry it for free
© 2026 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
      • Adding data to a ClickHouse® DB
      • Fetching data from Managed Service for Apache Kafka® to Managed Service for ClickHouse®
      • Fetching data from Managed Service for Apache Kafka® to ksqlDB
      • Fetching data from RabbitMQ to Managed Service for ClickHouse®
      • Migrating data to Managed Service for ClickHouse® using ClickHouse®
      • Migrating data to Managed Service for ClickHouse® using Data Transfer
      • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
      • Migrating data from Managed Service for OpenSearch to Managed Service for ClickHouse® with a storage change using Data Transfer
      • Delivering data from Managed Service for MySQL® to Managed Service for ClickHouse® using Data Transfer
      • Exchanging data between Managed Service for ClickHouse® and Yandex Data Processing
      • Configuring Managed Service for ClickHouse® for Graphite
      • Saving a data stream from Data Streams to Managed Service for ClickHouse®
      • Asynchronously replicating data from PostgreSQL to ClickHouse®
      • Asynchronous replication of data from Yandex Metrica to ClickHouse® using Data Transfer
      • Using hybrid storage in Managed Service for ClickHouse®
      • Sharding Managed Service for ClickHouse® tables
      • Executing analytical queries in Managed Service for PostgreSQL with processing in Managed Service for ClickHouse®
      • Loading data from Yandex Direct to a Managed Service for ClickHouse® data mart using Cloud Functions, Object Storage, and Data Transfer
      • Loading data from Object Storage to Managed Service for ClickHouse® using Data Transfer
      • Loading data from Managed Service for YDB to Managed Service for ClickHouse® using Data Transfer
      • Yandex Managed Service for ClickHouse® integration with Microsoft SQL Server via ClickHouse® JDBC Bridge
      • Yandex Managed Service for ClickHouse® integration with Oracle via ClickHouse® JDBC Bridge

In this article:

  • Getting started
  • Required paid resources
  • Set up your infrastructure
  • Set up Apache Kafka® integration for the ksqlDB database
  • Review the format of the data coming from Managed Service for Apache Kafka®
  • Create a table in ksqlDB to write a data stream from the Apache Kafka® topic
  • Get test data from the Managed Service for Apache Kafka® cluster
  • Write test data to ksqlDB
  • Check for records in Apache Kafka® topics
  • Delete the resources you created
  1. Building a data platform
  2. ClickHouse®
  3. Fetching data from Managed Service for Apache Kafka® to ksqlDB

Delivering data to ksqlDB

Written by
Yandex Cloud
Updated at November 16, 2026
View in Markdown
  • Getting started
    • Required paid resources
  • Set up your infrastructure
  • Set up Apache Kafka® integration for the ksqlDB database
  • Review the format of the data coming from Managed Service for Apache Kafka®
  • Create a table in ksqlDB to write a data stream from the Apache Kafka® topic
  • Get test data from the Managed Service for Apache Kafka® cluster
  • Write test data to ksqlDB
  • Check for records in Apache Kafka® topics
  • Delete the resources you created

ksqlDB is a database designed for stream processing of messages coming from Apache Kafka® topics. Working with message streams in ksqlDB is similar to working with tables in a regular database. A ksqlDB table is automatically populated with data from an Apache Kafka® topic, and any data you insert into the ksqlDB table is written back to the topic. Learn more in this ksqlDB article.

To set up data delivery from Yandex Managed Service for Apache Kafka® to ksqlDB:

  1. Set up your infrastructure.
  2. Set up Apache Kafka® integration for the ksqlDB database.
  3. Review the format of the data coming from Managed Service for Apache Kafka®.
  4. Create a ksqlDB table to write a data stream from the Apache Kafka® topic.
  5. Get test data from the Managed Service for Apache Kafka® cluster.
  6. Write the test data to ksqlDB.
  7. Check the Apache Kafka® topic for the test data.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

  • Managed Service for Apache Kafka® cluster: use of computing resources allocated to hosts and storage size (see Managed Service for Apache Kafka® pricing).
  • Public IP addresses if public access is enabled for cluster hosts (see Yandex Virtual Private Cloud pricing).

Set up your infrastructureSet up your infrastructure

  1. Create a Managed Service for Apache Kafka® cluster of any suitable configuration.

    • If the ksqlDB server is hosted on the internet, create a publicly accessible Managed Service for Apache Kafka® cluster.

    • If the ksqlDB server is hosted in Yandex Cloud, create a Managed Service for Apache Kafka® cluster on the same cloud network as ksqlDB.

  2. Create topics in the Managed Service for Apache Kafka® cluster:

    1. Service topic named default_ksql_processing_log to write ksqlDB logs to. Use any settings.
    2. Data storage topic named locations. Use any settings.
  3. Create a user named ksql and assign them the ACCESS_ROLE_ADMIN role for all topics.

  4. Make sure you can connect to the ksqlDB server.

  5. Install kafkacat on the ksqlDB server and check that you can use it to connect to the Managed Service for Apache Kafka® cluster over SSL.

  6. Install jq on the ksqlDB server to process JSON data streams.

Set up Apache Kafka® integration for the ksqlDB databaseSet up Apache Kafka® integration for the ksqlDB database

  1. Connect to the ksqlDB server.

  2. Go to the /etc/ksqldb directory:

    cd /etc/ksqldb
    
  3. Add the server's SSL certificate to the Java trusted certificate store (Java Key Store) so that ksqlDB can use it for secure connections to cluster hosts:

    Linux (Bash)
    macOS (Zsh)
    awk '/-----BEGIN CERTIFICATE-----/ {n++} n {print > "YandexCA-" n ".crt"}' \
      < /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt
    
    for cert in YandexCA-*.crt; do
      alias=$(
        openssl x509 -noout -text -in "${cert}" |
        perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print'
      )
    
      year=$(openssl x509 -noout -enddate -in "${cert}" | awk '{print $(NF-1)}')
    
      echo "Importing ${alias}-${year}"
    
      keytool -importcert \
              -alias "${alias}-${year}" \
              -file "${cert}" \
              -keystore ssl \
              -storepass <secure_store_password> \
              -noprompt
    
      rm "${cert}"
    done
    
    chmod 0655 ssl
    
    split -p "-----BEGIN CERTIFICATE-----" \
      /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt \
      YandexCA-
    
    for cert in YandexCA-*.crt; do
      alias=$(
        openssl x509 -noout -text -in "${cert}" |
        perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print'
       )
    
      year=$(openssl x509 -noout -enddate -in "${cert}" | awk '{print $(NF-1)}')
    
      echo "Importing ${alias}-${year}"
    
      keytool -importcert \
              -alias "${alias}-${year}" \
              -file "${cert}" \
              -keystore ssl \
              -storepass <secure_store_password> \
              -noprompt
    
      rm "${cert}"
    done
    
    chmod 0655 ssl
    

    Where -storepass is the certificate store password. The password must contain at least six characters.

  4. In the /etc/ksqldb/ksql-server.properties ksqlDB configuration file, specify the credentials for authentication in the Managed Service for Apache Kafka® cluster:

    bootstrap.servers=<broker_1_FQDN>:9091,...,<broker_N_FQDN>:9091
    sasl.mechanism=SCRAM-SHA-512
    security.protocol=SASL_SSL
    ssl.truststore.location=/etc/ksqldb/ssl
    ssl.truststore.password=<certificate_store_password>
    sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="ksql" password="<ksql_user_password>";
    

    To learn how to get a broker host FQDN, see this guide.

    You can get the cluster name with the list of clusters in the folder.

  5. In the ksqlDB logging configuration file named /etc/ksqldb/log4j.properties, configure logging to a Managed Service for Apache Kafka® cluster topic:

    log4j.appender.kafka_appender=org.apache.kafka.log4jappender.KafkaLog4jAppender
    log4j.appender.kafka_appender.layout=io.confluent.common.logging.log4j.StructuredJsonLayout
    log4j.appender.kafka_appender.BrokerList=<broker_1_FQDN>:9091,...,<broker_N_FQDN>:9091
    log4j.appender.kafka_appender.Topic=default_ksql_processing_log
    log4j.logger.io.confluent.ksql=INFO,kafka_appender
    
    log4j.appender.kafka_appender.clientJaasConf=org.apache.kafka.common.security.scram.ScramLoginModule required username="ksql" password="<ksql_user_password>";
    log4j.appender.kafka_appender.SecurityProtocol=SASL_SSL
    log4j.appender.kafka_appender.SaslMechanism=SCRAM-SHA-512
    log4j.appender.kafka_appender.SslTruststoreLocation=/etc/ksqldb/ssl
    log4j.appender.kafka_appender.SslTruststorePassword=<certificate_store_password>
    
  6. Restart the ksqlDB service with the command below:

    sudo systemctl restart confluent-ksqldb.service
    

Review the format of the data coming from Managed Service for Apache Kafka®Review the format of the data coming from Managed Service for Apache Kafka®

The Managed Service for Apache Kafka® data stream processing depends on the Apache Kafka® message view format.

In our example, geodata is written to the locations Apache Kafka® topic in JSON format:

  • profileId: ID
  • latitude: Latitude
  • longitude: Longitude

This data will be transmitted as Apache Kafka® messages. Each message will contain a string containing a serialized JSON object with the following structure:

{"profileId": "c2309eec", "latitude": 37.7877, "longitude": -122.4205}

ksqlDB stores the values of the relevant parameters from Apache Kafka® messages in a three-column table.

Next, we are going to configure the fields of a ksqlDB data stream table.

Create a table in ksqlDB to write a data stream from the Apache Kafka® topicCreate a table in ksqlDB to write a data stream from the Apache Kafka® topic

Create a table in ksqlDB for writing data from the Apache Kafka® topic. The table structure matches the format of data from Managed Service for Apache Kafka®:

  1. Connect to the ksqlDB server.

  2. Run the ksql client using this command:

    ksql http://0.0.0.0:8088
    
  3. Run this query:

    CREATE STREAM riderLocations 
    (
      profileId VARCHAR,
      latitude DOUBLE,
      longitude DOUBLE
    ) WITH 
    (
      kafka_topic='locations', 
      value_format='json', 
      partitions=<number_of_locations_topic_sections>
    );
    

    This data stream table will be automatically populated with messages from the Managed Service for Apache Kafka® cluster's locations topic. ksqlDB uses the ksql user's settings to read messages.

    For more information about creating a streaming table in ksqlDB, see this ksqlDB article.

  4. Run this query:

    SELECT * FROM riderLocations WHERE 
             GEO_DISTANCE(latitude, longitude, 37.4133, -122.1162) <= 5 
             EMIT CHANGES;
    

    The query waits for real-time data to appear in the table.

Get test data from the Managed Service for Apache Kafka® clusterGet test data from the Managed Service for Apache Kafka® cluster

  1. Connect to the ksqlDB server.

  2. Create a file named sample.json with the following test data:

    {
      "profileId": "c2309eec", 
      "latitude": 37.7877,
      "longitude": -122.4205
    }
    
    {
      "profileId": "4ab5cbad", 
      "latitude": 37.3952,
      "longitude": -122.0813
    }
    
    {
      "profileId": "4a7c7b41", 
      "latitude": 37.4049,
      "longitude": -122.0822
    }   
    
  3. Send the sample.json file to the Managed Service for Apache Kafka® cluster's locations topic using jq and kafkacat:

    jq -rc . sample.json | kafkacat -P \
       -b <broker_1_FQDN>:9091,...,<broker_N_FQDN>:9091> \
       -t locations \
       -X security.protocol=SASL_SSL \
       -X sasl.mechanisms=SCRAM-SHA-512 \
       -X sasl.username=ksql \
       -X sasl.password="<ksql_user_password>" \
       -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -Z
    

    The information is sent using the ksql user. To learn more about setting up an SSL certificate and using kafkacat, see Connecting to an Apache Kafka® cluster from applications.

  4. Make sure the session shows the data sent to the topic:

    +--------------------------+--------------------------+------------------------+
    |PROFILEID                 |LATITUDE                  |LONGITUDE               |
    +--------------------------+--------------------------+------------------------+
    |4ab5cbad                  |37.3952                   |-122.0813               | 
    |4a7c7b41                  |37.4049                   |-122.0822               |
    

The data is read using the ksql user.

Write test data to ksqlDBWrite test data to ksqlDB

  1. Connect to the ksqlDB server.

  2. Run the ksql client using this command:

    ksql http://0.0.0.0:8088
    
  3. Insert test data into the riderLocations table as follows:

    INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('18f4ea86', 37.3903, -122.0643);
    INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('8b6eae59', 37.3944, -122.0813);
    INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ddad000', 37.7857, -122.4011);
    

    This data is sent synchronously to the locations Apache Kafka® topic using the ksql user.

Check for records in Apache Kafka® topicsCheck for records in Apache Kafka® topics

  1. Check messages in the Managed Service for Apache Kafka® cluster's locations topic using kafkacat and the ksql user:

    kafkacat -C \
     -b <broker_1_FQDN>:9091,...,<broker_N_FQDN>:9091 \
     -t locations \
     -X security.protocol=SASL_SSL \
     -X sasl.mechanisms=SCRAM-SHA-512 \
     -X sasl.username=ksql \
     -X sasl.password="<ksql_user_password>" \
     -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -Z -K:
    
  2. Make sure the console displays the messages you inserted into the table.

  3. Check messages in the Managed Service for Apache Kafka® cluster's default_ksql_processing_log topic using kafkacat and the ksql user:

    kafkacat -C \
     -b <broker_1_FQDN>:9091,...,<broker_N_FQDN>:9091 \
     -t default_ksql_processing_log \
     -X security.protocol=SASL_SSL \
     -X sasl.mechanisms=SCRAM-SHA-512 \
     -X sasl.username=ksql \
     -X sasl.password="<ksql_user_password>" \
     -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -Z -K:
    
  4. Make sure the console displays ksqlDB log entries.

Delete the resources you createdDelete the resources you created

Some resources are not free of charge. Delete the resources you no longer need, so you will not be charged for them:

  • Delete the VM.
  • If you reserved a public static IP address for your virtual machine, delete it.
  • Delete the Managed Service for Apache Kafka® cluster.

Was the article helpful?

Previous
Fetching data from Managed Service for Apache Kafka® to Managed Service for ClickHouse®
Next
Fetching data from RabbitMQ to Managed Service for ClickHouse®
© 2026 Direct Cursus Technology L.L.C.