My microservice application throws a continuous error while trying to use Kafka. I am testing several configuration possibilities and I cannot understand why it doesn’t work.
Configuration of microservice:
# Kafka general configuration
spring.kafka.bootstrap-servers=localhost:9092
docker-compose.yml
kafka:
image: wurstmeister/kafka:2.13-2.7.0
ports:
- "9092:9093"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9093
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
Per my understanding:
- My application connects to
localhost:9092
docker-compose.yml
has included mappinghost:container
ports which is9092
(host where we connect):9093
(port which we access within container)
Expected result:
Kafka port is correctly mapped – application uses localhost:9092
which is mapped on port 9093
on Kafka therefore allowing us to use it properly
Actual result:
An error is thrown
2024-06-01T14:13:11.354+02:00 WARN 9560 --- [event] [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-example_group-1, groupId=example_group] Connection to node 1001 (localhost/127.0.0.1:9093) could not be established. Broker may not be available.
2024-06-01T14:13:12.282+02:00 INFO 9560 --- [event] [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-example_group-1, groupId=example_group] Node 1001 disconnected.
If I use one port everywhere, it works correctly. But I want to test out other possibilites.