I\'m new to Kafka and am trying to use the AdminClient
API to manage the Kafka server running on my local machine. I have it setup exactly the same as in the quick
Sounds like your broker isn't healthy...
This code works fine
public class Main {
static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
properties.setProperty(AdminClientConfig.CLIENT_ID_CONFIG, "local-test");
properties.setProperty(AdminClientConfig.RETRIES_CONFIG, "3");
try (AdminClient client = AdminClient.create(properties)) {
final CreateTopicsResult res = client.createTopics(
Collections.singletonList(
new NewTopic("foo", 1, (short) 1)
)
);
res.all().get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("unable to create topic", e);
}
}
}
And I can see in the broker logs that the topic was created
I started kafka service with bitnami/kafka, and got exactly the same error. Try to start kafka by this version, it works: https://hub.docker.com/r/wurstmeister/kafka
$ docker run -d --name zookeeper-server --network app-tier \
-e ALLOW_ANONYMOUS_LOGIN=yes -p 2181:2181 zookeeper:3.6.2
$ docker run -d --name kafka-server --network app-tier --publish 9092:9092 \
--env KAFKA_ZOOKEEPER_CONNECT=zookeeper-server:2181 \
--env KAFKA_ADVERTISED_HOST_NAME=30.225.51.235 \
--env KAFKA_ADVERTISED_PORT=9092 \
wurstmeister/kafka
30.225.51.235 is ip address for the host machine.