Skip to content

Commit 138f55a

Browse files
authored
Updated README.md
Using scala markup notation.
1 parent 9f1891f commit 138f55a

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

README.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,56 @@ scalatest-embedded-kafka is available on Bintray and Maven Central, compiled for
2020
* In your `build.sbt` file add the following dependency: `"net.manub" %% "scalatest-embedded-kafka" % "0.9.0" % "test"`
2121
* Have your `Spec` extend the `EmbeddedKafka` trait.
2222
* Enclose the code that needs a running instance of Kafka within the `withRunningKafka` closure.
23+
```scala
24+
class MySpec extends WordSpec with EmbeddedKafka {
2325

24-
class MySpec extends WordSpec with EmbeddedKafka {
25-
26-
"runs with embedded kafka" should {
26+
"runs with embedded kafka" should {
2727

28-
withRunningKafka {
29-
// ... code goes here
30-
}
31-
32-
}
28+
withRunningKafka {
29+
// ... code goes here
30+
}
3331

32+
}
33+
```
3434
* In-memory Zookeeper and Kafka will be instantiated respectively on port 6000 and 6001 and automatically shutdown at the end of the test.
3535

3636
### Use without the `withRunningKafka` method
3737

3838
A `EmbeddedKafka` companion object is provided for usage without the `EmbeddedKafka` trait. Zookeeper and Kafka can be started an stopped in a programmatic way.
3939

40-
class MySpec extends WordSpec {
40+
```scala
41+
class MySpec extends WordSpec {
4142

42-
"runs with embedded kafka" should {
43-
44-
EmbeddedKafka.start()
45-
46-
// ... code goes here
47-
48-
EmbeddedKafka.stop()
49-
50-
}
43+
"runs with embedded kafka" should {
44+
45+
EmbeddedKafka.start()
46+
47+
// ... code goes here
48+
49+
EmbeddedKafka.stop()
50+
51+
}
52+
```
5153

5254
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.
5355

5456
## Configuration
5557

5658
It's possible to change the ports on which Zookeeper and Kafka are started by providing an implicit `EmbeddedKafkaConfig`
5759

58-
class MySpec extends WordSpec with EmbeddedKafka {
59-
60-
"runs with embedded kafka on a specific port" should {
60+
```scala
61+
class MySpec extends WordSpec with EmbeddedKafka {
6162

62-
implicit val config = EmbeddedKafkaConfig(kafkaPort = 12345)
63+
"runs with embedded kafka on a specific port" should {
6364

64-
withRunningKafka {
65-
// now a kafka broker is listening on port 12345
66-
}
67-
68-
}
65+
implicit val config = EmbeddedKafkaConfig(kafkaPort = 12345)
66+
67+
withRunningKafka {
68+
// now a kafka broker is listening on port 12345
69+
}
70+
71+
}
72+
```
6973

7074
This works for both `withRunningKafka` and `EmbeddedKafka.start()`
7175

@@ -79,12 +83,14 @@ are.
7983

8084
The `EmbeddedKafka` trait provides also some utility methods to interact with the embedded kafka, in order to set preconditions or verifications in your specs:
8185

82-
def publishToKafka(topic: String, message: String): Unit
83-
84-
def consumeFirstMessageFrom(topic: String): String
86+
```scala
87+
def publishToKafka(topic: String, message: String): Unit
88+
89+
def consumeFirstMessageFrom(topic: String): String
90+
91+
def createCustomTopic(topic: String, topicConfig: Map[String,String], partitions: Int, replicationFactor: Int): Unit
92+
```
8593

86-
def createCustomTopic(topic: String, topicConfig: Map[String,String], partitions: Int, replicationFactor: Int): Unit
87-
8894
## Custom producers
8995

9096
It is possible to create producers for custom types in two ways:

0 commit comments

Comments
 (0)