0

I used spring-cloud-starter stream-kafka to connect to kafka, version 2.1.2. When I started the service in the k8s cluster, the first few could connect successfully. The following errors occurred in subsequent projects:

org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.errors.TimeoutException: Timeout expired while fetching topic metadata
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:893)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.zynn.service.module.user.ZynnServiceModuleUserApplication.main(ZynnServiceModuleUserApplication.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

I need some help. Any Suggestions are welcome. Thanks

hero-zh
  • 45
  • 7
  • Without any details about your environment it is hard to tell, so consider googling _"org.apache.kafka.common.errors.TimeoutException: Timeout expired while fetching topic metadata"_. SSL? Wrong URL/port? etc. There are many references and solutions, so perhaps it could help. – Oleg Zhurakousky Apr 23 '19 at 05:51
  • Without SSL on, this is the default kafka that I just installed, and some of the projects started successfully, which is the point of my confusion – hero-zh Apr 23 '19 at 06:26
  • Perhaps you can create a sample project that reproduces the issue and push it to Github so we can take a look? – Oleg Zhurakousky Apr 23 '19 at 07:28
  • I'm sorry I can't do that, because I don't know if it's going to work or not, it seems random, but I found this: https://stackoverflow.com/questions/49421979/spring-cloud-kafka-stream-unable-to-create-producer-config-error – hero-zh Apr 23 '19 at 07:37
  • As mentioned before, if the project is running in a k8s cluster and kafka is running outside of the docker container, will that be the problem? – hero-zh Apr 23 '19 at 07:39
  • Yes it is possible. What the exception above means is that you have some type of network connectivity issues, so effectively it's outside of framework scope. – Oleg Zhurakousky Apr 23 '19 at 07:41

1 Answers1

0

I have found the reason for the error. I must configure item ”spring.kafka.bootstrap-servers” and item “spring.cloud.stream.kafka.binder.brokers”, otherwise I will create a connection pointing to localhost:9092,This connection is impossible to connect to, so after I configure it simultaneously, the project works

hero-zh
  • 45
  • 7