當前位置: 首頁>>代碼示例>>Java>>正文


Java Vertx.vertx方法代碼示例

本文整理匯總了Java中io.vertx.core.Vertx.vertx方法的典型用法代碼示例。如果您正苦於以下問題:Java Vertx.vertx方法的具體用法?Java Vertx.vertx怎麽用?Java Vertx.vertx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.Vertx的用法示例。


在下文中一共展示了Vertx.vertx方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: prepare

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Before
public void prepare(TestContext context) {
  vertx = Vertx.vertx();

  JsonObject dbConf = new JsonObject()
    .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") // <1>
    .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4);

  vertx.deployVerticle(new WikiDatabaseVerticle(),
    new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess());

  vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess());

  webClient = WebClient.create(vertx, new WebClientOptions()
    .setDefaultHost("localhost")
    .setDefaultPort(8080));
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:18,代碼來源:ApiTest.java

示例2: handleRequest

import io.vertx.core.Vertx; //導入方法依賴的package包/類
/**
 * This is a handler method called by the AWS Lambda runtime
 */
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {

    // Lambda function is allowed write access to /tmp only
    System.setProperty("vertx.cacheDirBase", "/tmp/.vertx");

    Vertx vertx = Vertx.vertx();

    router = Router.router(vertx);

    router.route().handler(rc -> {
        LocalDateTime now = LocalDateTime.now();
        rc.response().putHeader("content-type", "text/html").end("Hello from Lambda at " + now);
    });

    // create a LambdaServer which will process a single HTTP request
    LambdaServer server = new LambdaServer(vertx, context, input, output);

    // trigger the HTTP request processing
    server.requestHandler(this::handleRequest).listen();

    // block the main thread until the request has been fully processed
    waitForResponseEnd();
}
 
開發者ID:noseka1,項目名稱:vertx-aws-lambda,代碼行數:28,代碼來源:SampleApp.java

示例3: testGetNode

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
	public void testGetNode() {
		Vertx vertx = Vertx.vertx();
		WebClient http = WebClient.create(vertx);
		App a = new App(vertx,http,"test");
		WeightNodeStrategy w = new WeightNodeStrategy();
		w.addNode(a.createDevNode("10.10.10.1",80,1));
		w.addNode(a.createDevNode("10.10.10.2",80,2));
		w.addNode(a.createDevNode("10.10.10.3",80,3));
		w.addNode(a.createDevNode("10.10.10.4",80,4));
		w.addNode(a.createDevNode("10.10.10.5",80,5));
		w.addNode(a.createDevNode("10.10.10.6",80,6));
		w.addNode(a.createDevNode("10.10.10.7",80,7));
		w.addNode(a.createDevNode("10.10.10.8",80,8));
		w.addNode(a.createDevNode("10.10.10.9",80,9));
		w.addNode(a.createDevNode("10.10.10.10",80,10));
		
		for(int i=0; i<100 ;i++){
//			Node n = w.getNode(null);
//			System.out.println(n);
			System.out.println(w.getNode(null).toString());
		}
		
		
	}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:26,代碼來源:TestNodeSelectStrategy.java

示例4: prepare

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@BeforeEach
public void prepare() {
  MockitoAnnotations.initMocks(this);

  vertx = Vertx.vertx();

  dataset = TestFixture.aPersistedDataset();
  select = "select";
  where = "where";

  // asOf is tested elsewhere, from the perspective of this test case it is simply an external
  // collaborator with
  // the same behaviour for every test in this test case
  asOf = mock(AsOf.class);
  when(asOf.applyAsOf(where)).thenReturn(where);
  when(asOfFactory.create(
          eq(dataset.getSubscriptionControlField()),
          eq(dataset.getSubscriptionControlFieldPattern()),
          any(LocalDateTime.class)))
      .thenReturn(asOf);

  subscriptionManager = new VertxSubscriptionManager(vertx, datasetDao, reader, asOfFactory);
}
 
開發者ID:glytching,項目名稱:dragoman,代碼行數:24,代碼來源:VertxSubscriptionManagerTest.java

示例5: testImplicitMode

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public void testImplicitMode() {
    vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    HttpRequest<Buffer> request = client.postAbs("http://admin:[email protected]:8080/oauth/authorize?response_type=token&scope=read%20write&client_id=myClientId&redirect_uri=http://example.com");
    request.putHeader("Authorization", getHeader());
    request.send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            //String location = response.getHeader("Location");
            String body = response.bodyAsString();
            System.out.println("Implicit Mode Get Token" + body + " status code" + response.statusCode() + " Location=");
        } else {
            System.out.println("Something went wrong " + ar.cause().getMessage());
        }
    });
}
 
開發者ID:openmg,項目名稱:metagraph-auth,代碼行數:17,代碼來源:VertxWebTest.java

示例6: testAuthorizationCode

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public void testAuthorizationCode() {
    vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    HttpRequest<Buffer> request = client.postAbs("http://admin:[email protected]:8080/oauth/authorize?client_id=myClientId&client_secret=myClientSecret&redirect_uri=http://example.com&response_type=code&scope=read%20write");
    request.putHeader("Authorization", getHeader());
    request.send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            String body = response.bodyAsString();
            System.out.println("Authorization Code Mode Get Token" + body + " status code" + response.statusCode());
        } else {
            System.out.println("Something went wrong " + ar.cause().getMessage());
        }
    });
}
 
開發者ID:openmg,項目名稱:metagraph-auth,代碼行數:16,代碼來源:VertxWebTest.java

示例7: before

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Before
public void before(TestContext context) {
    vertx = Vertx.vertx();
    vertx.exceptionHandler(context.exceptionHandler());
    vertx.deployVerticle(TradeRecommendationsService.class.getName(), context.asyncAssertSuccess());
    client = WebClient.create(vertx);
}
 
開發者ID:qodfathr,項目名稱:trade-insights-service,代碼行數:8,代碼來源:HttpApplicationTest.java

示例8: HttpClientTest

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
public void HttpClientTest() {
    Vertx vertx = Vertx.vertx();
    System.out.println("===================Test start===================");
    HttpClient client = vertx.createHttpClient();
    client.get(8080, "localhost", "/api/prod/dfsad", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).end();
}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:10,代碼來源:NetworkUtilTest.java

示例9: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    NetworkUtils.init();
    System.out.println("===================Test start===================");
    vertx.deployVerticle(new AbstractVerticle() {
        @Override
        public void start() throws Exception {
            NetworkUtils.asyncPostString("http://breo.turing.asia/gzwx/smartBox/poll", System.out::println);
        }
    });

}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:13,代碼來源:NetworkUtilTest.java

示例10: initVertx

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public void initVertx(@Observes @Initialized(ApplicationScoped.class) Object obj) {

        System.setProperty("vertx.disableDnsResolver", "true");

        this.vertx = Vertx.vertx();

        this.vertx.eventBus().registerDefaultCodec(ChatMessage.class, new ChatMessageCodec());
        this.vertx.eventBus().registerDefaultCodec(PersonName.class, new PersonNameCodec());
        this.vertx.eventBus().registerDefaultCodec(String[].class, new StringArrayCodec());

        allDiscoveredVerticles.forEach(v -> {
            System.out.println("Found verticle "+v);
            vertx.deployVerticle(v);
        });
    }
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:16,代碼來源:VertxLauncher.java

示例11: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	vertx.setPeriodic(2000, id -> {
		System.out.println("Timer fired with id : " +  id);
	});
	vertx.setPeriodic(5000, id -> {
		throw new RuntimeException("I failed in second timer");
	});
	
	try {
		TimeUnit.SECONDS.sleep(10);
	} catch (InterruptedException e) {
	}
	vertx.close();
}
 
開發者ID:gauravrmazra,項目名稱:gauravbytes,代碼行數:16,代碼來源:VertxPeriodicTimerExample.java

示例12: start

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@PostConstruct
public void start() {

    LOG.debug("Application={}", Microservice.getApplicationClass());

    vertx = Vertx.vertx(vertxOptions);
    if (Microservice.getApplicationClass() == null) {
        LOG.warn("No application class specified, assuming running as a unit test");
        return;
    }
    final Router router = Router.router(vertx);

    handlerStack.push(SwaggerHandler.registerToRouter(router, Microservice.getApplicationClass()));
    handlerStack.push(ManifestHandler.registerToRouter(router));

    final Handler<RoutingContext> notFoundHandler = ctx -> ctx.response().setStatusCode(404).setStatusMessage(Status.NOT_FOUND.getReasonPhrase()).end(Status.NOT_FOUND.getReasonPhrase());
    router.get("/favicon.ico").handler(notFoundHandler);

    // Register engine implementation classes
    applicationContext.register(GsonJacksonJsonOps.class,
        GsonProvider.class,
        JcaCryptoOps.class,
        CachedDataProvider.class,
        JwksRouteHandler.class,
        CommonMsJaxRs.class);
    final SpringJaxRsHandler springJaxRsHandler = new SpringJaxRsHandler(applicationContext, Microservice.getApplicationClass());

    jaxRsRouter.register(Microservice.getApplicationClass(), router, springJaxRsHandler, springJaxRsHandler);

    handlerStack.push(springJaxRsHandler);

    final Handler<RoutingContext> jwksRouteHandler = applicationContext.getBean(JwksRouteHandler.class);

    // Prioritize JWKS higher than default router.
    router.route("/.well-known/jwks").order(-1).handler(jwksRouteHandler);

    final HttpServer http = vertx.createHttpServer(httpServerOptions);

    http.requestHandler(router::accept).listen(res -> {
        if (res.failed()) {
            LOG.error("Listening on port {} failed", httpServerOptions.getPort(), res.cause());
            SpringApplication.exit(applicationContext, () -> -1);
        } else {
            LOG.info("Listening on port {}", http.actualPort());
            thePort = http.actualPort();
        }
    });
    try {
        theHostname = InetAddress.getLocalHost().getHostName();
    } catch (final UnknownHostException e) {
        throw new ExceptionInInitializerError(e);
    }
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:54,代碼來源:VertxMicroserviceEngine.java

示例13: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	DeploymentOptions options = new DeploymentOptions().setWorker(true);
	vertx.deployVerticle(new MyTestVerticle(), options);
	vertx.close();
}
 
開發者ID:gauravrmazra,項目名稱:gauravbytes,代碼行數:7,代碼來源:VerticleExample.java

示例14: setUp

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Before
public void setUp(@NotNull TestContext context) {
  this.context = context;
  this.vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(options.apply(new VertxPrometheusOptions())));
}
 
開發者ID:nolequen,項目名稱:vertx-prometheus-metrics,代碼行數:6,代碼來源:PrometheusMetricsTestCase.java

示例15: setup

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Before
public void setup() {
  vertx = Vertx.vertx();
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:5,代碼來源:PgPoolTestBase.java


注:本文中的io.vertx.core.Vertx.vertx方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。