I want to ensure whether kafka server is running or not before starting production and consumption jobs. It is in windows environment and here's my kafka server's code in eclipse...
Properties properties = new Properties(); properties.setProperty("broker.id", "1"); properties.setProperty("port", "9092"); properties.setProperty("log.dirs", "D://workspace//"); properties.setProperty("zookeeper.connect", "localhost:2181"); Option<String> option = Option.empty(); KafkaConfig config = new KafkaConfig(properties); KafkaServer kafka = new KafkaServer(config, new CurrentTime(), option); kafka.startup();
In this case if (kafka != null)
is not enough because it is always true. So is there any way to know that my kafka server is running and ready for producer. It is necessary for me to check this because it causes loss of some starting data packets.
Use 'systemctl status kafka' to check the status.
To test Kafka APIs, you use the API Connection test step. To add it to a test case, you will need a ReadyAPI Test Pro license. If you do not have it, try a ReadyAPI trial.
Via command line, you can navigate to /usr/hdp/current/kafka-broker/libs and see the jar files with the versions.
All Kafka brokers must be assigned a broker.id
. On startup a broker will create an ephemeral node in Zookeeper with a path of /broker/ids/$id
. As the node is ephemeral it will be removed as soon as the broker disconnects, e.g. by shutting down.
You can view the list of the ephemeral broker nodes like so:
echo dump | nc localhost 2181 | grep brokers
The ZooKeeper client interface exposes a number of commands; dump
lists all the sessions and ephemeral nodes for the cluster.
Note, the above assumes:
2181
) on localhost
, and that localhost
is the leader for the clusterzookeeper.connect
Kafka config doesn't specify a chroot env for your Kafka cluster i.e. it's just host:port
and not host:port/path
I used the AdminClient api.
Properties properties = new Properties(); properties.put("bootstrap.servers", "localhost:9092"); properties.put("connections.max.idle.ms", 10000); properties.put("request.timeout.ms", 5000); try (AdminClient client = KafkaAdminClient.create(properties)) { ListTopicsResult topics = client.listTopics(); Set<String> names = topics.names().get(); if (names.isEmpty()) { // case: if no topic found. } return true; } catch (InterruptedException | ExecutionException e) { // Kafka is not available }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With