Skip to content

Conversation

sobychacko
Copy link
Contributor

Fixes: #3814

Issue link: #3814

This commit upgrades the Apache Kafka client to 4.0.0 with the following changes:

  • Upgrade Kafka client dependencies to 4.0.0 in build.gradle

  • Remove ZooKeeper-based broker implementation as Kafka 4.0 fully transitions to KRaft mode

    • Delete EmbeddedKafkaZKBroker class and related tests
    • Remove ZooKeeper dependency
    • Refactor EmbeddedKafkaRule to use KRaft exclusively
    • Update KafkaClusterTestKit imports to use new packages
  • Update ConsumerRecords constructor calls to include the new required Map parameter

  • Add implementations for new Producer interface methods:

    • registerMetricForSubscription
    • unregisterMetricFromSubscription
  • Update KafkaStreamBrancher to use new split() and branch() methods

  • Remove deprecated partitioner classes from runtime hints

  • Remove deprecated sendOffsetsToTransaction method that used String consumerGroupId

  • Update BrokerAddress to use org.apache.kafka.server.network.BrokerEndPoint

  • Update DeserializationExceptionHandler to use new ErrorHandlerContext

The commit also includes test modifications to address limitations with static port assignments in KRaft mode and adjustments to replication factors in tests.

…ersion 4.0.0

Fixes: spring-projects#3814

Issue link: spring-projects#3814

This commit upgrades the Apache Kafka client to 4.0.0 with the following changes:

- Upgrade Kafka client dependencies to 4.0.0 in build.gradle
- Remove ZooKeeper-based broker implementation as Kafka 4.0 fully transitions to KRaft mode
  - Delete EmbeddedKafkaZKBroker class and related tests
  - Remove ZooKeeper dependency
  - Refactor EmbeddedKafkaRule to use KRaft exclusively
  - Update KafkaClusterTestKit imports to use new packages

- Update ConsumerRecords constructor calls to include the new required Map parameter
- Add implementations for new Producer interface methods:
  - registerMetricForSubscription
  - unregisterMetricFromSubscription

- Update KafkaStreamBrancher to use new split() and branch() methods
- Remove deprecated partitioner classes from runtime hints
- Remove deprecated sendOffsetsToTransaction method that used String consumerGroupId
- Update BrokerAddress to use org.apache.kafka.server.network.BrokerEndPoint
- Update DeserializationExceptionHandler to use new ErrorHandlerContext

The commit also includes test modifications to address limitations with static port assignments in KRaft mode
and adjustments to replication factors in tests.

Signed-off-by: Soby Chacko <[email protected]>
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just couple simple nit-picks.
This is really cool!
And change is not that bad: mostly tests adjustments because of new ctor for ConsumerRecords 😄

The removal of EmbeddedKafkaRule is a bit destructive. But who uses JUnit 4 these days!
So, or we revise it for KRaft or just bite a bullet.

The docs has to be changed as well.
That might be some effort, so consider to do that in the separate issue/PR.

Thanks

build.gradle Outdated
@@ -355,16 +355,14 @@ project ('spring-kafka-test') {
description = 'Spring Kafka Test Support'

dependencies {
implementation "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be api .
That's exactly how Java libraries are designed with Gradle.

@@ -84,22 +88,37 @@ public KafkaStreamBrancher<K, V> defaultBranch(Consumer<? super KStream<K, V>> c

/**
* Terminating method that builds branches on top of given {@code KStream}.
* Applies each predicate-consumer pair sequentially to create branches.
* If a default consumer exists, it will handle all records that don't match any predicates.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank lines in method Javadocs.

@artembilan artembilan merged commit 579ae6a into spring-projects:main Mar 24, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Apache Kafka client dependencies to version 4.0.0
2 participants