kafka java consumer can't get data

The kafka server installed on the cloud server cannot send messages or obtain data when accessed by local java code.

An exception is thrown when sending a message:

Exception in thread "main" Failed to send requests for topics test with correlation ids in [0,12]
kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.

By looking at the kafka configuration, I found that there is an attribute: advertised.host.name. The remarks in the official documentation indicate that the value of this field is used by producers and consumers. If not set, it will take the value of host.name, which is localhost by default. Think about it, if the producer gets the value of localhost and only sends a message locally, it will inevitably report an error (because there is no kafka server locally).

In the servier.properties under kafka's config, the configuration property advertised.host.name is set to the server IP address. After testing, the message was sent smoothly.

When configuring the producer, metadata.broker.list will be set to the IP and address of the kafka server. But this is only to obtain some meta information, and subsequent messages will be sent according to the obtained meta information, and in the obtained meta information, since the advertised.host.name is defaulted to localhost, the local will of course send the message to the local, the result cause problems.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325983024&siteId=291194637