I am running kafka on ec2 instance. So amazon ec2 instance has two ips one is internal ip and second one is for external use.
I created producer from local machine, but it redirect to internal ip and give me connection unsuccessful error. Can anybody help me to configure kafka on ec2 instance, so that I can run producer from local machine. I am tried many combinations but didn't work.
In order to access Kafka Brokers from outside the cluster, an additional listener and advertised listener must be configured. Additionally, a specific service per kafka pod will be created. There are two ways of configuring external access. Using LoadBalancer services or using NodePort services.
Default port By default, the Kafka server is started on port 9092 . Kafka uses ZooKeeper, and hence a ZooKeeper server is also started on port 2181 . If the current default ports don't suit you, you can change either by adding the following in your build.
In the Kafka FAQ (updated for new properties) you can read:
When a broker starts up, it registers its ip/port in ZK. You need to make sure the registered ip is consistent with what's listed in
bootstrap.servers
in the producer config. By default, the registered ip is given byInetAddress.getLocalHost.getHostAddress()
. Typically, this should return the real ip of the host. However, sometimes (e.g., in EC2), the returned ip is an internal one and can't be connected to from outside. The solution is to explicitly set the host ip and port to be registered in ZK by setting theadvertised.listeners
property inserver.properties
.
I solved this problem, by setting advertised.host.name
in server.properties
and metadata.broker.list
in producer.properties
to public IP address and host.name
to 0.0.0.0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With