简体   繁体   English

Spring Cloud将数据有条件转发到Kafka主题

[英]Spring Cloud Streams Conditional Forwarding of Data to Kafka Topics

I am trying to send Data to different topics based on some evaluation. 我正在尝试根据一些评估将数据发送到不同的主题。 I am using SPring CLoud Streams and Kafka 我正在使用SPring CLoud Streams和Kafka

How can I conditionally forward to kafka topics. 我如何有条件地转发到kafka主题。 I need to insert SCS-kafka related code in the places where I commented specifically. 我需要在我特别评论的地方插入SCS-kafka相关的代码。

Thank you. 谢谢。

    @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");

//sent data to topic2 //将数据发送到topic2

            }

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

        }
        catch (SomeException e){

          //something

//sent data to topic2 and 3 respectively } //分别向主题2和3发送数据}

    }
}

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 在这里查看更多

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

相关问题 Spring Cloud Stream向Kafka主题发送数据失败 - Spring Cloud Stream Sending Data to Kafka Topics Fails Spring和Kafka:加入3个Kafka主题以生成输出Kafka流 - Spring and Kafka: Join 3 Kafka topics to generate output Kafka streams ClassCastException 与 Spring 云和 Kafka 流 - ClassCastException with Spring Cloud and Kafka Streams 如何使用 spring 云 stream binder kafka 流依赖项使用协议缓冲区(protobuf)来使用来自 kafka 主题的消息? - How to consume messages from kafka topics using protocol buffers (protobuf) by spring cloud stream binder kafka streams dependency? 无法使用 Spring Cloud Streams 反序列化 Kafka Stream 中的数据 - Can't deserialize data in the Kafka Stream using Spring Cloud Streams Kafka Streams - 根据 Streams 数据发送不同的主题 - Kafka Streams - Send on different topics depending on Streams Data 将 StateRestoreListener 与 Spring Cloud Kafka Streams 绑定器一起使用 - Using StateRestoreListener with Spring Cloud Kafka Streams binder 骆驼 kafka 主题中的 spring-cloud-contract-verifier 清理消息 - spring-cloud-contract-verifier cleanup messages in camel kafka topics 在 Kafka 代理本身或通过 Spring Cloud Stream 配置主题 - Configure Topics in Kafka broker itself or via Spring Cloud Stream 春天卡夫卡和卡夫卡流 - Spring Kafka and Kafka Streams
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM