Skip to main content
Quick navigation

a ksqlDB experience on concentrated topics

View the full demo in realtime

You can either follow all the steps manually, or watch the recording

Review the docker compose environment

As can be seen from docker-compose.yaml the demo environment consists of the following services:

  • gateway1
  • gateway2
  • kafka-client
  • kafka1
  • kafka2
  • kafka3
  • ksqldb-server
  • schema-registry
  • zookeeper
cat docker-compose.yaml

Starting the docker environment

Start all your docker processes, wait for them to be up and ready, then run in background

  • --wait: Wait for services to be running|healthy. Implies detached mode.
  • --detach: Detached mode: Run containers in the background
docker compose up --detach --wait

Creating virtual cluster teamA

Creating virtual cluster teamA on gateway gateway1 and reviewing the configuration file to access it

# Generate virtual cluster teamA with service account sa
token=$(curl \
--request POST "http://localhost:8888/admin/vclusters/v1/vcluster/teamA/username/sa" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data-raw '{"lifeTimeSeconds": 7776000}' | jq -r ".token")

# Create access file
echo """
bootstrap.servers=localhost:6969
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='sa' password='$token';
""" > teamA-sa.properties

# Review file
cat teamA-sa.properties

Let's tell gateway1 that topics matching the pattern .* need to be concentrated into the underlying concentrated physical topic.

[!NOTE] You don���t need to create the physical topic that backs the concentrated topics, it will automatically be created when a client topic starts using the concentrated topic.

{
"concentrated" : true,
"readOnly" : false,
"physicalTopicName" : "concentrated"
}
curl \
--request POST 'http://localhost:8888/admin/vclusters/v1/vcluster/teamA/topics/.%2A' \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data "@step-06-mapping.json" | jq

Start ksqlDB

export KSQL_BOOTSTRAP_SERVERS="localhost:6969"
export KSQL_SECURITY_PROTOCOL="SASL_PLAINTEXT"
export KSQL_SASL_MECHANISM="PLAIN"
export KSQL_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username='sa' password='eyJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InNhIiwidmNsdXN0ZXIiOiJ0ZWFtQSIsImV4cCI6MTcxNTY1MjI1OX0.Kl9stSuppDqvCOXs3noNte22PBQKuVApY-hc_ZudKuA';"
docker compose --profile ksqldb up -d --wait

Listing topics in teamA

kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--list

Listing topics in kafka1

kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--list

Review ksql.sql

cat ksql.sql

Execute ksql script

docker exec ksqldb-server ksql 'http://localhost:8088' -f /sql/ksql.sql

Listing topics in teamA

kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--list

Listing topics in kafka1

kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--list

Tearing down the docker environment

Remove all your docker processes and associated volumes

  • --volumes: Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers.
docker compose down --volumes

Conclusion

ksqlDB can run in a virtual cluster where all its topics are concentrated into a single physical topic