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:
- it only supports AMQP 1.0 and doesn't work with RabbitMQ (even if I use the experimental AMQP 1.0 plugin).
- it works with ActiveMQ Artemis but there's another issue: The smallrye-reactive-messaging is... reactive which is nice but there's no time right now to rewrite my database code to be reactive. Processing the message means persisting tens of thousands of documents to the mongodb which can take several minutes and it seems to be blocking the whole server:
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: