My SpringBoot app is running on localhost, but I want it to connect with Kafka that is downloaded on remote server e.g. 123.45.6.789. I am able to produce and consume messages from the mobaxTerm terminal but my springboot app is not able to connect with kafka due to this error
WARN[0;39m [35m18788[0;39m [2m---[0;39m [2m[ntainer#0-0-C-1][0;39m
[36morg.apache.kafka.clients.NetworkClient [0;39m [2m:[0;39m [Consumer
clientId=consumer-fooss-1, groupId=fooss] Connection to node -1
(localhost/127.0.0.1:9092) could not be established.
Broker may not be available.
my application.properties file
kafka.bootstrapAddress=123.45.6.789:9092
kafka.groupId=fooss
kafka.topicName=topicMyTopic
server.properties file
broker.id=0
listeners=PLAINTEXT://123.45.6.789:9092
advertised.listeners=PLAINTEXT://123.45.6.789:9092
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=123.45.6.789:2181
zookeeper.connection.timeout.ms=18000
I know that there are other questions related to this, and i have read them but i could not find answer to my problem... so please help me in understanding this...
my question is, Why am i getting an error that says the connection was failed on localhost, even though i am trying to connect to 123.45.6.789 as mentioned in application.properties file? and how can I resolve it?
CodePudding user response:
Spring boot defaults to using localhost:9092, and it's unclear how you're using kafka.bootstrapAddress
in your code.
The correct property for automatic configuration is spring.kafka.bootstrap-servers
https://docs.spring.io/spring-boot/docs/current/reference/html/messaging.html#messaging.kafka