I'm trying to create multiple implementation classes for a kafka event based on the type of event.
public class KafkaListener {
@Autowired
Service service;
@KafkaListener(topics = ("mytopic"), containerFactory = "kafkaListenerContainerFactory")
public void consumeSource(Object event) {
service.process(event);
}
}
public interface Service<E> {
void process(E event);
}
public class ServiceImpl1 implements Service<Event1> {
void process(Event1 event1) {
// process
}
}
public class ServiceImpl2 implements Service<Event2> {
void process(Event2 event2) {
// process
}
}
//Event1 & Event2 are 2 POJO classes with different inputs
Is it possible to implement or am I supposed to create multiple listener, one for each event type?