Spring Cloud Streams 有条件地将数据转发到 Kafka 主题 [英] Spring Cloud Streams Conditional Forwarding of Data to Kafka Topics

查看:45
本文介绍了Spring Cloud Streams 有条件地将数据转发到 Kafka 主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据一些评估将数据发送到不同的主题.我正在使用 SPring CLoud Streams 和 Kafka

I am trying to send Data to different topics based on some evaluation. I am using SPring CLoud Streams and Kafka

如何有条件地转发kafka主题.需要在我专门评论的地方插入SCS-kafka相关代码.

How can I conditionally forward to kafka topics. I need to insert SCS-kafka related code in the places where I commented specifically.

谢谢.

    @EnableBinding(Sink.class)
public class SampleSink {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SomeService someService;

    @ServiceActivator(inputChannel = Sink.INPUT)
    public void processor(Message<?> message1) {


        EvaluateData evaluateData = someService.evaluateData(message1);

        String Result = String.valueOf(evaluateData.getResult());

        try {

            if(validationResult.equalsIgnoreCase("allgood")){

                //Send message1 to Topic1


            }

            else if (validationResult.equalsIgnoreCase("notgood")){
 new SomeException("topic1");

//发送数据到topic2

//sent data to topic2

            }

            else {
                throw new SomeException("topic3");
            }

        }
        catch (SomeException e){

          //something

//分别向topic2和3发送数据}

//sent data to topic2 and 3 respectively }

    }
}

推荐答案

您尝试做的本质上是一个路由器,我们已经将其作为开箱即用的应用程序提供.它基本上是一个路由器接收器,它将根据您通过配置指定的条件路由消息.请在此处

What you are trying to do is essentially a router which we already provide as an out of the box application. It is basically a router Sink which will route message based on conditions you specify via configuration. Please see more here

这篇关于Spring Cloud Streams 有条件地将数据转发到 Kafka 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆