You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_Note that [prior to v2.8.0](https://github.com/apache/kafka/pull/10174) Kafka core was inlining the Scala library, so you couldn't use a different Scala **patch** version than [what Kafka used to compile its jars](https://github.com/apache/kafka/blob/trunk/gradle/dependencies.gradle#L30)._
21
35
22
-
[Prior to v2.8.0](https://github.com/apache/kafka/pull/10174) Kafka core was inlining the Scala library, so you couldn't use a different Scala **patch** version than [what Kafka used to compile its jars](https://github.com/apache/kafka/blob/trunk/gradle/dependencies.gradle#L30)!
36
+
---
23
37
24
-
## Breaking change: new package name
38
+
## Upgrade notes
25
39
26
-
From v2.8.0 onwards package name has been updated to reflect the library group id (i.e. `io.github.embeddedkafka`).
40
+
### 4.0.0
27
41
42
+
Major changes:
43
+
-**Java 17+:** as [Kafka Server 4.x requires Java 17+](https://kafka.apache.org/40/documentation/compatibility.html), so does embedded-kafka even though Kafka Clients/Streams are still available for Java 11+.
44
+
-**Scala 2.13+**: Kafka is not compiled against Scala 2.12 anymore, so does embedded-kafka.
45
+
- embedded-kafka 4.0.0 starts a Kafka server in combined mode (broker and controller) and no more Zookeeper.
46
+
47
+
As a user, you'll have to change your code to use `controllerPort` instead of `zookeeperPort` in places you were doing so:
**Package name change:** from v2.8.0 onwards package name has been updated to reflect the library group id (i.e. `io.github.embeddedkafka`).
28
56
Aliases to the old package name have been added, along with a one-time [Scalafix rule](https://github.com/embeddedkafka/embedded-kafka-scalafix) to ensure the smoothest migration.
29
57
30
-
## embedded-kafka
58
+
---
59
+
60
+
## Usage
61
+
62
+
### embedded-kafka
31
63
32
-
### How to use
64
+
####How to use
33
65
34
66
* In your `build.sbt` file add the following dependency (replace `x.x.x` with the appropriate version): `"io.github.embeddedkafka" %% "embedded-kafka" % "x.x.x" % Test`
35
67
* Have your class extend the `EmbeddedKafka` trait.
@@ -52,11 +84,11 @@ class MySpec extends AnyWordSpecLike with Matchers with EmbeddedKafka {
52
84
}
53
85
```
54
86
55
-
* In-memory Zookeeper and Kafka will be instantiated respectively on port 6000 and 6001 and automatically shutdown at the end of the test.
87
+
* In-memory Kafka broker and controller (combined mode) will be instantiated respectively on port 6000 and 6001 and automatically shutdown at the end of the test.
56
88
57
-
### Use without the `withRunningKafka` method
89
+
####Use without the `withRunningKafka` method
58
90
59
-
A `EmbeddedKafka` companion object is provided for usage without extending the `EmbeddedKafka` trait. Zookeeper and Kafka can be started and stopped in a programmatic way. This is the recommended usage if you have more than one test in your file and you don't want to start and stop Kafka and Zookeeper on every test.
91
+
A `EmbeddedKafka` companion object is provided for usage without extending the `EmbeddedKafka` trait. Kafka can be started and stopped in a programmatic way. This is the recommended usage if you have more than one test in your file and you don't want to start and stop Kafka on every test.
60
92
61
93
```scala
62
94
classMySpecextendsAnyWordSpecLikewithMatchers {
@@ -76,9 +108,9 @@ class MySpec extends AnyWordSpecLike with Matchers {
76
108
77
109
Please note that in order to avoid Kafka instances not shutting down properly, it's recommended to call `EmbeddedKafka.stop()` in a `after` block or in a similar teardown logic.
78
110
79
-
### Configuration
111
+
####Configuration
80
112
81
-
It's possible to change the ports on which Zookeeper and Kafka are started by providing an implicit `EmbeddedKafkaConfig`
113
+
It's possible to change the ports on which Kafka broker and controller are started by providing an implicit `EmbeddedKafkaConfig`
// now a kafka broker is listening on actualConfig.kafkaPort
@@ -153,7 +185,7 @@ Those properties will be added to the broker configuration, be careful some prop
153
185
in case of conflict the `customBrokerProperties` values will take precedence. Please look at the source code to see what these properties
154
186
are.
155
187
156
-
### Utility methods
188
+
####Utility methods
157
189
158
190
The `EmbeddedKafka` trait provides also some utility methods to interact with the embedded kafka, in order to set preconditions or verifications in your specs:
Given implicits `Deserializer`s for each type and an `EmbeddedKafkaConfig` it is possible to use `withProducer[A, B, R] { your code here }` where R is the code return type.
171
203
172
204
For more information about how to use the utility methods, you can either look at the Scaladocs or at the tests of this project.
173
205
174
-
### Custom consumers
206
+
####Custom consumers
175
207
176
208
Given implicits `Serializer`s for each type and an `EmbeddedKafkaConfig` it is possible to use `withConsumer[A, B, R] { your code here }` where R is the code return type.
177
209
178
-
### Loan methods example
210
+
####Loan methods example
179
211
180
212
A simple test using loan methods can be as simple as this:
181
213
@@ -201,26 +233,26 @@ A simple test using loan methods can be as simple as this:
201
233
})
202
234
```
203
235
204
-
## embedded-kafka-streams
236
+
###embedded-kafka-streams
205
237
206
238
A library that builds on top of `embedded-kafka` to offer easy testing of [Kafka Streams](https://kafka.apache.org/documentation/streams).
207
239
208
240
It takes care of instantiating and starting your streams as well as closing them after running your test-case code.
209
241
210
-
### How to use
242
+
####How to use
211
243
212
244
* In your `build.sbt` file add the following dependency (replace `x.x.x` with the appropriate version): `"io.github.embeddedkafka" %% "embedded-kafka-streams" % "x.x.x" % Test`
213
245
* Have a look at the [example test](kafka-streams/src/test/scala/io/github/embeddedkafka/streams/ExampleKafkaStreamsSpec.scala)
214
246
* For most of the cases have your class extend the `EmbeddedKafkaStreams` trait. This offers both streams management and easy loaning of producers and consumers for asserting resulting messages in output/sink topics.
215
247
* Use `EmbeddedKafkaStreams.runStreams` and `EmbeddedKafka.withConsumer` and `EmbeddedKafka.withProducer`. This allows you to create your own consumers of custom types as seen in the [example test](kafka-streams/src/test/scala/io/github/embeddedkafka/streams/ExampleKafkaStreamsSpec.scala).
216
248
217
-
## embedded-kafka-connect
249
+
###embedded-kafka-connect
218
250
219
251
A library that builds on top of `embedded-kafka` to offer easy testing of [Kafka Connect](https://kafka.apache.org/documentation/#connect).
220
252
221
253
It takes care of instantiating and starting a Kafka Connect server as well as closing it after running your test-case code.
222
254
223
-
### How to use
255
+
####How to use
224
256
225
257
* In your `build.sbt` file add the following dependency (replace `x.x.x` with the appropriate version): `"io.github.embeddedkafka" %% "embedded-kafka-connect" % "x.x.x" % Test`
226
258
* Have a look at the [example test](kafka-connect/src/test/scala/io/github/embeddedkafka/connect/ExampleKafkaConnectSpec.scala)
0 commit comments