I am using spring cloud stream kafka with functional approach. Have got two topics Topic1 and Topic2 and contains messages related to multiple schema.
Topic1 contains messages of Car and Bike
Topic2 contains messages related to Fruits and Vegetables.
Would like to process them independently as processCar, processBike, processFruits and ProcessVegetables functions.
Able to apply MessageRoutingCallback functionality to handle Car and Bike from one topic. But unable to do so on topic2.
@Bean
public MessageRoutingCallback customRouter() {
String EVENT_TYPE = "eventType";
Map<String, String> evenTypeToFunctionNameMap = new HashMap<>();
evenTypeToFunctionNameMap.put(
"car",
"processCar"
);
evenTypeToFunctionNameMap.put(
"bike",
"processBike"
);
return new MessageRoutingCallback() {
@Override
public FunctionRoutingResult routingResult(Message<?> message) {
return new FunctionRoutingResult(
evenTypeToFunctionNameMap.get(
message.getHeaders().get(EVENT_TYPE, String.class)
)
);
}
};
}
And properties are
spring.cloud.stream.bindings.functionRouter-in-0.destination=topic1
spring.cloud.stream.bindings.functionRouter-in-0.binder=default
Note : Would like to avoid spring.cloud.stream.bindings.functionRouter-in-0.destination=topic1, topic2 as an option as topic 1 and topic 2 needs to be on different channel as they are on different binder / have different fault processing needs.