Last active
July 5, 2016 12:32
-
-
Save joost-de-vries/cd32ceb0a0cc9cc685e559c770dec414 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Mono<Void> gitterSlackRelay() { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| return create() | |
| .get(gitterStreamUrl, gitterStreamHandler()) | |
| .flatMap(replies -> replies | |
| .receiveByteArray() | |
| .filter(b -> b.length > 2) // ignore gitter keep-alives (\r) | |
| .map(b -> { | |
| try { | |
| return mapper.readValue(b, Map.class); | |
| } | |
| catch (IOException e) { | |
| throw Exceptions.propagate(e); | |
| } | |
| }) // ObjectMapper.readValue(Map | |
| // .class) | |
| .window(10, 1_000) // microbatch 10 items or 1s worth into individual streams (for reduce ops) | |
| .flatMap(w -> postToSlack( | |
| w.map(m -> formatLink(m) + ": " + formatText(m)) | |
| .reduce("", GitterSlackRelayApplication::appendLines)) | |
| ) | |
| ) | |
| .then(); // only complete when all windows have completed AND gitter GET connection has closed | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment