Skip to content

Commit 74d3eae

Browse files
authored
Improve README (#16)
1 parent a87fe4c commit 74d3eae

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ We want to implement this flow:
4949

5050
![Diagram1](doc/diagram1.png)
5151

52-
* User will POST string payloads to `/text` endpoint
53-
* A **KafkaProducer** will send these payloads to topic `pub.texts` as `{ "text" : string }`
54-
* A **KafkaStreams** transformation will consume from topic `pub.texts` and produce events to topic `pub.lengths` as `{ "length" : number }`
55-
* A **KafkaConsumer** will consume events from topic `pub.lengths` and log them to the console
52+
* User will POST string payloads to **/text** endpoint
53+
* A **KafkaProducer** will send these payloads to topic **pub.texts** as `{ "text" : string }`
54+
* A **KafkaStreams** transformation will consume from topic **pub.texts** and produce events to topic **pub.lengths** as `{ "length" : number }`
55+
* A **KafkaConsumer** will consume events from topic **pub.lengths** and log them to the console
5656

5757
So we will use two Spring Cloud Stream binders:
5858
* **Kafka**
@@ -61,8 +61,8 @@ So we will use two Spring Cloud Stream binders:
6161
## Create the project
6262

6363
We use this [spring initializr configuration](https://start.spring.io/#!type=gradle-project&language=kotlin&packaging=jar&groupId=com.rogervinas&artifactId=springcloudstreammultibinder&name=springcloudstreammultibinder&description=Spring%20Cloud%20Streams%20%26%20Kafka%20Streams%20Binder&packageName=com.rogervinas.springcloudstreammultibinder&dependencies=cloud-stream) and we add:
64-
* **Kafka** binder lib `spring-cloud-stream-binder-kafka`
65-
* **Kafka Streams** binder lib `spring-cloud-stream-binder-kafka-streams`
64+
* **Kafka** binder lib **spring-cloud-stream-binder-kafka**
65+
* **Kafka Streams** binder lib **spring-cloud-stream-binder-kafka-streams**
6666

6767
## Integration Test
6868

@@ -134,30 +134,30 @@ kafka:
134134
```
135135
136136
* Spring Cloud Stream will create:
137-
* A **Kafka Streams binder** connected to `localhost:9094`
138-
* A **Kafka binder** connected to `localhost:9094`
137+
* A **Kafka Streams binder** connected to **localhost:9094**
138+
* A **Kafka binder** connected to **localhost:9094**
139139
* Following the Spring Cloud Stream *functional programming model conventions* we should create:
140-
* A bean named `textProducer` that should implement:
141-
* In **Java**: `Supplier<Flux<TextEvent>>` interface
142-
* In **Kotlin**: `() -> Flux<TextEvent>` lambda
143-
* A bean named `textLengthProcessor` that should implement:
144-
* In **Java**: `Function<KStream<String, TextEvent>, KStream<String, LengthEvent>>` interface
140+
* A bean named **textProducer** that should implement:
141+
* In **Java**: **Supplier<Flux<TextEvent>>** interface
142+
* In **Kotlin**: **() -> Flux<TextEvent>** lambda
143+
* A bean named **textLengthProcessor** that should implement:
144+
* In **Java**: **Function<KStream<String, TextEvent>, KStream<String, LengthEvent>>** interface
145145
* In **Kotlin**: the same, there is no support for lambdas yet 😅
146-
* A bean named `lengthConsumer` that should implement:
147-
* In **Java**: `Consumer<LengthEvent>` interface
148-
* In **Kotlin**: `(LengthEvent>) -> Unit` lambda
146+
* A bean named **lengthConsumer** that should implement:
147+
* In **Java**: **Consumer<LengthEvent>** interface
148+
* In **Kotlin**: **(LengthEvent>) -> Unit** lambda
149149
150-
💡 We use different values for the Kafka Streams `applicationId` and the Kafka Consumers `group` to avoid undesired behaviors.
150+
💡 We use different values for the Kafka Streams **applicationId** and the Kafka Consumers **group** to avoid undesired behaviors.
151151
152-
💡 We are using Spring Cloud Stream's default serialization/deserialization of Kotlin data classes to Json. In order for this to work we need to add `com.fasterxml.jackson.module:jackson-module-kotlin` dependency.
152+
💡 We are using Spring Cloud Stream's default serialization/deserialization of Kotlin data classes to Json. In order for this to work we need to add **com.fasterxml.jackson.module:jackson-module-kotlin** dependency.
153153
154154
💡 You can find all the available configuration properties documented in:
155155
* [Kafka binder properties](https://github.com/spring-cloud/spring-cloud-stream-binder-kafka#kafka-binder-properties)
156156
* [Kafka Streams binder properties](https://cloud.spring.io/spring-cloud-stream-binder-kafka/spring-cloud-stream-binder-kafka.html#_kafka_streams_properties)
157157
158158
## TextProducer
159159
160-
We create `TextProducer` interface to be implemented later:
160+
We create **TextProducer** interface to be implemented later:
161161
162162
```kotlin
163163
data class TextEvent(val text: String)
@@ -210,7 +210,7 @@ class TextController(private val textProducer: TextProducer) {
210210

211211
## TextProducer implementation
212212

213-
We implement `TextProducer` as expected by Spring Cloud Stream conventions like this:
213+
We implement **TextProducer** as expected by Spring Cloud Stream conventions like this:
214214

215215
```kotlin
216216
class TextFluxProducer : () -> Flux<TextEvent>, TextProducer {
@@ -261,7 +261,7 @@ class TextLengthProcessor : Function<KStream<String, TextEvent>, KStream<String,
261261
}
262262
```
263263

264-
And we can test it using `kafka-streams-test-utils`:
264+
And we can test it using **kafka-streams-test-utils**:
265265

266266
```kotlin
267267
private const val TOPIC_IN = "topic.in"
@@ -321,7 +321,7 @@ internal class TextLengthProcessorTest {
321321

322322
## LengthConsumer
323323

324-
We implement `LengthStreamConsumer` as expected by Spring Cloud Stream conventions like this:
324+
We implement **LengthStreamConsumer** as expected by Spring Cloud Stream conventions like this:
325325

326326
```kotlin
327327
data class LengthEvent(val length: Int)
@@ -334,7 +334,7 @@ class LengthStreamConsumer(private val processor: LengthProcessor) : (LengthEven
334334
}
335335
```
336336

337-
We decouple the final implementation using the interface `LengthProcessor`:
337+
We decouple the final implementation using the interface **LengthProcessor**:
338338

339339
```kotlin
340340
interface LengthProcessor {
@@ -420,13 +420,13 @@ class MyApplicationConfiguration {
420420
```
421421

422422
Please note that:
423-
* The three Spring Cloud functions defined in [application.yml](src/main/resources/application.yml) will be bound **by name** to the beans `textProducer`, `textLengthProcessor` and `lengthConsumer`.
424-
* For the Kafka binder ones, `textProducer` and `lengthConsumer`, we have to **define them explicitly as Kotlin lambdas** (required by `KotlinLambdaToFunctionAutoConfiguration`).
425-
* If we were using **Java** we should use `java.util.function` types: `Supplier` and `Consumer`.
426-
* For the Kafka Stream binder one, `textLengthProcessor`, we have to **define it explicitly as a `java.util.function.Function`**, there is no support for **Kotlin** lambdas yet (check `KafkaStreamsFunctionBeanPostProcessor`).
427-
* Beans `textFluxProducer` and `textProducer` return the same instance ...
428-
* We need `textFluxProducer` to inject it whenever a `TextProducer` interface is needed (the `TextController` for example).
429-
* We need `textProducer` to bind it to the `textProducer` Spring Cloud function required by the Kafka binder.
423+
* The three Spring Cloud functions defined in [application.yml](src/main/resources/application.yml) will be bound **by name** to the beans **textProducer**, **textLengthProcessor** and **lengthConsumer**.
424+
* For the Kafka binder ones, **textProducer** and **lengthConsumer**, we have to **define them explicitly as Kotlin lambdas** (required by **KotlinLambdaToFunctionAutoConfiguration**).
425+
* If we were using **Java** we should use **java.util.function** types: **Supplier** and **Consumer**.
426+
* For the Kafka Stream binder one, **textLengthProcessor**, we have to **define it explicitly as a java.util.function.Function**, there is no support for **Kotlin** lambdas yet (check **KafkaStreamsFunctionBeanPostProcessor**).
427+
* Beans **textFluxProducer** and **textProducer** return the same instance ...
428+
* We need **textFluxProducer** to inject it whenever a **TextProducer** interface is needed (the **TextController** for example).
429+
* We need **textProducer** to bind it to the **textProducer** Spring Cloud function required by the Kafka binder.
430430

431431
And that is it, now [MyApplicationIntegrationTest](src/test/kotlin/com/rogervinas/multibinder/MyApplicationIntegrationTest.kt) should work! 🤞
432432

0 commit comments

Comments
 (0)