I'm working with a java application that use Quarkus and Kafka.
I have a Kafka Consumer that reads from a topic but I need to read some data form a database before it start to consume.
My consumer looks like this:
@ApplicationScoped
public class Consumer {
private final Logger LOG = Logger.getLogger(Consumer.class);
@Inject
ObjectMapper objectMapper;
@Incoming("topic-in")
public void consume(ConsumerRecord<String, String> record) throws JsonProcessingException {
LOG.info(record.key());
Data myData = objectMapper.readValue(record.value(), Data.class);
myData.setKey(record.key());
// Do stuff...
}
}
I know that i can use @KafkaListener as describe here (Run a method before starting spring kafka-consumer) but I'd like to keep using Quarkus and the @Incoming annotation.
I also tried to fetch the data from the database using something like that void onStartup(@Observes StartupEvent startupEvent) but without luck