【问题标题】:Spring Cloud Stream Kafka consumer app, AdminClient is called for no reasonSpring Cloud Stream Kafka消费者应用,AdminClient被无故调用
【发布时间】:2023-02-08 12:01:01
【问题描述】:

请问有关 Spring Cloud Stream Kafka 的小问题。

我有一个非常简单直接的消费者。 它只是消费,不产生消息,主题已经存在,我不需要创建主题。

@SpringBootApplication
public class StreamReactiveConsumerApplication implements CommandLineRunner {

    private static final Logger log = LoggerFactory.getLogger(StreamReactiveConsumerApplication.class);

    public static void main(String... args) {
        new SpringApplicationBuilder(StreamReactiveConsumerApplication.class).web(WebApplicationType.NONE).run(args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.warn("Remember about calling <.subscribe()> at the end of your Consumer<Flux> bean!");
        log.warn("Remember about finishing the span manually before calling subscribe!");
    }

    @Bean
    Consumer<Flux<Message<String>>> channel(Tracer tracer, ObservationRegistry observationRegistry) {
        return flux -> flux.doOnNext(msg -> log.info("<ACCEPTANCE_TEST> <TRACE:{}> Hello from consumer",
                tracer.currentSpan().context().traceId())).subscribe();
    }

}

然而在应用程序启动时,我看到了来自管理客户端的交互,请查看下面的日志:

2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.i.c.PublishSubscribeChannel : Channel 'stream-reactive-consumer.errorChannel' has 1 subscriber(s).
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.i.endpoint.EventDrivenConsumer : started bean '_org.springframework.integration.errorLogger'
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.c.s.binder.DefaultBinderFactory : Creating binder: kafka
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.c.s.binder.DefaultBinderFactory : Constructing binder child context for kafka
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.s.c.s.binder.DefaultBinderFactory : Caching the binder: kafka
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.a.k.c.admin.AdminClientConfig : AdminClientConfig values:

[bunch of values...]

2023-02-06 10:25:24 [stream-reactive-consumer,,] o.a.kafka.common.utils.AppInfoParser : Kafka version: 3.3.1
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: e23c59d00e687ff5
2023-02-06 10:25:24 [stream-reactive-consumer,,] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1675650324403

如您所见,该应用正在调用管理客户端:

2023-02-06 10:25:24 [stream-reactive-consumer,,] o.a.k.c.admin.AdminClientConfig : AdminClientConfig values:

我可以问一下为什么消费者专用应用程序依赖管理员吗? 同样,我没有制作任何东西,也没有创建任何主题。

没有这个管理客户端有没有办法消费,请禁用这个管理客户端?

谢谢

【问题讨论】:

  • 您使用的是什么版本?这是去年夏天修复的... github.com/spring-cloud/spring-cloud-stream/issues/2486
  • 我使用的是最新的 SpringBoot 3.0.2 + Spring Cloud 2022.0.1,它们都是最新的。我查看了相关的 SO 和 Github 问题,虽然我在启动我的应用程序时确实看到了 Admin Client 交互,但我只看到一次,它不会重复。请问我做错了什么?
  • 我建议在调试器中运行并在两个 Admin.create() 方法中设置一个断点以查看它是从哪里调用的。

标签: java spring-boot apache-kafka spring-cloud-stream


【解决方案1】:

正如@Gary Russell 所建议的那样,该错误已修复,并且确实不会在启动时看到仅消费者应用程序的管理客户端。

就我而言,这是由于多种原因造成的:

1 - How can I configure a Spring Cloud Stream (Kafka) application to autocreate the topics in Confluent Cloud?

spring.cloud.stream.kafka.binder.autoCreateTopics 属性默认设置为 true,这将“触发 Admin Client”

我确实将它设置为 false,但由于这个问题:https://github.com/spring-cloud/spring-cloud-stream/issues/2644 在本机上运行时,该属性未被考虑在内。

确保该属性为假,并按照 Gary 的建议设置断点是正确的解决方案(支持他所说的)

【讨论】:

    猜你喜欢
    • 2016-06-21
    • 2017-06-22
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 2021-12-30
    • 2022-12-22
    • 2018-03-28
    • 1970-01-01
    相关资源
    最近更新 更多