There is no problem everything is ok on the terminals; i can send message via producer and receive it on consumer. But am not able to get same result via KafkaProducer java.
kafka:
image: 'bitnami/kafka:latest'
ports:
- "9092:9092"
- '9093:9093'
environment:
- KAFKA_BROKER_ID=1
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT
depends_on:
- zookeeper
zookeeper:
image: 'bitnami/zookeeper:latest'
ports:
- "2181:2181"
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
microservicesnet:
driver: bridge
Java code for KafkaProducer
public Producer<String, String> setUpKafkaPropoerties() {
Properties properties = new Properties();
//Update the IP adress of Kafka server here//
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9093");
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
StringSerializer.class);
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
StringSerializer.class);
properties.put("acks", "all");
properties.put("retries", 0);
properties.put("linger.ms", 0);
properties.put("partitioner.class",
"org.apache.kafka.clients.producer.internals.DefaultPartitioner");
properties.put("request.timeout.ms", 30000);
properties.put("timeout.ms", 30000);
properties.put("max.in.flight.requests.per.connection", 5);
properties.put("retry.backoff.ms", 5);
//Instantiate Producer Object
Producer<String, String> producer = new KafkaProducer<String, String>(properties);
return producer;
ERROR LOG:
2022-05-21 14:55:21.240 WARN 1 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9093) could not be established. Broker may not be available.
2022-05-21 14:55:21.240 WARN 1 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Bootstrap broker localhost:9093 (id: -1 rack: null) disconnected
2022-05-21 14:55:22.254 WARN 1 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9093) could not be established. Broker may not be available.