I need to consume messages from RabbitMQ in a microservice written using Quarkus. I tried to use the smallrye-reactive-messaging for Quarkus but faced two problems:
WARNING [io.ver.cor.imp.BlockedThreadChecker] (vertx-blocked-thread-checker) Thread Thread[vert.x-eventloop-thread-0,5,main]=Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 212088 ms, time limit is 2000 ms: io.vertx.core.VertxException: Thread blocked
So my idea for a workaround is to start a thread for consuming and processing the messages somewhere in Quarkus when it boots up. There's a support for scheduling periodic tasks in Quarkus is there's an annotation for background processes or do I have to write my own extension?
In the end I've solved my problem by using ActiveMQ Artemis and rewriting my database code using the reactive pattern. Another approach might have been using the io.vertx.rabbitmq.RabbitMQClient
in Vert.x.
In case someone came here looking for how and where a background process can be started in Quarkus I found the answer in the book Quarkus Cookbook (Chapter 5.9). There's also a section on Application Life Cycle Events in the official documentation.
So to execute some code when Quarkus boots you observe the StartupEvent
in your bean:
import io.quarkus.runtime.StartupEvent;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class AppLifeEventListener {
void onStart(@Observes StartupEvent event) {
// start you background thread here
}
}