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
At the moment, Kafka Streams binder only allows KStream bindings on the outbound.
There is a delegation mechanism in which we stil can use KStream for output binding
while allowing the applications to provide a KTable type as the function return type.
Update docs.
Resolvesspring-attic#1085
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/kafka-streams.adoc
+24-7
Original file line number
Diff line number
Diff line change
@@ -252,7 +252,28 @@ The input from the three partial functions which are `KStream`, `GlobalKTable`,
252
252
Input bindings are named as `enrichOrder-in-0`, `enrichOrder-in-1` and `enrichOrder-in-2` respectively. Output binding is named as `enrichOrder-out-0`.
253
253
254
254
With curried functions, you can virtually have any number of inputs. However, keep in mind that, anything more than a smaller number of inputs and partially applied functions for them as above in Java might lead to unreadable code.
255
-
Therefore if your Kafka Streams application requires more than a reasonably smaller number of input bindings and you want to use this functional model, then you may want to rethink your design and decompose the application appropriately.
255
+
Therefore if your Kafka Streams application requires more than a reasonably smaller number of input bindings, and you want to use this functional model, then you may want to rethink your design and decompose the application appropriately.
256
+
257
+
===== Output Bindings
258
+
259
+
Kafka Streams binder allows types of either `KStream` or `KTable` as output bindings.
260
+
Behind the scenes, the binder uses the `to` method on `KStream` to send the resultant records to the output topic.
261
+
If the application provides a `KTable` as output in the function, the binder still uses this technique by delegating to the `to` method of `KStream`.
262
+
263
+
For example both functions below will work:
264
+
265
+
```
266
+
@Bean
267
+
public Function<KStream<String, String>, KTable<String, String>> foo() {
268
+
return KStream::toTable;
269
+
};
270
+
}
271
+
272
+
@Bean
273
+
public Function<KTable<String, String>, KStream<String, String>> bar() {
274
+
return KTable::toStream;
275
+
}
276
+
```
256
277
257
278
===== Multiple Output Bindings
258
279
@@ -383,8 +404,7 @@ The default output binding for this example becomes `curriedFoobar-out-0`.
383
404
384
405
====== Special note on using `KTable` as output in function composition
385
406
386
-
When using function composition, for intermediate functions, you can use `KTable` as output.
387
-
For instance, lets say you have the following two functions.
You can compose them as `foo|bar` although foo's output is `KTable`.
403
-
In normal case, when you use `foo` as standalone, this will not work, as the binder does not support `KTable` as the final output.
404
-
Note that in the example above, bar's output is still a `KStream`.
405
-
We are only able to use `foo` which has a `KTable` output, since we are composing with another function that has `KStream` as its output.
422
+
You can compose them as `foo|bar`, but keep in mind that the second function (`bar` in this case) must have a `KTable` as input since the first function (`foo`) has `KTable` as output.
Copy file name to clipboardExpand all lines: spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/KTableBinder.java
Copy file name to clipboardExpand all lines: spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/KafkaStreamsFunctionProcessor.java
Copy file name to clipboardExpand all lines: spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsBindableProxyFactory.java
+6-2
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,8 @@ public void afterPropertiesSet() {
0 commit comments