How to check whether Kafka Server is running?

后端 未结 9 1551
无人及你
无人及你 2020-12-08 03:46

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

相关标签:
9条回答
  • 2020-12-08 04:44

    For Linux, "ps aux | grep kafka" see if kafka properties are shown in the results. E.g. /path/to/kafka/server.properties

    0 讨论(0)
  • 2020-12-08 04:44

    The good option is to use AdminClient as below before starting to produce or consume the messages

    private static final int ADMIN_CLIENT_TIMEOUT_MS = 5000;           
     try (AdminClient client = AdminClient.create(properties)) {
                client.listTopics(new ListTopicsOptions().timeoutMs(ADMIN_CLIENT_TIMEOUT_MS)).listings().get();
            } catch (ExecutionException ex) {
                LOG.error("Kafka is not available, timed out after {} ms", ADMIN_CLIENT_TIMEOUT_MS);
                return;
            }
    
    0 讨论(0)
  • 2020-12-08 04:47

    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:

    • You're running ZooKeeper on the default port (2181) on localhost, and that localhost is the leader for the cluster
    • Your zookeeper.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
    0 讨论(0)
提交回复
热议问题