Stream processing with ksqlDB on IBM Cloud Event Streams

Gen 2

Use ksqlDB with Event Streams for stream processing on IBM Cloud®. Learn how to set up and run ksqlDB for event streaming applications.

ksqlDB is an event streaming database built on Apache Kafka that you can use to build stream processing applications by using familiar SQL syntax.

You can run ksqlDB with Event Streams by using Docker as described in the ksqlDB quickstart.

Because ksqlDB requires topics with an unlimited retention.ms setting, you can use ksqlDB only with the Enterprise plan.

Complete the following steps to configure ksqlDB. After configuration is complete, you can run the queries described in the ksqlDB Quick Start Guide.

  1. In the IBM Cloud console, navigate to your Event Streams instance and create a topic named _confluent-ksql-default__command_topic with one partition and the default retention period.

  2. To run ksqlDB in a Docker container:

    a. Create a docker-compose.yml file with the following configuration:

    version: '2'
    
    services:
      ksqldb-server:
        image: confluentinc/ksqldb-server:latest
        hostname: ksqldb-server
        container_name: ksqldb-server
        ports:
          - "8088:8088"
        environment:
          KSQL_LISTENERS: http://0.0.0.0:8088
          KSQL_BOOTSTRAP_SERVERS: <BOOTSTRAP_SERVERS>
          KSQL_KSQL_SERVICE_ID: default_
          KSQL_KSQL_SINK_REPLICAS: 3
          KSQL_KSQL_STREAMS_REPLICATION_FACTOR: 3
          KSQL_SECURITY_PROTOCOL: SASL_SSL
          KSQL_KSQL_INTERNAL_TOPIC_REPLICAS: 3
          KSQL_SASL_JAAS_CONFIG: org.apache.kafka.common.security.plain.PlainLoginModule required username=\"token\" password=\"<PASSWORD>\";
          KSQL_SASL_MECHANISM: PLAIN
    
      ksqldb-cli:
        image: confluentinc/ksqldb-cli:latest
        container_name: ksqldb-cli
        depends_on:
          - ksqldb-server
        entrypoint: /bin/sh
        tty: true
    

    Replace <BOOTSTRAP_SERVERS> and <PASSWORD> with the connection values from your service credential.

    b. From the directory that contains the file, start the ksqlDB server:

    docker-compose up -d
    

    c. Connect to the ksqlDB server and launch an interactive CLI session:

    docker exec -it ksqldb-cli ksql http://ksqldb-server:8088
    
  3. To run ksqlDB natively from source:

    a. Clone the ksqlDB repository:

    git clone https://github.com/confluentinc/ksql.git
    

    b. Navigate to the repository directory and compile the project:

    cd ksql
    mvn clean install -Dmaven.test.skip=true
    

    c. Create an Event Streams ksqlDB configuration file (for example, config/ibm-eventstreams.properties):

    bootstrap.servers=<BOOTSTRAP_SERVERS>
    listeners=http://localhost:8088
    security.protocol=SASL_SSL
    sasl.mechanism=PLAIN
    sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="token" password="<PASSWORD>";
    ksql.sink.replications.default=3
    

    Replace <BOOTSTRAP_SERVERS> and <PASSWORD> with your service credential values.

    d. Start the ksqlDB server:

    ./bin/ksql-server-start ./config/ibm-eventstreams.properties
    

    e. Start the ksqlDB CLI:

    ./bin/ksql
    

When you complete these steps, you can run stream processing queries in ksqlDB.