简体   繁体   English

Kafka流,将输出分支到多个主题

[英]Kafka streams, branched output to multiple topics

In my DSL based transformation, I have a stream-->branch, where in I want branched output redirected to multiple topics. 在我的基于DSL的转换中,我有一个流 - >分支,我希望分支输出重定向到多个主题。 Current branch.to() method accepts only a String . 当前branch.to()方法仅接受String Is there any simple option with stream.branch where I can route the result to multiple topics. 有没有使用stream.branch简单选项,我可以将结果路由到多个主题。 With a consumer, I can subscribe to multiple topics by providing an array of string as topics. 对于消费者,我可以通过提供字符串数组作为主题来订阅多个主题。

My problem requires me to take multiple actions if particular predicate satisfies a query. 如果特定谓词满足查询,我的问题需要我采取多个操作。

I tried with stream.branch[index].to(string) , but this is not sufficient for my requirement. 我尝试使用stream.branch[index].to(string) ,但这还不足以满足我的要求。 I am looking for something like stream.branch[index].to(string array of topics) or stream.branch[index].to(string) . 我正在寻找像stream.branch[index].to(string array of topics)stream.branch[index].to(string)

I expect the branch.to method with multiple topics or is there any alternate way to achieve the same with streams? 我期望branch.to方法有多个主题,或者是否有任何替代方法来实现与流相同的方法?

adding sample code.Removed actual variable names. 添加示例代码。删除实际变量名称。

My Predicates 我的谓词

    Predicate <String, MyDomainObject> Predicate1 = new Predicate<String, MyDomainObject>() {
        @Override
        public boolean test(String key, MyDomainObject domObj) {
            boolean result = false;
    if condition on domObj
            return result;
        }
    };
    Predicate <String, MyDomainObject> Predicate2 = new Predicate<String, MyDomainObject>() {
        @Override
        public boolean test(String key, MyDomainObject domObj) {
            boolean result = false;
    if condition on domObj
            return result;
        }
    };

    KStream <String, MyDomainObject>[] branches= myStream.branch(
            Predicate1, Predicate2
    );


// here I need your suggestions.

// this is my current implementation
branches[0].to(singleTopic),
            Produced.with(Serdes.String(), Serdes.serdeFrom(inSer, deSer)));

// I want to send notification to multiple topics. something like below

branches[0].to(topicList),
            Produced.with(Serdes.String(), Serdes.serdeFrom(inSer, deSer)));

If you know to which topics you want to send the data, you can do the following: 如果您知道要将数据发送到哪些主题,则可以执行以下操作:

branches[0].to("first-topic");
branches[0].to("second-topic");
// etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM