Skip to content

Connect to Kafka

View as Markdown
Your servicessend messagesKafkatopicsYour servicesread with their own groupsa consumer group of its ownstreamviewonly readsYour browserthe timelineStored messages first, then new messages.The offsets of your groups do not change.

You need the streamview program, Node.js, and the address of a broker.

Run this command with the address of your broker:

streamview kafka --brokers localhost:9092

The first time, the command installs the Kafka adapter. This takes some seconds. The browser then opens, and each topic is one lane.

streamview reads all stored messages first, and sorts them by time. With many messages, this takes some minutes. The page stays empty during this time.

Connect to a broker that needs TLS or a login

Section titled “Connect to a broker that needs TLS or a login”

A hosted Kafka service usually needs an encrypted connection (TLS) and a login (SASL). Your Kafka service gives you the address, the user name, the password, and the login mechanism.

  1. Put the password in the environment variable STREAMVIEW_KAFKA_PASSWORD. For some services, the password is an API secret.
  2. Add --tls to the command.
  3. Add --user with the user name. For some services, the user name is an API key.
  4. Add --mechanism if the service does not use plain. The other mechanisms are scram-sha-256 and scram-sha-512.
export STREAMVIEW_KAFKA_PASSWORD='your-password'
streamview kafka --brokers broker.example.com:9093 --tls --user your-user --mechanism scram-sha-512

If the broker has a certificate from a private certificate authority, add --ca with the PEM file of that authority. --ca also turns on TLS.

streamview kafka --brokers broker.example.com:9093 --ca ca.pem --user your-user

If the broker asks for a client certificate, add --cert and --key with the two PEM files.

streamview kafka --brokers broker.example.com:9093 --ca ca.pem --cert client.pem --key client-key.pem

If the broker refuses the connection, the command prints the cause in the terminal, and tells you which option to change.

Add --latest. streamview then does not read the stored messages.

streamview kafka --brokers localhost:9092 --latest

Add --topics with a regular expression. streamview reads only the topics that match.

streamview kafka --brokers localhost:9092 --topics '^(orders|payments)\.'

streamview does not read internal topics, for example __consumer_offsets, also when the expression matches them. To read them, add --include-internal.

If your messages are CloudEvents, streamview uses their correlationid field.

If your messages are plain JSON, streamview looks for a correlationid header or a traceparent header. If the messages do not have these headers, use one of these two options:

  • Add --correlation-field with the name of the field that all messages of one order contain.
  • Add --correlation-key if the key of each message is the ID of the order.
streamview kafka --brokers localhost:9092 --correlation-field orderId
streamview kafka --brokers localhost:9092 --correlation-key

Do not use --correlation-key if many different orders have the same key. All messages with one key then become one order.

By default, streamview uses a new consumer group for each start, and reads all stored messages.

To continue from the position of the last start, give the consumer group a name with --group. Use the same SQLite file each time, because the file has the events from before.

streamview kafka --brokers localhost:9092 --group streamview-team

When a group with this name read before, the command prints a line that tells you. If the page is empty and you expected old messages, use a different name, or remove --group.

streamview stores the events in streamview.db in the current directory. To use a different file, add --db and a path.

streamview kafka --brokers localhost:9092 --db /var/lib/streamview/kafka.db

When you start streamview again with the same file, it loads the stored events and ignores messages that it already has.

Put a comma between the addresses:

streamview kafka --brokers broker-1:9092,broker-2:9092