Skip to content

Commit e95f041

Browse files
authored
GH-2391: Add Kraft Version of EmbeddedKafkaBroker
Resolves #2391 * Kraft by default; polishing. * Fix typo.
1 parent b212b4d commit e95f041

27 files changed

+1694
-815
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/testing.adoc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
The `spring-kafka-test` jar contains some useful utilities to assist with testing your applications.
55

6+
[[ekb]]
7+
== EmbeddedKafkaBroker
8+
9+
Two implementations are provided:
10+
11+
* `EmbeddedKafkaZKBroker` - legacy implementation which starts an embedded `Zookeeper` instance.
12+
* `EmbeddedKafkaKraftBroker` - (default) uses Kraft instead of `Zookeeper` in combined controller and broker modes (since 3.1)
13+
14+
There are several techniques to configure the broker as discussed in the following sections.
15+
616
[[ktu]]
717
== KafkaTestUtils
818

@@ -47,7 +57,7 @@ If this is not possible for some reason, note that the `consumeFromEmbeddedTopic
4757
Since it does not have access to the consumer properties, you must use the overloaded method that takes a `seekToEnd` boolean parameter to seek to the end instead of the beginning.
4858
====
4959

50-
A JUnit 4 `@Rule` wrapper for the `EmbeddedKafkaBroker` is provided to create an embedded Kafka and an embedded Zookeeper server.
60+
A JUnit 4 `@Rule` wrapper for the `EmbeddedKafkaZKBroker` is provided to create an embedded Kafka and an embedded Zookeeper server.
5161
(See xref:testing.adoc#embedded-kafka-annotation[@EmbeddedKafka Annotation] for information about using `@EmbeddedKafka` with JUnit 5).
5262
The following listing shows the signatures of those methods:
5363

@@ -72,6 +82,8 @@ public EmbeddedKafkaRule(int count, boolean controlledShutdown, String... topics
7282
public EmbeddedKafkaRule(int count, boolean controlledShutdown, int partitions, String... topics) { ... }
7383
----
7484

85+
NOTE: The `EmbeddedKafkaKraftBroker` is not supported with JUnit4.
86+
7587
The `EmbeddedKafkaBroker` class has a utility method that lets you consume for all the topics it created.
7688
The following example shows how to use it:
7789

@@ -162,7 +174,7 @@ You can use the same broker for multiple test classes with something similar to
162174
----
163175
public final class EmbeddedKafkaHolder {
164176
165-
private static EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaBroker(1, false)
177+
private static EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaZKBroker(1, false)
166178
.brokerListProperty("spring.kafka.bootstrap-servers");
167179
168180
private static boolean started;
@@ -216,7 +228,8 @@ In addition, these properties can be provided:
216228
- `spring.kafka.embedded.ports` - ports (comma-separated value) for every Kafka broker to start, `0` if random port is a preferred; the number of values must be equal to the `count` mentioned above;
217229
- `spring.kafka.embedded.topics` - topics (comma-separated value) to create in the started Kafka cluster;
218230
- `spring.kafka.embedded.partitions` - number of partitions to provision for the created topics;
219-
- `spring.kafka.embedded.broker.properties.location` - the location of the file for additional Kafka broker configuration properties; the value of this property must follow the Spring resource abstraction pattern.
231+
- `spring.kafka.embedded.broker.properties.location` - the location of the file for additional Kafka broker configuration properties; the value of this property must follow the Spring resource abstraction pattern;
232+
- `spring.kafka.embedded.kraft` - when false, use an `EmbeddedKafkaZKBroker` instead of an `EmbeddedKafkaKraftBroker`.
220233

221234
Essentially these properties mimic some of the `@EmbeddedKafka` attributes.
222235

@@ -283,6 +296,8 @@ public class KafkaStreamsTests {
283296

284297
Starting with version 2.2.4, you can also use the `@EmbeddedKafka` annotation to specify the Kafka ports property.
285298

299+
Starting with version 3.1; set the `kraft` property to `false` to use an `EmbeddedKafkaZKBroker` instead of an `EmbeddedKafkaKraftBroker`.
300+
286301
The following example sets the `topics`, `brokerProperties`, and `brokerPropertiesLocation` attributes of `@EmbeddedKafka` support property placeholder resolutions:
287302

288303
[source, java]

spring-kafka-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
This section covers the changes made from version 3.0 to version 3.1.
88
For changes in earlier version, see xref:appendix/change-history.adoc[Change History].
99

10-
[[x30-kafka-client]]
10+
[[x31-kafka-client]]
1111
=== Kafka Client Version
1212

1313
This version requires the 3.5.1 `kafka-clients`.
1414

15+
[[x31-ekb]]
16+
=== EmbeddedKafkaBroker
17+
18+
An additional implementation is now provided to use `Kraft` instead of Zookeeper.
19+
See <<ekb>> for more information.

0 commit comments

Comments
 (0)