Java Code Examples for io.vertx.core.Vertx#deployVerticle()

The following examples show how to use io.vertx.core.Vertx#deployVerticle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertxUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx,
    Class<VERTICLE> cls,
    DeploymentOptions options) throws InterruptedException {
  Holder<Boolean> result = new Holder<>();

  CountDownLatch latch = new CountDownLatch(1);
  vertx.deployVerticle(cls.getName(), options, ar -> {
    result.value = ar.succeeded();

    if (ar.failed()) {
      LOGGER.error("deploy vertx failed, cause ", ar.cause());
    }

    latch.countDown();
  });

  latch.await();

  return result.value;
}
 
Example 2
Source File: Application.java    From skywalking with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    //ensures .vertx files are uncreated/deleted
    System.setProperty("vertx.disableFileCPResolving", "true");
    Vertx vertx = Vertx.vertx();
    if (new File(".vertx").exists()) {
        Files.walk(new File(".vertx").toPath())
                .sorted(Comparator.reverseOrder())
                .map(Path::toFile)
                .forEach(File::delete);
    }

    vertx.deployVerticle(new VertxWebController(), it -> {
        if (it.failed()) {
            it.cause().printStackTrace();
            System.exit(-1);
        }
    });
}
 
Example 3
Source File: ShellExamples.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
public void deploySSHServiceWithShiro(Vertx vertx) throws Exception {
  vertx.deployVerticle("maven:{maven-groupId}:{maven-artifactId}:{maven-version}",
    new DeploymentOptions().setConfig(new JsonObject().
      put("sshOptions", new JsonObject().
        put("host", "localhost").
        put("port", 5000).
        put("keyPairOptions", new JsonObject().
          put("path", "src/test/resources/ssh.jks").
          put("password", "wibble")).
        put("authOptions", new JsonObject().
          put("provider", "shiro").
          put("config", new JsonObject().
            put("properties_path", "file:/path/to/my/auth.properties"))))
    )
  );
}
 
Example 4
Source File: ShellExamples.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
public void deploySSHServiceWithMongo(Vertx vertx) throws Exception {
  vertx.deployVerticle("maven:{maven-groupId}:{maven-artifactId}:{maven-version}",
    new DeploymentOptions().setConfig(new JsonObject().
      put("sshOptions", new JsonObject().
        put("host", "localhost").
        put("port", 5000).
        put("keyPairOptions", new JsonObject().
          put("path", "src/test/resources/ssh.jks").
          put("password", "wibble")).
        put("authOptions", new JsonObject().
          put("provider", "mongo").
          put("config", new JsonObject().
            put("connection_string", "mongodb://localhost:27018"))))
    )
  );
}
 
Example 5
Source File: IntegrationTest.java    From vertx-junit5 with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Start a HTTP server, then issue a HTTP client request and check the response")
void vertx_check_http_server_response() throws InterruptedException {
  Vertx vertx = Vertx.vertx();
  VertxTestContext testContext = new VertxTestContext();

  vertx.deployVerticle(new HttpServerVerticle(), testContext.succeeding(id -> {
    HttpClient client = vertx.createHttpClient();
    client.get(8080, "localhost", "/")
      .flatMap(HttpClientResponse::body)
      .onFailure(testContext::failNow)
      .onSuccess(buffer -> testContext.verify(() -> {
        assertThat(buffer.toString()).isEqualTo("Plop");
        testContext.completeNow();
      }));
  }));

  assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
  closeVertx(vertx);
}
 
Example 6
Source File: TypeScriptVerticleTest.java    From vertx-lang-typescript with Apache License 2.0 6 votes vote down vote up
private void doTest(String verticle, String message, TestContext context) throws IOException {
  Async async = context.async();
  int port = getAvailablePort();
  JsonObject config = new JsonObject().put("port", port);
  DeploymentOptions options = new DeploymentOptions().setConfig(config);
  Vertx vertx = runTestOnContext.vertx();
  vertx.deployVerticle(verticle, options, context.asyncAssertSuccess(deploymentID -> {
    HttpClient client = vertx.createHttpClient();
    // retry for 30 seconds and give the verticle a chance to launch the server
    makeRequest(client, port, 30, 1000, context.asyncAssertSuccess(buffer -> {
      context.assertEquals(message, buffer.toString());
      vertx.undeploy(deploymentID, context.asyncAssertSuccess(r -> async.complete()));
      client.close();
    }));
  }));
}
 
Example 7
Source File: Application.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
/**
 * Deploys the HTTP bridge into a new verticle
 *
 * @param vertx                 Vertx instance
 * @param bridgeConfig          Bridge configuration
 * @param metricsReporter       MetricsReporter instance for scraping metrics from different registries
 * @return                      Future for the bridge startup
 */
private static Future<HttpBridge> deployHttpBridge(Vertx vertx, BridgeConfig bridgeConfig, MetricsReporter metricsReporter)  {
    Promise<HttpBridge> httpPromise = Promise.promise();

    if (bridgeConfig.getHttpConfig().isEnabled()) {
        HttpBridge httpBridge = new HttpBridge(bridgeConfig, metricsReporter);
        
        vertx.deployVerticle(httpBridge, done -> {
            if (done.succeeded()) {
                log.info("HTTP verticle instance deployed [{}]", done.result());
                httpPromise.complete(httpBridge);
            } else {
                log.error("Failed to deploy HTTP verticle instance", done.cause());
                httpPromise.fail(done.cause());
            }
        });
    } else {
        httpPromise.complete();
    }

    return httpPromise.future();
}
 
Example 8
Source File: ShellExamples.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
public void deployTelnetService(Vertx vertx) throws Exception {
  vertx.deployVerticle("maven:{maven-groupId}:{maven-artifactId}:{maven-version}",
    new DeploymentOptions().setConfig(
      new JsonObject().put("telnetOptions",
        new JsonObject().
          put("host", "localhost").
          put("port", 4000))
    )
  );
}
 
Example 9
Source File: SensorDataTest.java    From vertx-in-action with MIT License 5 votes vote down vote up
@Test
void testAverage(Vertx vertx, VertxTestContext ctx) {
  EventBus bus = vertx.eventBus();
  vertx.deployVerticle(new SensorData(), ctx.succeeding(id -> {
    bus.publish("sensor.updates", new JsonObject()
      .put("id", "a").put("temp", 20.0d));
    bus.publish("sensor.updates", new JsonObject()
      .put("id", "b").put("temp", 22.0d));
    bus.request("sensor.average", "", ctx.succeeding(reply -> ctx.verify(() -> {
      JsonObject json = (JsonObject) reply.body();
      assertEquals(21.0d, (double) json.getDouble("average"));
      ctx.completeNow();
    })));
  }));
}
 
Example 10
Source File: Examples.java    From vertx-unit with Apache License 2.0 5 votes vote down vote up
@Source(translate = false)
public static void asyncAssertSuccess_01(Vertx vertx, TestContext context) {
  Async async = context.async();
  vertx.deployVerticle("my.verticle", ar -> {
    if (ar.succeeded()) {
      async.complete();
    } else {
      context.fail(ar.cause());
    }
  });

  // Can be replaced by

  vertx.deployVerticle("my.verticle", context.asyncAssertSuccess());
}
 
Example 11
Source File: GeneratorConfigVerticleTest.java    From vertx-microservices-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException {
  byte[] bytes = Files.readAllBytes(new File("src/test/resources/config.json").toPath());
  JsonObject config = new JsonObject(new String(bytes, "UTF-8"));

  Vertx vertx = Vertx.vertx();

  List<JsonObject> mch = new ArrayList<>();
  List<JsonObject> dvn = new ArrayList<>();
  List<JsonObject> bct = new ArrayList<>();

  vertx.eventBus().consumer(GeneratorConfigVerticle.ADDRESS, message -> {
    JsonObject quote = (JsonObject) message.body();
    System.out.println(quote.encodePrettily());
    assertThat(quote.getDouble("bid")).isGreaterThan(0);
    assertThat(quote.getDouble("ask")).isGreaterThan(0);
    assertThat(quote.getInteger("volume")).isGreaterThan(0);
    assertThat(quote.getInteger("shares")).isGreaterThan(0);
    switch (quote.getString("symbol")) {
      case "MCH":
        mch.add(quote);
        break;
      case "DVN":
        dvn.add(quote);
        break;
      case "BCT":
        bct.add(quote);
        break;
    }
  });

  vertx.deployVerticle(GeneratorConfigVerticle.class.getName(), new DeploymentOptions().setConfig(config));

  await().until(() -> mch.size() > 10);
  await().until(() -> dvn.size() > 10);
  await().until(() -> bct.size() > 10);
}
 
Example 12
Source File: AnalyticsTest.java    From vertx-starter with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void beforeEach(Vertx vertx, VertxTestContext testContext) throws IOException {
  vertx.eventBus().registerDefaultCodec(VertxProject.class, new VertxProjectCodec());

  JsonObject config = new JsonObject()
    .put("host", mongo.getContainerIpAddress())
    .put("port", mongo.getMappedPort(27017));

  client = MongoClient.create(vertx, config);

  DeploymentOptions options = new DeploymentOptions().setConfig(config);
  vertx.deployVerticle(new AnalyticsVerticle(), options, testContext.succeeding(id -> testContext.completeNow()));
}
 
Example 13
Source File: Application.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(new CamelVerticle());
    vertx.deployVerticle(new HttpVerticle());
}
 
Example 14
Source File: Exercise4.java    From vertx-kubernetes-workshop with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(Exercise4SenderVerticle.class.getName());
    vertx.deployVerticle(Exercise4ReceiverVerticle.class.getName());
}
 
Example 15
Source File: Main.java    From vertx-in-action with MIT License 4 votes vote down vote up
public static void main(String[] args) {
  Vertx vertx = Vertx.vertx();
  vertx.deployVerticle(new Jukebox());
  vertx.deployVerticle(new NetControl());
}
 
Example 16
Source File: LifecycleExampleTest.java    From vertx-junit5 with Apache License 2.0 4 votes vote down vote up
@BeforeEach
@DisplayName("Deploy a verticle")
void prepare(Vertx vertx, VertxTestContext testContext) {
  vertx.deployVerticle(new SomeVerticle(), testContext.succeedingThenComplete());
}
 
Example 17
Source File: Main.java    From vertx-in-action with MIT License 4 votes vote down vote up
public static void main(String[] args) {
  Vertx vertx = Vertx.vertx();
  vertx.deployVerticle(new Deployer());
}
 
Example 18
Source File: BlockEventLoop.java    From vertx-in-action with MIT License 4 votes vote down vote up
public static void main(String[] args) {
  Vertx vertx = Vertx.vertx();
  vertx.deployVerticle(new BlockEventLoop());
}
 
Example 19
Source File: Main.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();

    vertx.deployVerticle(SimpleVerticle.class.getName(), new DeploymentOptions()
        .setConfig(new JsonObject().put("message", "bonjour")));
}
 
Example 20
Source File: VertxSpringApplication.java    From tutorials with MIT License 4 votes vote down vote up
@PostConstruct
public void deployVerticle() {
    final Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(serverVerticle);
    vertx.deployVerticle(serviceVerticle);
}