Spring Cloud Streams Conditional Forwarding of Data to Kafka Topics

喜欢而已 提交于 2019-12-11 16:59:35

问题


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

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

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

            }

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

        }
        catch (SomeException e){

          //something

//sent data to topic2 and 3 respectively }

    }
}

回答1:


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



来源:https://stackoverflow.com/questions/53263321/spring-cloud-streams-conditional-forwarding-of-data-to-kafka-topics

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