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
{{ message }}
This repository was archived by the owner on May 25, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+6-36Lines changed: 6 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ The library wraps Java APIs in Scala thereby providing:
7
7
1. much better type inference in Scala
8
8
2. less boilerplate in application code
9
9
3. the usual builder-style composition that developers get with the original Java API
10
+
4. complete compile time type safety
10
11
11
12
The design of the library was inspired by the work started by Alexis Seigneurin in [this repository](https://github.com/aseigneurin/kafka-streams-scala).
12
13
@@ -52,48 +53,17 @@ val clicksPerRegion: KTableS[String, Long] = userClicksStream
52
53
.map((_, regionWithClicks) => regionWithClicks)
53
54
54
55
// Compute the total per region by summing the individual click counts per region.
> 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 ..
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.
Also, the explicit conversion `asJava` from a Scala `Iterable` to a Java `Iterable` is done for you by the Scala library.
91
-
92
60
## Implicit Serdes
93
61
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.
95
66
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.
0 commit comments