npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kafka-console

v1.4.21

Published

Kafka CLI tool

Downloads

1,323

Readme

Kafka CLI tool

Command line tool to sufficiently and easy work with Kafka

NPM version Downloads

Table of Contents

Features

  • Producer
  • Consumer groups with seek and timeout
  • Built-in message encoders/decoders with types: json, js, raw
  • Custom message encoders/decoders as a js module
  • Message headers
  • GZIP compression
  • Plain, SSL and SASL_SSL implementations
  • Admin client
  • TypeScript support

Installing

npm install -g kafka-console

Examples

Common options

  -b, --brokers <brokers>                bootstrap server host (default: "localhost:9092")
  -l, --log-level <logLevel>             log level
  -t, --timeout <timeout>                set a timeout of operation (default: "0")
  -p, --pretty                           pretty print json
  --ssl                                  enable ssl (default: false)
  --mechanism <mechanism>                sasl mechanism
  --username <username>                  sasl username
  --password <password>                  sasl password
  --auth-id <authId>                     sasl aws authorization identity
  --access-key-id <accessKeyId>          sasl aws access key id
  --secret-access-key <secretAccessKey>  sasl aws secret access key
  --session-token <seccionToken>         sasl aws session token
  --oauth-bearer <oauthBearer>           sasl oauth bearer token
  -V, --version                          output the version number
  -h, --help                             display help for command

Commands

  consume [options] <topic>              Consume kafka topic events
  produce [options] <topic>              Produce kafka topic events
  metadata                               Displays kafka server metadata
  list|ls [options]                      Lists kafka topics
  config [options]                       Describes config for specific resource
  create <topic>                         Creates kafka topic
  delete <topic>                         Deletes kafka topic
  help [command]                         display help for command

Consumer

kcli consume [options] <topic>

Options

  -g, --group <group>      consumer group name
  -f, --format <format>    message type decoding json, js, raw (default: "json")
  -o, --output <filename>  write output to specified filename
  -a, --from-beginning     read messages from the beginning (default: false)
  -c, --count <count>      a number of messages to read (default: null)
  -s, --skip <skip>        a number of messages to skip (default: 0)
  -h, --help               display help for command

General usage with authentication

kcli consume $KAFKA_TOPIC -g $KAFKA_TOPIC_GROUP -b $KAFKA_BROKERS --ssl --mechanism plain --username $KAFKA_USERNAME --password $KAFKA_PASSWORD

Stdout jq example

kcli consume $KAFKA_TOPIC | jq .value

Custom data formatter example

kcli consume $KAFKA_TOPIC --format ./formatter/avro.js | jq

Producer

kcli produce [options] <topic>

Options

  -f, --format <format>   message format encoding json, js, raw (default: "json")
  -i, --input <filename>  input filename
  -d, --delay <delay>     delay in ms after event emitting (default: 0)
  -h, --header <header>   set a static header (default: [])
  --help                  display help for command

General usage

kcli produce $KAFKA_TOPIC -b $KAFKA_BROKERS --ssl --mechanism plain --username $KAFKA_USERNAME --password $KAFKA_PASSWORD

Produce a json data from stdin with custom formatter

cat payload.txt|kcli produce $KAFKA_TOPIC --format ./formatter/avro.js

Produce a json data from stdin

node payloadGenerator.js|kcli produce $KAFKA_TOPIC

Produce a json array data from stdin

cat payload.json|jq -r -c .[]|kcli produce $KAFKA_TOPIC

Payload single message input interface

interface Payload {
  key?: string; // kafka
  value: any;
  headers?: { [key: string]: value };
}

Formatters

export interface Encoder<T> {
  (value: T): Promise<string | Buffer> | string | Buffer;
}

export interface Decoder<T> {
  (value: Buffer): Promise<T> | T;
}

export interface Formatter<T> {
  encode: Encoder<T>;
  decode: Decoder<T>;
}

Environment

  • KAFKA_BROKERS
  • KAFKA_TIMEOUT
  • KAFKA_MECHANISM
  • KAFKA_USERNAME
  • KAFKA_PASSWORD
  • KAFKA_AUTH_ID
  • KAFKA_ACCESS_KEY_ID
  • KAFKA_SECRET_ACCESS_KEY
  • KAFKA_SESSION_TOKEN
  • KAFKA_OAUTH_BEARER

License

License The MIT License Copyright (c) 2024 Ivan Zakharchanka