2 回答
TA贡献1807条经验 获得超9个赞
听起来您的经纪人不健康...
该代码可以正常工作
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);
}
}
}
而且我可以在代理日志中看到该主题已创建
TA贡献1860条经验 获得超8个赞
我用bitnami / kafka启动了kafka服务,并得到了完全相同的错误。尝试通过此版本启动kafka,它可以正常工作: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是主机的IP地址。
添加回答
举报