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


Java HttpEndpoint类代码示例

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


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

示例1: addWeightService

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
private void addWeightService(AtomicInteger seq) {
  discovery.publish(HttpEndpoint.createRecord(service, "localhost", 8081, "/"),
                    ar -> {
                      LoadBalanceStats.instance().get(ar.result().getRegistration()).setWeight(5);
                      seq.incrementAndGet();
                    });
  discovery.publish(HttpEndpoint.createRecord(service, "localhost", 8082, "/"),
                    ar -> {
                      LoadBalanceStats.instance().get(ar.result().getRegistration()).setWeight(1);
                      seq.incrementAndGet();
                    });
  discovery.publish(HttpEndpoint.createRecord(service, "localhost", 8083, "/"),
                    ar -> {
                      LoadBalanceStats.instance().get(ar.result().getRegistration()).setWeight(1);
                      seq.incrementAndGet();
                    });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:18,代码来源:ServiceProviderTest.java

示例2: undefinedMethodShouldThrowInvalidArg

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void undefinedMethodShouldThrowInvalidArg(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices")
          .setHttpMethod(HttpMethod.OPTIONS);

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      context.fail();
    } else {
      Throwable t = ar.cause();
      context.assertTrue(t instanceof SystemException);
      SystemException ex = (SystemException) t;
      context.assertEquals(DefaultErrorCode.INVALID_ARGS, ex.getErrorCode());
      async.complete();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:23,代码来源:HttpRpcHandlerTest.java

示例3: postMissBodyShouldThrowMissArg

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void postMissBodyShouldThrowMissArg(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices")
          .setHttpMethod(HttpMethod.POST);

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      context.fail();
    } else {
      Throwable t = ar.cause();
      context.assertTrue(t instanceof SystemException);
      SystemException ex = (SystemException) t;
      context.assertEquals(DefaultErrorCode.MISSING_ARGS, ex.getErrorCode());
      async.complete();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:23,代码来源:HttpRpcHandlerTest.java

示例4: putMissBodyShouldThrowMissArg

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void putMissBodyShouldThrowMissArg(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices")
          .setHttpMethod(HttpMethod.PUT);

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      context.fail();
    } else {
      Throwable t = ar.cause();
      context.assertTrue(t instanceof SystemException);
      SystemException ex = (SystemException) t;
      context.assertEquals(DefaultErrorCode.MISSING_ARGS, ex.getErrorCode());
      async.complete();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:23,代码来源:HttpRpcHandlerTest.java

示例5: testGetArray

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void testGetArray(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("/devices")
          .setHttpMethod(HttpMethod.GET);

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      RpcResponse rpcResponse = ar.result();
      context.assertTrue(rpcResponse.isArray());
      context.assertEquals(2, rpcResponse.responseArray().size());
      async.complete();
    } else {
      ar.cause().printStackTrace();
      context.fail();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:23,代码来源:HttpRpcHandlerTest.java

示例6: testDelete

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void testDelete(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices")
          .setHttpMethod(HttpMethod.DELETE)
          .addParam("userId", "2");

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      RpcResponse rpcResponse = ar.result();
      context.assertFalse(rpcResponse.isArray());
      context.assertEquals("1", rpcResponse.responseObject().getString("result"));
      async.complete();
    } else {
      ar.cause().printStackTrace();
      context.fail();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:24,代码来源:HttpRpcHandlerTest.java

示例7: testPost

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void testPost(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices?type=2")
          .setHttpMethod(HttpMethod.POST)
          .setBody(new JsonObject().put("foo", "bar"))
          .addParam("userId", "2");

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);

  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      RpcResponse rpcResponse = ar.result();
      context.assertFalse(rpcResponse.isArray());
      context.assertEquals("bar", rpcResponse.responseObject().getString("foo"));
      context.assertEquals("abc", rpcResponse.id());
      async.complete();
    } else {
      context.fail();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:26,代码来源:HttpRpcHandlerTest.java

示例8: testPut

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void testPut(TestContext context) {
  HttpRpcRequest rpcRequest = SdHttpRequest.create("abc", "device")
          .setRecord(HttpEndpoint.createRecord("device", "localhost", port, "/")
                             .setRegistration(serviceId))
          .setPath("devices?type=2")
          .setHttpMethod(HttpMethod.PUT)
          .setBody(new JsonObject().put("foo", "bar"))
          .addParam("userId", "2");

  Future<RpcResponse> future = rpcHandler.handle(rpcRequest);
  Async async = context.async();
  future.setHandler(ar -> {
    if (ar.succeeded()) {
      RpcResponse rpcResponse = ar.result();
      context.assertFalse(rpcResponse.isArray());
      context.assertEquals("bar", rpcResponse.responseObject().getString("foo"));
      context.assertEquals("abc", rpcResponse.id());
      async.complete();
    } else {
      context.fail();
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:25,代码来源:HttpRpcHandlerTest.java

示例9: testHttpImport

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Test
public void testHttpImport() throws InterruptedException {
  services.add(new JsonObject("{\n" +
      "  \"Node\" : \"node1\",\n" +
      "  \"Address\" : \"172.17.0.2\",\n" +
      "  \"ServiceID\" : \"web\",\n" +
      "  \"ServiceName\" : \"web\",\n" +
      "  \"ServiceTags\" : [ \"rails\", \"http-endpoint\" ],\n" +
      "  \"ServiceAddress\" : \"\",\n" +
      "  \"ServicePort\" : 80\n" +
      "}"));

  discovery = ServiceDiscovery.create(vertx)
      .registerServiceImporter(new ConsulServiceImporter(),
          new JsonObject().put("host", "localhost").put("port", 5601));

  await().until(() -> getAllRecordsBlocking().size() > 0);
  List<Record> list = getAllRecordsBlocking();

  assertThat(list).hasSize(1);

  assertThat(list.get(0).getType()).isEqualTo(HttpEndpoint.TYPE);
  assertThat(list.get(0).getLocation().getString("endpoint")).isEqualTo("http://172.17.0.2:80/");
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:25,代码来源:ConsulServiceImporterTest.java

示例10: example1

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
public void example1(ServiceDiscovery discovery) {
  Record record1 = HttpEndpoint.createRecord(
    "some-http-service", // The service name
    "localhost", // The host
    8433, // the port
    "/api" // the root of the service
  );

  discovery.publish(record1, ar -> {
    // ...
  });

  Record record2 = HttpEndpoint.createRecord(
    "some-other-name", // the service name
    true, // whether or not the service requires HTTPs
    "localhost", // The host
    8433, // the port
    "/api", // the root of the service
    new JsonObject().put("some-metadata", "some value")
  );

}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:23,代码来源:HTTPEndpointExamples.java

示例11: example3

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
public void example3(ServiceDiscovery discovery) {
  HttpEndpoint.getClient(discovery, new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded()) {
      HttpClient client = ar.result();

      // You need to path the complete path
      client.getNow("/api/persons", response -> {

        // ...

        // Dont' forget to release the service
        ServiceDiscovery.releaseServiceObject(discovery, client);

      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:18,代码来源:HTTPEndpointExamples.java

示例12: example3_webclient

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
public void example3_webclient(ServiceDiscovery discovery) {
  HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded()) {
      WebClient client = ar.result();

      // You need to path the complete path
      client.get("/api/persons")
        .send(response -> {

          // ...

          // Dont' forget to release the service
          ServiceDiscovery.releaseServiceObject(discovery, client);

        });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:HTTPEndpointExamples.java

示例13: evaluate

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
@Override
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
  // ----
  // First we need to discover and get a HTTP client for the `quotes` service:
  HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "quotes"),
      client -> {
        if (client.failed()) {
          // It failed...
          resultHandler.handle(Future.failedFuture(client.cause()));
        } else {
          // We have the client
          WebClient webClient = client.result();
          computeEvaluation(webClient, resultHandler);
        }
      });

  // ---
}
 
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:19,代码来源:PortfolioServiceImpl.java

示例14: getMicroServiceRecord

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
/**
 * Define microservice options
 * servicePort: this is the visible port from outside
 * for example you run your service with 8080 on a platform (Clever Cloud, Docker, ...)
 * and the visible port is 80
 */
static Record getMicroServiceRecord() {
  
  String serviceName = Optional.ofNullable(System.getenv("SERVICE_NAME")).orElse("John Doe");
  String serviceHost = Optional.ofNullable(System.getenv("SERVICE_HOST")).orElse("localhost"); // domain name
  Integer servicePort = Integer.parseInt(Optional.ofNullable(System.getenv("SERVICE_PORT")).orElse("80")); // set to 80 on Clever Cloud
  String serviceRoot = Optional.ofNullable(System.getenv("SERVICE_ROOT")).orElse("/api");
  
  return HttpEndpoint.createRecord(
    serviceName,
    serviceHost,
    servicePort,
    serviceRoot
  );
}
 
开发者ID:the-big-bang-theory,项目名称:penny,代码行数:21,代码来源:Parameters.java

示例15: createRecord

import io.vertx.servicediscovery.types.HttpEndpoint; //导入依赖的package包/类
private Record createRecord(final JsonObject item) {
    final String name = item.getString(NAME);
    final String host = item.getString(HOST);
    final Integer port = item.getInteger(PORT);
    final JsonObject meta = item.getJsonObject(META);
    return HttpEndpoint.createRecord(
            name, host, port, "/*", meta
    );
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:10,代码来源:EndPointOrigin.java


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