Connect to Kafka
You need the streamview program, Node.js, and the address of a broker.
Show all topics
Section titled “Show all topics”Run this command with the address of your broker:
streamview kafka --brokers localhost:9092The 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.
- Put the password in the environment variable
STREAMVIEW_KAFKA_PASSWORD. For some services, the password is an API secret. - Add
--tlsto the command. - Add
--userwith the user name. For some services, the user name is an API key. - Add
--mechanismif the service does not useplain. The other mechanisms arescram-sha-256andscram-sha-512.
export STREAMVIEW_KAFKA_PASSWORD='your-password'streamview kafka --brokers broker.example.com:9093 --tls --user your-user --mechanism scram-sha-512If 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-userIf 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.pemIf the broker refuses the connection, the command prints the cause in the terminal, and tells you which option to change.
Show only new messages
Section titled “Show only new messages”Add --latest. streamview then does not read the stored messages.
streamview kafka --brokers localhost:9092 --latestShow only some topics
Section titled “Show only some topics”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.
Connect the messages of one order
Section titled “Connect the messages of one order”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-fieldwith the name of the field that all messages of one order contain. - Add
--correlation-keyif the key of each message is the ID of the order.
streamview kafka --brokers localhost:9092 --correlation-field orderIdstreamview kafka --brokers localhost:9092 --correlation-keyDo not use --correlation-key if many different orders have the same key. All messages with one key then become one order.
Continue from the last position
Section titled “Continue from the last position”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-teamWhen 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.
Keep the events in a different file
Section titled “Keep the events in a different file”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.dbWhen you start streamview again with the same file, it loads the stored events and ignores messages that it already has.
Use more than one broker
Section titled “Use more than one broker”Put a comma between the addresses:
streamview kafka --brokers broker-1:9092,broker-2:9092