alnoda-workspaces/workspaces/kafka-workspace/removeme_docs/getting-started.md
2022-05-23 16:13:15 +00:00

3.9 KiB

Getting started

Intro

This tutorial demonstrates how to use Kafka workspace to explore and interact with Kafka.

Singl-node Kafka cluster is running within the workspace, but all the tools can be used with the external Kafka clusters.

To start, open workspace UI http://localhost:8020/ for quick access to all the tools

Kafka WID

Open browser-based VS-code editor from the workspace UI, or go directly to http://localhost:8025/, and connect to the local Kafka cluster using VS-code Kafka extension. You only need to provide the name for the cluster, which can be any.

Theia connect WID

Using VS-code Kafka extension create topic "quickstart-events", and cosume events from this topic directly in VS-code using Kafka extension

Theia Kafka consume

Kafka native tools

Kafka distribution itself contains command line tools that allow to create topics, send and consume events, etc. Open workspace terminal http://localhost:8026/ and go to Kafka directory

cd /opt/kafka
  • create topic
bin/kafka-topics.sh --create --partitions 1 --replication-factor 1 --topic quickstart-events --bootstrap-server localhost:9092
  • send some messages
bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
  • consume messages
bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092

Send message

kt

Kafka tool that likes JSON.

Configure brokers, topic, Kafka version and authentication via environment variables KT_BROKERS, KT_TOPIC, KT_KAFKA_VERSION and KT_AUTH.

  • Set topic to "quickstart-events" (local Kafka instance by default)
export KT_TOPIC="quickstart-events"
  • Get information about topics, brockers and consumer groups
kt topic 
kt group
  • consume messages
kt consume 
  • produce messages
echo 'Bob wins Oscar' | kt produce -topic quickstart-events -literal

KT demo

kafkactl

A command-line interface for interaction with Apache Kafka.

  • Consume from topic "quickstart-events"
kafkactl consume  quickstart-events --from-beginning
kafkactl consume quickstart-events --from-beginning --print-keys --print-timestamps -o yaml

kcat

Generic non-JVM producer and consumer for Apache Kafka.

  • Consume topic "quickstart-events"
kafkacat -b localhost -t quickstart-events
  • Produce events to the topic
echo "Hello World" | kafkacat -b localhost -t quickstart-events

kcli

Kafka read only command line browser

Launch kcli in the Workspace terminal

kcli

trubka

Kafka CLI tool built in Go which gives you everything you need.

  • Consume from the topic "quickstart-events"
trubka consume plain quickstart-events --brokers localhost:9092
  • Produce message to the topic
trubka produce plain quickstart-events "Random Data" --brokers localhost:9092