简体   繁体   中英

How to detect unreachable brokers Kafka and reconnect?

scheme: 2 broker -2 hosts Java clients - org.apache.kafka.clients.producer.KafkaProducer or org.apache.kafka.clients.consumer.KafkaConsumer Bootsrap servers property contain 2 ip address (2 brokers) Zookeeper - distributed coordinator

Invocation Method at constructor org.apache.kafka.clients.ClientUtil#parseAndValidateAddresses check only network up servers without validate instance (check broken state server or doesn't start)

By default, Zookeeper keep tracks of all nodes connected and reachable brokers. You can query ZK to see what nodes are connected at present.

# Connect to ZooKeeper
bin/zookeeper-shell.sh  localhost:2181
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is disabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
    >> ls /brokers/ids
        [1, 2, 3]
    >> ls /brokers/topics
        [myTopic, __consumer_offsets]
    >> get /brokers/ids/0
    Node does not exist: /brokers/ids/0
    >> get /brokers/ids/1
    {"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT","SSL":"SSL"},"endpoints":["PLAINTEXT://172.31.4.17:9092","SSL://18.216.252.106:9093"],"jmx_port":9999,"host":"172.31.4.17","timestamp":"1522349056258","port":9092,"version":4}
    cZxid = 0x3000005f3
    ctime = Thu Mar 29 18:44:16 UTC 2018
    mZxid = 0x3000005f3
    mtime = Thu Mar 29 18:44:16 UTC 2018
    pZxid = 0x3000005f3
    cversion = 0
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x2625d127c0b0003
    dataLength = 234
    numChildren = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM