kafka-python producer

A line-oriented console producer. Reads lines from standard input and publishes each one as a record to the configured topic.

Examples

# Publish a single message
echo "hello kafka" | kafka-python producer -b localhost:9092 -t my-topic

# Stream lines from a file
kafka-python producer -b localhost:9092 -t my-topic < messages.txt

Reference

Kafka console producer

usage: kafka-python producer [-h] -b BOOTSTRAP_SERVERS [-S SECURITY_PROTOCOL]
                             [-M SASL_MECHANISM] [-U SASL_USER]
                             [-P SASL_PASSWORD] [-l LOG_LEVEL]
                             [-L ENABLE_LOGGER] [-D DISABLE_LOGGER]
                             [--log-format LOG_FORMAT]
                             [--log-date-format LOG_DATE_FORMAT]
                             [--log-file LOG_FILE] [--log-config LOG_CONFIG]
                             [-C EXTRA_CONFIG] -t TOPIC [--encoding ENCODING]

connection

-b, --bootstrap-servers

host:port for cluster bootstrap server. Can be provided multiple times.

-S, --security-protocol

PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL

Default: 'PLAINTEXT'

-M, --sasl-mechanism

PLAIN, GSSAPI, OAUTHBEARER, SCRAM-SHA-256, SCRAM-SHA-512

Default: 'PLAIN'

-U, --sasl-user
-P, --sasl-password

logging

-l, --log-level

logging level, passed to logging.basicConfig

Default: 'CRITICAL'

-L, --enable-logger

enable a specific logger. Can be provided multiple times. If not provided, all loggers are enabled

-D, --disable-logger

disable a specific logger. Can be provided multiple times.

--log-format

log message format string, passed to logging.Formatter

--log-date-format

log date format string, passed to logging.Formatter

--log-file

write logs to this file instead of stderr

--log-config

path to a logging configuration file for full control over handlers, formatters, etc. A .json (or .yaml/.yml, if PyYAML is installed) file is loaded as a logging.config.dictConfig; any other extension is loaded as a logging.config.fileConfig. The file owns handlers/formatters, so –log-format, –log-date-format and –log-file are ignored, but –enable-logger and –disable-logger still apply as logger level adjustments.

extended

-C, --extra-config

additional configuration properties for client in “key=val” format. Can be provided multiple times.

producer options

-t, --topic

publish to topic

--encoding

byte encoding for produced messages

Default: 'utf-8'