[英]Can I configure the pool size of a specific Quarkus Vertx ConsumeEvent?
The parameter quarkus.vertx.worker-pool-size
allows me to configure the "Thread size of the worker thread pool", according to the quarkus guide - All configuration options .根据quarkus 指南 - 所有配置选项,参数
quarkus.vertx.worker-pool-size
允许我配置“工作线程池的线程大小”。
Is it possible to configure the pool size of a specific Quarkus ConsumeEvent like this:是否可以像这样配置特定 Quarkus ConsumeEvent 的池大小:
@io.quarkus.vertx.ConsumeEvent(value = "my-consume-event", blocking = true)
public void start(String value) {
// do the work
}
I would like to set the number of threads that can process this my-consume-event
without changing the global quarkus.vertx.worker-pool-size
.我想在不更改全局
quarkus.vertx.worker-pool-size
的情况下设置可以处理此my-consume-event
的线程数。
On the SmallRye Reactive Messaging guide there's one example of what I want to do.在SmallRye Reactive Messaging 指南中有一个我想做的事的例子。
Here, I can use one Blocking annotation, define one name for it and configure the thread pool:在这里,我可以使用一个 Blocking 注释,为其定义一个名称并配置线程池:
@Outgoing("Y")
@Incoming("X")
@Blocking("my-custom-pool")
public String process(String s) {
return s.toUpperCase();
}
Specifying the concurrency for the above worker pool requires the following configuration property to be defined:
为上述工作池指定并发需要定义以下配置属性:
smallrye.messaging.worker.my-custom-pool.max-concurrency=3
In this example, I can configure the size of the thread pool that will process the messages from the my-custom-pool
.在此示例中,我可以配置将处理来自
my-custom-pool
的消息的线程池的大小。
Thanks谢谢
@io.smallrye.common.annotation.Blocking("my-custom-pool")
@io.smallrye.common.annotation.Blocking("my-custom-pool")
I tried to set a value to the @io.smallrye.common.annotation.Blocking("my-custom-pool")
annotation, but I receive the following error:我试图为
@io.smallrye.common.annotation.Blocking("my-custom-pool")
注释设置一个值,但我收到以下错误:
The attribute value is undefined for the annotation type Blocking
I'm using this dependency:我正在使用这种依赖:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
I also created this project on my GitHub account to do this test.我还在我的 GitHub 帐户上创建了这个项目来做这个测试。
package org.acme;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.jboss.logging.Logger;
import io.vertx.core.eventbus.EventBus;
@Path("/hello")
public class GreetingResource {
private static final Logger LOG = Logger.getLogger(GreetingResource.class);
@Inject
EventBus eventBus;
@GET
public Response hello() {
LOG.info("hello()");
eventBus.send("my-consume-event", null);
return Response
.status(Response.Status.ACCEPTED)
.build();
}
@io.quarkus.vertx.ConsumeEvent("my-consume-event")
// @io.smallrye.common.annotation.Blocking("my-custom-pool")
@io.smallrye.common.annotation.Blocking
public void start(String value) {
try {
LOG.info("before the sleep");
Thread.sleep(5000);
LOG.info("after the sleep");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
You should be able to use the @io.smallrye.common.annotation.Blocking
annotation:您应该能够使用
@io.smallrye.common.annotation.Blocking
注释:
@ConsumeEvent("my-consume-event")
@Blocking("my-custom-pool")
public void start(String value) {
// do the work
}
And configure your pool size in application.properties
:并在
application.properties
中配置您的池大小:
smallrye.messaging.worker.my-custom-pool.max-concurrency=3
EDIT编辑
Actually, the @io.smallrye.reactive.messaging.annotations.Blocking
is not supported on methods annotated with @ConsumeEvent
.实际上,
@io.smallrye.reactive.messaging.annotations.Blocking
在使用@ConsumeEvent
注释的方法上不受支持。
Also, according to ConsumeEvent with Blocking Threading on wrong ExecutorService #19911 , it seems events are executed on the default Quarkus executor.此外,根据ConsumeEvent with Blocking Threading on wrong ExecutorService #19911 ,事件似乎是在默认的 Quarkus 执行器上执行的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.