<div>
<p>The error message "connection to node -1 (localhost/127.0.0.1:9092) could not be established. broker may not be available." suggests that there is an issue connecting to the Kafka broker running on the local machine at port 9092.</p>
<p>There can be multiple reasons for this error: </p>
<ol>
<li>
<p><strong>Kafka broker not running</strong>: Make sure the Kafka server is up and running on the local machine. You can check if the broker is available by using the command line tool or by accessing the Kafka web UI.</p>
<p>For example, you can use the following command to check the status of the Kafka broker:</p>
<pre>bin/kafka-topics.sh --list --bootstrap-server localhost:9092</pre>
</li>
<li>
<p><strong>Incorrect broker configuration</strong>: Ensure that the connection parameters specified in your code are correct. Verify the hostname or IP address and the port number. For local development, the default configuration is often set to "localhost:9092".</p>
</li>
<li>
<p><strong>Firewall or network issues</strong>: Check if there are any firewall rules or network restrictions preventing the connection to the Kafka broker. Make sure that the necessary ports are open and accessible.</p>
</li>
<li>
<p><strong>Kafka dependencies not included</strong>: If you are using a Kafka client library, ensure that the necessary dependencies are included in your project. Check your project's dependency management configuration to verify if the required Kafka libraries are present.</p>
</li>
</ol>
</div>
Read more