Spring Cloud将有条件的数据流传输到Kafka主题 [英] Spring Cloud Streams Conditional Forwarding of Data to Kafka Topics
问题描述
我正在尝试根据一些评估将数据发送到不同的主题.我正在使用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将有条件的数据流传输到Kafka主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!