Kafka — Standalone Command-Line Application

kafka.Kafka is a standalone command-line application that starts a Kafka broker.

kafka.Kafka is started using kafka-server-start.sh shell script.

// Using sh -xv to trace kafka-server-start.sh
$ sh -xv ./bin/kafka-server-start.sh config/server.properties
exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@"
+ exec ./bin/kafka-run-class.sh -name kafkaServer -loggc kafka.Kafka config/server.properties

getPropsFromArgs Method


Starting Kafka Broker on Command Line — main Method

main(args: Array[String]): Unit

main registers a JVM shutdown hook to shut down KafkaServerStartable.

main uses Java’s Runtime.addShutdownHook to register the shutdown hook.

main terminates the JVM with status 0 when KafkaServerStartable shuts down properly and with status 1 in case of any exception.

main uses Java’s System.exit to terminate a JVM.

Registering INFO Logging Signal Handlers (for TERM, INT and HUP Signals) — registerLoggingSignalHandler Internal Method

registerLoggingSignalHandler(): Unit

registerLoggingSignalHandler registers signal handlers for TERM, INT and HUP signals so that, once received, it prints out the following INFO message to the logs:

Terminating process due to signal [signal]
$ jps -lm | grep -i kafka
79965 kafka.Kafka config/server.properties

// You could use "pkill -TERM -nf kafka" instead
$ kill -TERM 79965

// In the Kafka server's console
INFO Terminating process due to signal SIGTERM (kafka.Kafka$)
registerLoggingSignalHandler is used exclusively when a Kafka broker is started.
registerLoggingSignalHandler was added to Kafka 1.0.0 in KAFKA-5679; Add logging for broker termination due to SIGTERM or SIGINT.

results matching ""

    No results matching ""