Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 2bb39d1

Browse files
committed
Merge branch 'develop' of https://github.com/lightbend/kafka-streams-scala into develop
2 parents 604555e + 05229e1 commit 2bb39d1

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

README.md

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The library wraps Java APIs in Scala thereby providing:
77
1. much better type inference in Scala
88
2. less boilerplate in application code
99
3. the usual builder-style composition that developers get with the original Java API
10+
4. complete compile time type safety
1011

1112
The design of the library was inspired by the work started by Alexis Seigneurin in [this repository](https://github.com/aseigneurin/kafka-streams-scala).
1213

@@ -52,48 +53,17 @@ val clicksPerRegion: KTableS[String, Long] = userClicksStream
5253
.map((_, regionWithClicks) => regionWithClicks)
5354

5455
// Compute the total per region by summing the individual click counts per region.
55-
.groupByKey(Serialized.`with`(stringSerde, longSerde))
56+
.groupByKey
5657
.reduce(_ + _)
5758
```
5859

59-
> **Notes:**
60-
>
61-
> 1. The left quotes around "with" are there because `with` is a Scala keyword. This is the mechanism you use to "escape" a Scala keyword when it's used as a normal identifier in a Java library.
62-
> 2. Note that some methods, like `map`, take a two-argument function, for key-value pairs, rather than the more typical single argument.
63-
64-
## Better Abstraction
65-
66-
The wrapped Scala APIs also incur less boilerplate by taking advantage of Scala function literals that get converted to Java objects in the implementation of the API. Hence the surface syntax of the client API looks simpler and less noisy.
67-
68-
Here's an example of a snippet built using the Java API from Scala ..
69-
70-
```scala
71-
val approximateWordCounts: KStream[String, Long] = textLines
72-
.flatMapValues(value => value.toLowerCase.split("\\W+").toIterable.asJava)
73-
.transform(
74-
new TransformerSupplier[Array[Byte], String, KeyValue[String, Long]] {
75-
override def get() = new ProbabilisticCounter
76-
},
77-
cmsStoreName)
78-
approximateWordCounts.to(outputTopic, Produced.`with`(Serdes.String(), longSerde))
79-
```
80-
81-
And here's the corresponding snippet using the Scala library. Note how the noise of `TransformerSupplier` has been abstracted out by the function literal syntax of Scala.
82-
83-
```scala
84-
textLines
85-
.flatMapValues(value => value.toLowerCase.split("\\W+").toIterable)
86-
.transform(() => new ProbabilisticCounter, cmsStoreName)
87-
.to(outputTopic, Produced.`with`(Serdes.String(), longSerde))
88-
```
89-
90-
Also, the explicit conversion `asJava` from a Scala `Iterable` to a Java `Iterable` is done for you by the Scala library.
91-
9260
## Implicit Serdes
9361

94-
One of the areas where the Java APIs' verbosity can be reduced is through a succinct way to pass serializers and de-serializers to the various functions. The library implementation offers type safe implicit serdes to provide the serializers and de-serializers. In doing so, the Scala library **does not use configuration based default serdes** which is not type safe and prone to runtime errors.
62+
One of the areas where the Java APIs' verbosity can be reduced is through a succinct way to pass serializers and de-serializers to the various functions. The library uses the power of Scala implicits towards this end. The library makes some decisions that help implement more succinct serdes in a type safe manner:
63+
64+
1. No use of configuration based default serdes. Java APIs allow the user to define default key and value serdes as part of the configuration. This configuration, being implemented as `java.util.Properties` is type-unsafe and hence can result in runtime errors in case the user misses any of the serdes to be specified or plugs in an incorrect serde. `kafka-streams-scala` makes this completely type-safe by allowing all serdes to be specified through Scala implicits.
65+
2. The libraty offers implicit conversions from serdes to `Serialized`, `Produced`, `Consumed` or `Joined`. Hence as a user you just have to pass in the implicit serde and all conversions to `Serialized`, `Produced`, `Consumed` or `Joined` will be taken care of automatically.
9566

96-
The implementation allows implicits for the `Serde`s or for `Serialized`, `Consumed`, `Produced` and `Joined`. The test examples demonstrate both, though the implicits for Serdes make a cleaner implementation.
9767

9868
### Default Serdes
9969

0 commit comments

Comments
 (0)