kafka AdminClient无法在已部署的环境中工作

时间:2018-06-18 13:31:01

标签: apache-kafka spring-kafka

我正在使用spring kafka连接到kafka并检查kafka服务器的状态,我正在使用org.apache.kafka.clients.admin.AdminClient。它在我的本地工作正常但是当我部署到QA环境时,它没有启动,抱怨无法创建AdminClient bean。我的猜测是AdminClient将使用任何特定的端口,这在QA环境中是不会打开的。

有人知道是否是这种情况以及KafkaAdmin连接到哪个端口?没有KafkaAdmin的春天kafka似乎工作正常。

1 个答案:

答案 0 :(得分:1)

没有什么特别的。 KafkaAdmin基于一些提供的配置:

/**
 * Create an instance with an {@link AdminClient} based on the supplied
 * configuration.
 * @param config the configuration for the {@link AdminClient}.
 */
public KafkaAdmin(Map<String, Object> config) {

此配置确实用于AdminClient内部实例:

 adminClient = AdminClient.create(this.config);

那个是基于AdminClientConfig

/**
 * Create a new AdminClient with the given configuration.
 *
 * @param conf The configuration.
 * @return The new KafkaAdminClient.
 */
public static AdminClient create(Map<String, Object> conf) {
    return KafkaAdminClient.createInternal(new AdminClientConfig(conf), null);
}

因此,您可以在AdminClient中找到AdminClientConfig连接所需的所有属性。并注意默认情况下主机/端口与任何其他客户端完全相同:

public static final String BOOTSTRAP_SERVERS_CONFIG = CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG;

private static final String BOOTSTRAP_SERVERS_DOC = CommonClientConfigs.BOOTSTRAP_SERVERS_DOC;

因此,当您创建KafkaAdmin实例时,您应该至少提供bootstrap.servers属性。

同样很高兴看到在上述环境中发生的堆栈跟踪。