gpt4 book ai didi

java - 如果启动时没有代理可用,Spring Integration Kafka 3.0.1 -> 3.1.2 测试现在无法启动

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:16 25 4
gpt4 key购买 nike

当一个项目从Springboot 2.0升级到2.1时,我们也将spring-kafka-integration从3.0.1升级到3.2.1。在这样做的过程中,我们的测试现在都无法启动,原因是:

org.apache.kafka.clients.NetworkClient   : [Consumer clientId=consumer-1, groupId=x] Connection to node -1 could not be established. Broker may not be available.
org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-1, groupId=x] Connection to node -1 could not be established. Broker may not be available.
org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-1, groupId=x] Connection to node -1 could not be established. Broker may not be available.
...
org.springframework.context.ApplicationContextException: Failed to start bean 'eventInboundFlow.kafka:message-driven-channel-adapter#0'; nested exception is org.apache.kafka.common.errors.TimeoutException: Timeout expired while fetching topic metadata

我们的构建机器没有本地运行的 Kafka,使用 EmbeddedKafkaBroker 的测试使用自定义 JUnit5 扩展来运行,该扩展在测试之间停止/启动容器监听器(同时寻找所有分区和主题最新的,以防止测试意外泄漏消息以在以后的测试中打破预期)。虽然比 @DirtiesContext 快得多,但它不会像 @EmbddedKafka 注释那样在配置期间将自身注入(inject)上下文。

在以前的版本中,这不是问题;在配置扩展并启动代理时,我们会看到一些关于无法连接的日志消息,但随后一切正常。

在新版本中,上下文无法完全启动(自定义扩展甚至没有机会运行)。查看属性,我能看到的关于启动失败的唯一设置是 spring.kafka.admin.fail-fast,但默认情况下为 FALSE,我们不会更改它。

将其与启动项目本身作为 springboot 应用程序进行比较,我看到的第一个区别是容器在作为应用程序运行时在自己的线程中启动,但在 main/作为测试运行时的 Test Worker 线程。在以前的版本中,测试还在自己的线程中启动容器。

是否了解为什么现在的测试表现不同?或者是否有办法将其配置为使它们脱离主线程?

最佳答案

将容器属性 missingQueuesFatal 设置为 false

参见 Spring for Apacher Kafka 2.2. What's new .

A new container property (missingTopicsFatal) has been added. See Using KafkaMessageListenerContainer for more information.

Starting with version 2.2, a new container property called missingTopicsFatal has been added (default: true). This prevents the container from starting if any of the configured topics are not present on the broker. It does not apply if the container is configured to listen to a topic pattern (regex). Previously, the container threads looped within the consumer.poll() method waiting for the topic to appear while logging many messages. Aside from the logs, there was no indication that there was a problem. To restore the previous behavior, you can set the property to false.

将该属性设置为 false 将禁用检查。

关于java - 如果启动时没有代理可用,Spring Integration Kafka 3.0.1 -> 3.1.2 测试现在无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55976911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com