2

I writing a service where a deployed verticle is linked to a rest endpoint. The service is working 100% (I dynamically deployed the verticle and calling the REST endpoint execute a function on the verticle). The problem is that the supplied completion handler is never called. Any ideas?

Following is my code:

        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!");
            }
        });
davilj
  • 101
  • 2
  • 6

1 Answers1

2

In this case it depends on how you have implemented your Verticle.

in the below code when future.complete() is executed then only event.succeeded() will be 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();
  }
 } 
Kishore Tulsiani
  • 1,106
  • 13
  • 29