无法创建新的KafkaAdminClient。

huangapple go评论81阅读模式
英文:

Failed to create new KafkaAdminClient

问题

I get the following error whenever trying to run my spring boot Kafka application.

2020-08-04 20:17:23.366 ERROR 2827 --- [main] o.springframework.kafka.core.KafkaAdmin: Could not create admin

org.apache.kafka.common.KafkaException: Failed to create new KafkaAdminClient
	at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:479) ~[kafka-clients-2.5.0.jar:na]
	at org.apache.kafka.clients.admin.Admin.create(Admin.java:71) ~[kafka-clients-2.5.0.jar:na]
	at org.apache.kafka.clients.admin.AdminClient.create(AdminClient.java:49) ~[kafka-clients-2.5.0.jar:na]
	at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:177) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at ai.kollie.kafka.KafkaApplication.main(KafkaApplication.java:19) [main/:na]
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${spring.kafka.bootstrap-servers
	at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:59) ~[kafka-clients-2.5.0.jar:na]
	at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:48) ~[kafka-clients-2.5.0.jar:na]
	at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:439) ~[kafka-clients-2.5.0.jar:na]
	... 15 common frames omitted

Now, I have used spring.kafka.bootstrap-servers to set the server to localhost:9092 and following are my producer, consumer and topic configuration files respectively.

@Configuration
public class KafkaProducerConfig {

    @Value(value = "${spring.kafka.bootstrap-servers}")
    private String bootstrapAddress;
@EnableKafka
@Configuration
public class KafkaConsumerConfig {

    @Value(value = "${spring.kafka.bootstrap-servers}")
    private String bootstrapAddress;
@Configuration
public class KafkaTopicConfig {

    @Value(value = "${spring.kafka.bootstrap-servers}")
    private String bootstrapAddress;

    @Bean
    public KafkaAdmin kafkaAdmin() {
        Map<String, Object> configs = new HashMap<>();
        configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
...

Am I doing something wrong or overlooking something?

Update:

The previous error is resolved. Although, now I'm facing the following issue.

2020-08-06 01:30:02.895 INFO 4090 --- [main] o.a.kafka.common.utils.AppInfoParser: Kafka version: 2.5.0
2020-08-06 01:30:02.897 INFO 4090 --- [main] o.a.kafka.common.utils.AppInfoParser: Kafka commitId: 66563e712b0b9f84
2020-08-06 01:30:02.897 INFO 4090 --- [main] o.a.kafka.common.utils.AppInfoParser: Kafka startTimeMs: 1596657602893
2020-08-06 01:30:32.934 ERROR 4090 --- [main] o.springframework.kafka.core.KafkaAdmin: Could not configure topics

org.springframework.kafka.KafkaException: Timed out waiting to get existing topics; nested exception is java.util.concurrent.TimeoutException
	at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$4(KafkaAdmin.java:254) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at java.base/java.util.HashMap.forEach(HashMap.java:1341) ~[na:na]
	at org.springframework.kafka.core.KafkaAdmin.checkPartitions(KafkaAdmin.java:233) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.kafka.core.KafkaAdmin.addTopicsIfNeeded(KafkaAdmin.java:219) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:189) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.

<details>
<summary>英文:</summary>

I get the following error whenever trying to run my spring boot Kafka application.

2020-08-04 20:17:23.366 ERROR 2827 --- [ main] o.springframework.kafka.core.KafkaAdmin : Could not create admin

org.apache.kafka.common.KafkaException: Failed to create new KafkaAdminClient
at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:479) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.Admin.create(Admin.java:71) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.AdminClient.create(AdminClient.java:49) ~[kafka-clients-2.5.0.jar:na]
at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:177) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at ai.kollie.kafka.KafkaApplication.main(KafkaApplication.java:19) [main/:na]
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${spring.kafka.bootstrap-servers
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:59) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:48) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:439) ~[kafka-clients-2.5.0.jar:na]
... 15 common frames omitted


Now, I have used `spring.kafka.bootstrap-servers` to set the server to `localhost:9092` and following are my producer, consumer and topic configuration files respectively.

@Configuration
public class KafkaProducerConfig {

@Value(value = &quot;${spring.kafka.bootstrap-servers}&quot;)
private String bootstrapAddress;

@EnableKafka
@Configuration
public class KafkaConsumerConfig {

@Value(value = &quot;${spring.kafka.bootstrap-servers}&quot;)
private String bootstrapAddress;

@Configuration
public class KafkaTopicConfig {

@Value(value = &quot;${spring.kafka.bootstrap-servers&quot;)
private String bootstrapAddress;

@Bean
public KafkaAdmin kafkaAdmin() {
    Map&lt;String, Object&gt; configs = new HashMap&lt;&gt;();
    configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);

...

Am I doing something wrong or overlooking something?

**Update:**

The previous error is resolved. Although, now I&#39;m facing the following issue.

2020-08-06 01:30:02.895 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.5.0
2020-08-06 01:30:02.897 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: 66563e712b0b9f84
2020-08-06 01:30:02.897 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1596657602893
2020-08-06 01:30:32.934 ERROR 4090 --- [ main] o.springframework.kafka.core.KafkaAdmin : Could not configure topics

org.springframework.kafka.KafkaException: Timed out waiting to get existing topics; nested exception is java.util.concurrent.TimeoutException
at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$4(KafkaAdmin.java:254) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at java.base/java.util.HashMap.forEach(HashMap.java:1341) ~[na:na]
at org.springframework.kafka.core.KafkaAdmin.checkPartitions(KafkaAdmin.java:233) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.addTopicsIfNeeded(KafkaAdmin.java:219) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:189) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at ai.kollie.kafka.KafkaApplication.main(KafkaApplication.java:19) [main/:na]
Caused by: java.util.concurrent.TimeoutException: null
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:108) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:272) ~[kafka-clients-2.5.0.jar:na]
at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$4(KafkaAdmin.java:236) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
... 16 common frames omitted

I have the created the topics that the application is using by creating ``NewTopic`` beans as follows:

@Bean
public NewTopic userTestTopic() {
return TopicBuilder.name("test-user")
.partitions(1)
.replicas(3)
.build();
}

@Bean
public NewTopic employeeTestTopic() {
	return TopicBuilder.name(&quot;test-employee&quot;)
			.partitions(1)
			.replicas(3)
			.build();
}
Both the sides could communicate before despite of the previous error but cannot now. The terminal just lists out all the configs and stops, saying ``Close timed out with 1 pending requests to coordinator, terminating client connections``. How do I resolve this?

</details>


# 答案1
**得分**: 1

Caused by: org.apache.kafka.common.config.ConfigException: bootstrap.servers 中的 URL 无效: ${spring.kafka.bootstrap-servers}
您缺少了闭合的 `}`。

@Value(value = "${spring.kafka.bootstrap-servers}")
private String bootstrapAddress;

<details>
<summary>英文:</summary>

&gt;Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${spring.kafka.bootstrap-servers


You are missing the closing `}`.

    @Value(value = &quot;${spring.kafka.bootstrap-servers&quot;)
    private String bootstrapAddress;


</details>



huangapple
  • 本文由 发表于 2020年8月4日 23:05:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63249732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定