当前位置: 首页>>代码示例>>Java>>正文


Java Vertx类代码示例

本文整理汇总了Java中io.vertx.reactivex.core.Vertx的典型用法代码示例。如果您正苦于以下问题:Java Vertx类的具体用法?Java Vertx怎么用?Java Vertx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Vertx类属于io.vertx.reactivex.core包,在下文中一共展示了Vertx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    Vertx vertx = Vertx.vertx();

    vertx.rxDeployVerticle(IOTGateway.class.getName())
        .flatMap(x ->
            vertx.rxDeployVerticle(
                DataProcessorVerticle.class.getName()))
        .flatMap(x ->
            vertx.rxDeployVerticle(
                WebVerticle.class.getName()))
        .flatMap(x ->
            vertx.rxDeployVerticle(
                Sensor.class.getName(),
                new DeploymentOptions().setInstances(5)))
        .subscribe();
}
 
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:17,代码来源:Main.java

示例2: setUp

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
@Before
public void setUp(TestContext testContext) {
  vertx = new Vertx(rule.vertx());
  Router router = Router.router(vertx);

  BookDatabaseService bookDatabaseService = Mockito.mock(BookDatabaseService.class);

  JsonArray mockDbResponse = new JsonArray()
    .add(new JsonObject()
      .put("id", 1)
      .put("title", "Effective Java")
      .put("category", "java")
      .put("publicationDate", "2009-01-01"))
    .add(new JsonObject()
      .put("id", 2)
      .put("title", "Thinking in Java")
      .put("category", "java")
      .put("publicationDate", "2006-02-20"));


  Mockito.when(bookDatabaseService.rxGetBooks(new Book())).thenReturn(Single.just(mockDbResponse));

  router.get("/books").handler(new GetBooksHandler(bookDatabaseService));

  vertx.createHttpServer().requestHandler(router::accept).listen(1234, testContext.asyncAssertSuccess());
}
 
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:27,代码来源:GetBooksHandlerTest.java

示例3: setUp

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
@Before
public void setUp(TestContext testContext) {
  vertx = new Vertx(rule.vertx());
  Router router = Router.router(vertx);

  BookDatabaseService bookDatabaseService = Mockito.mock(BookDatabaseService.class);

  JsonObject mockDbResponse = new JsonObject()
    .put("id", 1)
    .put("title", "Effective Java")
    .put("category", "java")
    .put("publicationDate", "2009-01-01");


  Mockito.when(bookDatabaseService.rxGetBookById(1)).thenReturn(Single.just(mockDbResponse));

  router.get("/books/:id").handler(new GetBookByIdHandler(bookDatabaseService));

  vertx.createHttpServer().requestHandler(router::accept).listen(1234, testContext.asyncAssertSuccess());
}
 
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:21,代码来源:GetBookByIdHandlerTest.java

示例4: KafkaSource

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
KafkaSource(Vertx vertx, JsonObject json) {
  super(KafkaConsumer.<String, T>create(vertx, toMap(json))
    .subscribe(json.getString("topic", json.getString("name")))
    .toFlowable()
    .map(KafkaSource::createDataFromRecord)
    .compose(upstream -> {
      int size = json.getInteger("multicast.buffer.size", 0);
      if (size > 0) {
        return upstream.replay(size).autoConnect();
      }

      Integer seconds = json.getInteger("multicast.buffer.period.ms", -1);
      if (seconds != -1) {
        return upstream.replay(seconds, TimeUnit.MILLISECONDS).autoConnect();
      }

      return upstream;
    })
  );

  name = json.getString("name");
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:23,代码来源:KafkaSource.java

示例5: main

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  init();

  Vertx vertx = Vertx.vertx();
  vertx.deployVerticle(WebVerticle.class.getName());

  FluidRegistry.initialize(vertx);

  // Sensors
  createSensor();
  createSensor();

  // Mediation
  source("sensor", JsonObject.class)
    .transformPayload(json -> json.getDouble("data"))
    .transformPayloadFlow(flow ->
      flow.window(5)
        .flatMap(MathFlowable::averageDouble))
    .to(sink("eb-average"));

}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:22,代码来源:Main.java

示例6: createSourcesFromConfiguration

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
public static Map<String, Source> createSourcesFromConfiguration(Vertx vertx) {
  Map<String, Source> map = new HashMap<>();
  Optional<JsonNode> node = FluidConfig.get("sources");

  if (node.isPresent()) {
    Iterator<String> names = node.get().fieldNames();
    while (names.hasNext()) {
      String name = names.next();
      LOGGER.info("Creating source from configuration `" + name + "`");
      JsonNode conf = node.get().get(name);
      Source<?> source = buildSource(FluidConfig.mapper(), vertx, name, conf);
      map.put(name, source);
    }
  } else {
    LOGGER.warn("No sources configured from the fluid configuration");
  }

  return map;
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:20,代码来源:SourceAndSinkBuilder.java

示例7: createSinksFromConfiguration

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
public static Map<String, Sink> createSinksFromConfiguration(Vertx vertx) {
  Map<String, Sink> map = new HashMap<>();
  Optional<JsonNode> node = FluidConfig.get("sinks");

  if (node.isPresent()) {
    Iterator<String> names = node.get().fieldNames();
    while (names.hasNext()) {
      String name = names.next();
      LOGGER.info("Creating sink from configuration `" + name + "`");
      JsonNode conf = node.get().get(name);
      Sink<?> source = buildSink(FluidConfig.mapper(), vertx, name, conf);
      map.put(name, source);
    }
  } else {
    LOGGER.warn("No sinks configured from the fluid configuration");
  }
  return map;
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:19,代码来源:SourceAndSinkBuilder.java

示例8: buildSource

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
private static Source buildSource(ObjectMapper mapper, Vertx vertx, String name, JsonNode config) {
  String type = config.get("type").asText(null);
  if (type == null) {
    throw new NullPointerException("Invalid configuration, the config " + name + " has no `type`");
  }

  SourceFactory factory = lookupForSourceFactory(type);
  if (factory == null) {
    throw new NullPointerException("Invalid configuration, the source type " + type + " is unknown");
  }

  try {
    String json = mapper.writeValueAsString(config);
    return factory.create(vertx, new JsonObject(json).put("name", name)).blockingGet();
  } catch (JsonProcessingException e) {
    throw new IllegalArgumentException("Invalid configuration for " + name, e);
  }
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:19,代码来源:SourceAndSinkBuilder.java

示例9: buildSink

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
private static Sink buildSink(ObjectMapper mapper, Vertx vertx, String name, JsonNode config) {
  String type = config.get("type").asText(null);
  if (type == null) {
    throw new NullPointerException("Invalid configuration, the config " + name + " has no `type`");
  }

  SinkFactory factory = lookupForSinkFactory(type);
  if (factory == null) {
    throw new NullPointerException("Invalid configuration, the sink type " + type + " is unknown");
  }

  try {
    String json = mapper.writeValueAsString(config);
    return factory.create(vertx, new JsonObject(json).put("name", name)).blockingGet();
  } catch (JsonProcessingException e) {
    throw new IllegalArgumentException("Invalid configuration for " + name, e);
  }
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:19,代码来源:SourceAndSinkBuilder.java

示例10: EventBusSource

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
public EventBusSource(Vertx vertx, JsonObject json) {
  super(vertx.eventBus()
    .<T>consumer(json.getString("address"))
    .toFlowable()
    .map(EventBusSource::createData)
    .compose(upstream -> {
      Integer size = json.getInteger("multicast.buffer.size", -1);
      if (size != -1) {
        return upstream.replay(size).autoConnect();
      }

      Integer seconds = json.getInteger("multicast.buffer.period.ms", -1);
      if (seconds != -1) {
        return upstream.replay(seconds, TimeUnit.MILLISECONDS).autoConnect();
      }

      return upstream;
    }));
  name = json.getString("name");
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:21,代码来源:EventBusSource.java

示例11: testGetRequest

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url, String expectedResult) {
  HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
  Async async = context.async();
  client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
      resp -> resp.bodyHandler(body -> {
        context.assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
        context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
        context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
            resp.getHeader(EXPECTED_RESPONSE_HEADER));
        try {
          context.assertEquals(body.toString(),
              expectedResult, "Wrong engines processed request, expected " + expectedResult);
        } catch (Exception e) {
          context.fail(e);
        }
        client.close();
        async.complete();
      }));
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:20,代码来源:KnotxServerRoutingTest.java

示例12: whenDoPostSecureWithoutCSRF_expectForbidden

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostSecureWithoutCSRF_expectForbidden(
    TestContext context) {
  Async async = context.async();

  createPassThroughKnot("test-splitter");
  createPassThroughKnot("test-assembler");
  createSimpleKnot("some-knot", "test", null);

  MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");

  WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
  client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
      .sendForm(body, ar -> {
        if (ar.succeeded()) {
          context.assertEquals(HttpResponseStatus.FORBIDDEN.code(), ar.result().statusCode());
          async.complete();
        } else {
          context.fail(ar.cause());
          async.complete();
        }
      });
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:25,代码来源:KnotxServerCsrfTest.java

示例13: whenDoPostPublicWithoutCSRF_expectOk

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostPublicWithoutCSRF_expectOk(
    TestContext context) {
  Async async = context.async();

  createPassThroughKnot("test-splitter");
  createPassThroughKnot("test-assembler");
  createSimpleKnot("some-knot", "test", null);

  MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");

  WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
  client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html")
      .sendForm(body, ar -> {
        if (ar.succeeded()) {
          context.assertEquals(HttpResponseStatus.OK.code(), ar.result().statusCode());
          async.complete();
        } else {
          context.fail(ar.cause());
          async.complete();
        }
      });
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:25,代码来源:KnotxServerCsrfTest.java

示例14: testGetRequest

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url) {
  HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
  Async async = context.async();
  client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
      resp -> {
        MultiMap headers = resp.headers();
        headers.names().forEach(name -> {
          context.assertEquals(resp.statusCode(), 200, "Wrong status code received.");
          context
              .assertTrue(expectedHeaders.contains(name), "Header " + name + " is not expected.");
          context.assertEquals(expectedHeaders.get(name), headers.get(name),
              "Wrong value of " + name + " header.");
        });
        async.complete();
      });
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:SampleApplicationHeadersTest.java

示例15: testGetRequest

import io.vertx.reactivex.core.Vertx; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url, String expectedResponseFile) {
  HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
  Async async = context.async();
  client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
      resp -> resp.bodyHandler(body -> {
        context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
        try {
          context.assertEquals(Jsoup.parse(body.toString()).body().html().trim(),
              Jsoup.parse(FileReader.readText(expectedResponseFile)).body().html().trim());
        } catch (Exception e) {
          context.fail(e);
        }
        client.close();
        async.complete();
      }));
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:SampleApplicationTest.java


注:本文中的io.vertx.reactivex.core.Vertx类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。