Kafka pollable consumers lose ConsumerFactory listeners when max.poll.records is greater than one
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
調査の方向性
Start by reading Spring Integration Kafka's KafkaMessageSource, where the issue says a replacement DefaultKafkaConsumerFactory is created when max.poll.records is missing or greater than 1. Check how that replacement handles the original factory's listeners, then run the linked reproducer's SpringCloudStreamPollableKafkaMetricsTests to compare the two configurations. Done means the listener is preserved and native kafka.consumer.* meters register with either setting.
索引モデルが issue の本文から書いたものです。
説明
Thanks for considering raising a Spring Cloud Stream issue.
Describe the issue
Kafka pollable consumers lose ConsumerFactory.Listener instances when max.poll.records is not set to 1.
This prevents Micrometer native Kafka metrics from being registered for the consumer created by KafkaMessageSource.
The issue is visible through Spring Cloud Stream, but the suspected root cause appears to be in Spring Integration Kafka's KafkaMessageSource.
To Reproduce
The issue can be reproduced with this standalone demo application:
https://github.com/ferblaca/demoStreamPollable
The reproducer uses:
- Spring Boot 4.1.2;
- Spring Cloud Stream 5.0.4;
- the Spring Cloud Stream Kafka binder;
- a real Kafka broker started with Testcontainers;
- two Spring Cloud Stream pollable consumers.
Steps:
-
Clone the repository:
git clone https://github.com/ferblaca/demoStreamPollable.git cd demoStreamPollable -
Run the reproducer test:
./mvnw -B -Dtest=SpringCloudStreamPollableKafkaMetricsTests test -
Review the test implementation:
src/test/java/com/example/demoStreamPollable/SpringCloudStreamPollableKafkaMetricsTests.java -
The test creates two pollable bindings:
pollableInput-in-0 pollableInputMaxOne-in-0 -
The first binding is configured with:
spring.cloud.stream.kafka.bindings.pollableInput-in-0.consumer.configuration.max.poll.records=10The test publishes and consumes a real Kafka message through
PollableMessageSource, then verifies that no meter whose name starts withkafka.consumeris registered. -
The second binding is configured with:
spring.cloud.stream.kafka.bindings.pollableInputMaxOne-in-0.consumer.configuration.max.poll.records=1The test publishes and consumes another real Kafka message through a second
PollableMessageSource, then verifies that a meter whose name starts withkafka.consumeris registered.
The test passes and demonstrates the different behavior between both configurations.
Version of the framework
- Spring Boot 4.1.2
- Spring Cloud Stream 5.0.4
- Java 25
- Kafka broker: Testcontainers
apache/kafka-native:3.8.0
Expected behavior
When KafkaMessageSource creates a replacement consumer factory, it should preserve the behavior of the supplied factory, including registered ConsumerFactory.Listener instances such as:
MicrometerConsumerListener
Native kafka.consumer.* metrics should be registered regardless of whether max.poll.records is explicitly set to 1.
Screenshots
Not applicable.
Additional context
Spring Cloud Stream's Kafka binder creates the consumer factory and invokes the registered ClientFactoryCustomizer before creating the pollable source.
The relevant flow is:
KafkaMessageChannelBinder
-> createPolledConsumerResources(...)
-> createKafkaConsumerFactory(...)
-> ClientFactoryCustomizer.configure(consumerFactory)
-> new KafkaMessageSource<>(consumerFactory, consumerProperties)
The customizer adds a MicrometerConsumerListener to the original DefaultKafkaConsumerFactory.
However, when max.poll.records is missing or greater than 1, KafkaMessageSource forces it to 1 by creating a new DefaultKafkaConsumerFactory.
The replacement factory copies the configuration and deserializers, but does not copy the listeners from the original factory. Consequently, the MicrometerConsumerListener is lost before the actual Kafka consumer is created.
The current behavior also logs:
max.poll.records' has been forced from 10 to 1, to avoid having to seek after each record
As a workaround, applications can configure max.poll.records=1 for each pollable Kafka binding. This prevents KafkaMessageSource from creating the replacement factory, but it exposes an internal implementation detail to applications.
Could you please confirm whether this issue should be fixed in:
- Spring Integration Kafka, in
KafkaMessageSource; - Spring Cloud Stream's Kafka binder;
- or both?
The suspected fix is to copy the ConsumerFactory.Listener instances when KafkaMessageSource creates the replacement DefaultKafkaConsumerFactory. The reproducer is intentionally implemented through Spring Cloud Stream so that the behavior can be verified using a real PollableMessageSource and the Kafka binder, but the suspected defect appears to belong to Spring Integration Kafka.
- 主要言語
- Java
- スター
- 1.1k
- フォーク
- 651
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 8
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
spring-cloud/spring-cloud-stream のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
spring-cloud/spring-cloud-stream#3332 ·
メンテナーはふだん 1 日以内に返信
-
Kafka binder health-check consumer failures return DOWN without logging the exception対応中かも @Sanskar121543 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
spring-cloud/spring-cloud-stream#3329 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
spring-cloud/spring-cloud-stream#3316 ·
メンテナーはふだん 1 日以内に返信
-
StreamBridge removing BindingProperties leads to wrong destination in ProvisioningProvider再び着手できるかも @olegz が 60 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug
spring-cloud/spring-cloud-stream#3257 · コメント 6 件 · リアクション 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
StreamBridge's hashProducerProperties produces hash collisions across different binding names, causing Partition key cannot be null再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
spring-cloud/spring-cloud-stream#3242 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
spring-cloud/spring-cloud-stream の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
[Bug]: NetworkPolicyOperator removes finalizers added by the EKS network policy controller, which adds them back再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンbug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
strimzi/strimzi-kafka-operator#13360 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
bug javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
NationalSecurityAgency/ghidra#10149 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
yegor256/antlr2ebnf-maven-plugin#155 ·
メンテナーはふだん 1 日以内に返信