KStream send record to multiple streams (not Branch)

匆匆过客 提交于 2019-12-02 13:52:08

问题


Is there a way to make branch-like operation but to place record in each output stream which predicate evaluates to true? Brach puts record to first match (documentation: A record is placed to one and only one output stream on the first match).


回答1:


You can "broadcast" and filter each stream individually:

KStream stream = ...

stream1 = stream.filter(...);
stream2 = stream.filter(...);
// and so on...

If you use stream variable multiple times, all records are broadcasted to all downstream filters (or any other operator), ie, each filter is executed for each record.




回答2:


I think you can use something like this:

KStream<String, String> inputStream = builder.stream("input");
List<Predicate<String, String>> predicates = new ArrayList<>(); // <-- list of predicates
List<KStream<String, String>> kStreams = predicates.stream()
        .map(inputStream::branch)
        .map(Arrays::asList)
        .map(listOfOneElementKStreams -> listOfOneElementKStreams.get(0)).collect(Collectors.toList());


来源:https://stackoverflow.com/questions/54057772/kstream-send-record-to-multiple-streams-not-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!