我用一个简单的测试创建了一个新的 spring boot 项目:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExampleApplicationTests {
@Test
public void contextLoads() {
}
}
当我运行此测试时,它成功了。但是,如果我将任何方法注释@KafkaListener
注释添加到任何服务:
@KafkaListener(topics = "test", groupId = "v-group")
public void test(){
log.info("test");
}
并运行测试,它有时会工作并引发异常:
Caused by: 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