I have created a cluster in AWS MSK and created a topic. I can produce and consume events from the EC2 instance in the same VPC as the cluster. The specific use case is that I want to consume events using Java. The KafkaClient AWS SDK doesn’t have any methods for event consumption, so I can’t use it here. I cannot directly pass the bootstrap servers in the Properties() while creating a KafkaConsumer as the IPs are internal to the VPC.
I have gone through this AWS guide on ways to connect to MSK but not sure which method would be suitable for this exact use case. I have tried out a few ways-
Setting advertised.listerners to the public IP of the instance. But still kept getting this error while listing topics after creating KafkaConsumer-
Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Opening relevant ports (9092 for PLAINTEXT in my case) in the security group inbound rules. I was still getting a
Connection refused
error while trying to telnet to port 9092 after doing this.
My question is will any of the above work and I'm just missing something else here which can solve this. Or will the above methods won’t work?
My end goal here is to consume events from MSK Cluster using Java.