Description
Step 1: On a server running kafka using the kafka-server-start script and KAFKA_JMX_OPTS populated to turn on JMX. Kafka broker starts with a jmx listener.
Step 2: Use another script like bin/kafka-topics, the shell script always fails because the call to kafka-run-class always triggers starting a jmx listener on the same port in the environment variables.
Expected behavior: Be able to use a script like kafka-topics without error on a host that already has JMX environment variables and a process listening on the defined port.
Actual behavior: bin/kafka-topics errors out trying to start another jmx listener on the same port in KAFKA_JMX_OPTS.
When kafka-topics shell script pass arguments to kafka-run-class, kafka-run-class tries and fails to initialize a jmx listener because, in this example, the kafka-server-start already started one and $JMX_OPTS is always defined/used at the end of kafka-run-class.sh
A proposed solution is editing the kafka-run-class file.
- add a variable declaration NO_JMX="true"
- Add the following to the case statement in kafka-run-class.sh kafka.Kafka|org.apache.kafka.connect.cli.ConnectDistributed)
NO_JMX="false"
shift;; - Add an elif at the end of kafka-run-class.sh
elif [ "$NO_JMX" = "true" ] ; then
exec "$JAVA" $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_LOG4J_OPTS -cp "$CLASSPATH" $KAFKA_OPTS "$@"
The workaround is every time you run a script like kafka-topics.sh or kafka-configs.sh, run it like this JMX_PORT='' KAFKA_JMX_OPTS='' bin/kafka-topics ....