Skip to content
This repository was archived by the owner on Mar 13, 2021. It is now read-only.

Commit 7cd6611

Browse files
authored
Update samples for windowing and main class detection (#79)
- update README instructions - remove windowing from wordcount sample - rely on main class detection in SCFn in uppercase sample
1 parent 009d0d4 commit 7cd6611

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

samples/uppercase/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ N.B. this sample uses Spring (without really needing to, but just to show how it
2626
=== create the function and its input topic
2727

2828
```
29-
riff create java --handler 'uppercase&main=functions.UppercaseApplication'
29+
riff create java --handler uppercase
3030
```
3131

3232
=== publish a message and wait for a reply

samples/wordcount/README.adoc

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,36 @@
2222
./mvnw clean package
2323
```
2424

25-
=== create the function and its input topic
25+
=== create the function and its input topic resource definitions
2626

2727
```
28-
riff create java --input words --output counts --handler functions.Wordcount
28+
riff init java --input words --output counts --handler functions.Wordcount
29+
```
30+
31+
=== modify the function resource definition's windowing declaration
32+
33+
Modify the `wordcount-function.yaml` that was just created. Change the `windowing`
34+
declaration to be either
35+
36+
- time based:
37+
+
38+
```
39+
windowing:
40+
time: 10s
41+
```
42+
43+
- or, based on number of messages:
44+
+
45+
```
46+
windowing:
47+
size: 5
48+
```
49+
50+
=== build and create the function and its input topic
51+
52+
```
53+
riff build
54+
riff apply
2955
```
3056

3157
=== publish messages and witness grouped counts
@@ -40,13 +66,26 @@ In a different terminal window, in quick succession:
4066
riff publish --input words --data Two
4167
riff publish --input words --data One
4268
riff publish --input words --data Two
69+
riff publish --input words --data Three
70+
riff publish --input words --data One
71+
riff publish --input words --data Two
4372
```
4473

4574
You'll see output similar to the following:
75+
4676
```
47-
Content-Type["text/plain"] timestamp["1519342606257"]{"one":1,"two":2}
77+
timestamp["1527008218465"]{"One":2,"Two":2,"Three":1}
78+
timestamp["1527008230607"]{"Two":1}
4879
```
4980

81+
or
82+
83+
```
84+
timestamp["1527008390450"]{"One":2,"Two":3,"Three":1}
85+
```
86+
87+
depending on how you configure your windows.
88+
5089
=== delete the function and its input topic
5190

5291
```
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package functions;
22

3-
import java.time.Duration;
43
import java.util.HashMap;
54
import java.util.Map;
65
import java.util.function.Function;
@@ -11,8 +10,7 @@ public class Wordcount implements Function<Flux<String>, Flux<Map<String, Intege
1110

1211
@Override
1312
public Flux<Map<String, Integer>> apply(Flux<String> words) {
14-
return words.window(Duration.ofSeconds(10))
15-
.flatMap(w -> w.collect(HashMap::new, (map, word) ->
16-
map.merge(word, 1, Integer::sum)));
13+
return Flux.from(words.collect(
14+
HashMap::new, (map, word) -> map.merge(word, 1, Integer::sum)));
1715
}
1816
}

0 commit comments

Comments
 (0)