英文:
Spring cloud stream branch stream not working as expected
问题
以下是分支代码,它仅流向一个主题(第一个主题)。 据我了解,它应该流向所有三个主题?
无论如何,我可以使用分支流到三个主题吗?
@Bean
public Function<KStream<String, User>, KStream<String, User>[]> testprocess() {
Predicate<String, User> stream1 = (k, v) -> v != null;
Predicate<String, User> stream2 = (k, v) -> v != null;
Predicate<String, User> stream3 = (k, v) -> v != null;
return input -> input.map(
(key, user) -> new KeyValue<String, User>(user.getId(), user))
.branch(stream1, stream2, stream3);
}
处理器的配置
testprocess-in-0:
destination: input.users
testprocess-out-0:
destination: users.test.out.0
testprocess-out-1:
destination: users.test.out.1
testprocess-out-2:
destination: users.test.out.2
英文:
Below is the code for branching, it streams to only one topic (the first one). As I understand, it should stream to all three topics?
Anyway I can stream to three topics using branch?
@Bean
public Function<KStream<String, Usesr>, KStream<String, User>[]> testprocess() {
Predicate<String, User> stream1 = (k, v) -> v != null;
Predicate<String, User> stream2 = (k, v) -> v != null;
Predicate<String, User> stream3 = (k, v) -> v != null;
return input -> input.map(
(key, user) -> new KeyValue<String, User>(user.getId(), user))
.branch(stream1, stream2, stream3);
Configuration for the processor
testprocess-in-0:
destination: input.users
testprocess-out-0:
destination: users.test.out.0
testprocess-out-1:
destination: users.test.out.1
testprocess-out-2:
destination: users.test.out.2
答案1
得分: 1
通过查看您的谓词,似乎第一个谓词总是获胜,其他谓词没有机会。在Kafka Streams分支中,首个评估为真的谓词成功,相应的主题接收数据。您需要更改谓词中的逻辑,以正确映射到适当的主题。这里有一个示例。
英文:
By looking at your predicates, it appears that the first predicate always wins and the others do not get a chance. In Kafka Streams branching, the first predicate that evaluates to true succeeds and the corresponding topic receives the data. You need to change the logic in the predicates so that the correct topic is appropriately mapped. Here is an example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论