vert.x - Vertx.deployVerticle 不调用提供的完成处理程序

标签 vert.x vertx-verticle

我编写了一个服务,其中已部署的 Verticle 链接到休息端点。该服务正在 100% 运行(我动态部署了 verticle 并调用 REST 端点在 verticle 上执行函数)。问题是所提供的完成处理程序永远不会被调用。有什么想法吗?

以下是我的代码:

        LOGGER.debug(String.format("Starting runner %s:%s:%s" ,functionName, faasFunctionClass, fileName));

        DeploymentOptions deploymentOptions = new DeploymentOptions();
        deploymentOptions.setInstances(1);
        JsonObject jsonObject = new JsonObject();
        jsonObject.put(FUNCTION_NAME, functionName);
        jsonObject.put(FUNCTION_CLASS, faasFunctionClass);
        jsonObject.put(FUNCTION_FILENAME, fileName);

        deploymentOptions.setConfig(jsonObject);

        LOGGER.debug(String.format("Deploying [%s]" ,jsonObject.encode()));
        this.vertx.deployVerticle("faas:" + VertxFaasRunner.class.getCanonicalName(),deploymentOptions, event->{
            if (event.succeeded()) {
                System.out.println("Deployment id is: " + event.result());
            } else {
                System.out.println("Deployment failed!");
            }
        });

最佳答案

在这种情况下,这取决于您如何实现您的垂直领域。

在下面的代码中,当执行 future.complete() 时,只有 event.succeeded() 将为 true。

public class MainVerticle extends AbstractVerticle {

    @Override
    public void start() throws Exception {
        System.out.println("[Main] Running in " + Thread.currentThread().getName());
        vertx
                .deployVerticle("io.vertx.example.core.verticle.worker.WorkerVerticle",
                        new DeploymentOptions().setWorker(true), event -> {
                            if (event.succeeded()) {
                                System.out.println("Deployment id is: " + event.result());
                            } else {
                                System.out.println("Deployment failed!");
                            }
                        });

    }
}

 public class WorkerVerticle extends AbstractVerticle {
  @Override
  public void start(Future future) throws Exception {
    System.out.println("[Worker] Starting in " + Thread.currentThread().getName());

    vertx.eventBus().<String>consumer("sample.data", message -> {
      System.out.println("[Worker] Consuming data in " + Thread.currentThread().getName());
      String body = message.body();
      message.reply(body.toUpperCase());
    });
    // this notifies that the verticle is deployed successfully.
    future.complete();
  }
 } 

关于vert.x - Vertx.deployVerticle 不调用提供的完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062075/

相关文章:

java - 在 vert.x 中,为什么静态方法在静态代码块之前运行?

java - Verticle 核心上的多个实例

java - onErrorReturn rx java 中的断言不会失败

java - 无法使用 Guice 和 Vertx 将同一实例注入(inject)多个 Verticles

java - lambda 表达式中的 AtomicInteger 变量

java - 用于非阻塞IO调用的aspectj计时器

java - 将 Thymeleaf TemplateEngine 与 Vert.x 3.9 结合使用

java - Vert.x,RoutingContext无法接收json数组