0

I have a message consumer like this one in Quarkus that consume messages in a queue :

@Incoming("incoming-messages")
@Blocking(ordered = false, value = "custom-worker-pool")
public Uni<Void> onExecutionReceive(final Message<JsonObject> message) {
       message.ack();
       // Do long process here 
       
       return Uni.createFrom().voidItem();
}

With associated configuration in application.properties :

smallrye.messaging.worker.custom-worker-pool.max-concurrency=3

This works well : A vertex worker thread consume my messages. But the problem occurs when my blocking process exceed 60s i get this warning :

.. has been blocked for 61159 ms, time limit is 60000 ms: io.vertx.core.VertxException: Thread blocked

In order to avoid that i would replace the vertex worker thread used by smallrye by a regular thread pool that has no time limitation for example something like Executors.newFixedThreadPool(3).

Is it possible to do so ? If yes how ?

user1549094
  • 21
  • 1
  • 4

1 Answers1

0

Since you're already using Uni. You can do something like:

@Incoming("incoming-messages")
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Blocking(ordered = false, value = "custom-worker-pool")
public Uni<Void> onExecutionReceive(final Message<JsonObject> message) {
       return Uni.createFrom().emitter((UniEmitter<? super Object> uniEmitter) -> {
                    try {
                        // do long-running stuff here
                        uniEmitter.complete(new Object()); // Possibly some job result to return if needed
                    } catch (Exception e) {
                        uniEmitter.fail(e);
                    }
                })
                .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) // worker pool can also be defined for subscription
                .onItem().invoke(message::ack)
                .onFailure().invoke(message::nack)
                .replaceWithVoid();
}

Possibly you can adapt it for your requirements (e.g play around with emitter some other form of creation of Uni)

Dmytro Chaban
  • 1,106
  • 1
  • 11
  • 19
  • I tried your solution but it doesn't work. When i add breakpoint on // do long-running stuff here it is never reached. Seems that try{...}catch{ ...} is simply never executed – user1549094 Jun 17 '23 at 14:49