[英]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.