im trying to deploy kafka kraft by docker-compose with bitnami image 3.3.1 and 3 nodes.
- but nodes disconnect frequently and i cant produce or consume messages with my python client.
get docker log like this:
INFO [RaftManager nodeId=2] Node 1 disconnected.
- and get error with
kafka-console-producer.sh
like this:
Got error produce response with correlation id 8 on topic-partition testad8-2, retrying (0 attempts left). Error: NOT_LEADER_OR_FOLLOWER (org.apache.kafka.clients.producer.internals.Sender)
WARN [Producer clientId=console-producer] Received invalid metadata error in produce request on partition testad8-2 due to org.apache.kafka.common.errors.NotLeaderOrFollowerException: For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.. Going to request metadata update now (org.apache.kafka.clients.producer.internals.Sender)
ERROR Error when sending message to topic testad8 with key: null, value: 9 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.NotLeaderOrFollowerException: For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.
WARN [Producer clientId=console-producer] Received invalid metadata error in produce request on partition testad8-2 due to org.apache.kafka.common.errors.NotLeaderOrFollowerException: For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.. Going to request metadata update now (org.apache.kafka.clients.producer.internals.Sender)
- use
kafka-console-consumer.sh
sometimes work and consume well but sometimes not working.
and this is my docker-compose and broker configs (im using .env file):
broker1:
image: bitnami/kafka:3.4.0-debian-11-r11
hostname: broker1
container_name: broker1
ports:
- "9092:9092"
- "9093:9093"
environment:
KAFKA_ENABLE_KRAFT: 1
ALLOW_PLAINTEXT_LISTENER: 1
KAFKA_KRAFT_CLUSTER_ID: ${CLUSTER_ID}
KAFKA_NODE_ID: 1
KAFKA_BROKER_ID: 1
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://broker1:29092,PLAINTEXT_HOST://${EXTERNAL_IP}:9092
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@${EXTERNAL_IP}:9093,2@${EXTERNAL_IP}:9083,3@${EXTERNAL_IP}:9073,4@${EXTERNAL_IP}:9063
KAFKA_CFG_LISTENERS: PLAINTEXT://localhost:29092,CONTROLLER://:9093,PLAINTEXT_HOST://:9092
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CFG_PROCESS_ROLES: broker,controller
KAFKA_CFG_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_LOG_DIRS: /bitnami/kafka/kafka-logs
i tried different solution like change image version or python client but still not work correctly. and i run this on a kafka cluster with kubernetes and work well.
notice: with 1 partition on topic everything works well but on multi partition i got these problem and python client consumer not listening