2

我编写了一个服务,其中部署的 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!");
            }
        });
4

1 回答 1

2

在这种情况下,这取决于您如何实现 Verticle。

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

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();
  }
 } 
于 2017-11-01T21:44:34.927 回答