本文整理汇总了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();
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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();
}
});
}
示例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/");
}
示例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")
);
}
示例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);
});
}
});
}
示例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);
});
}
});
}
示例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);
}
});
// ---
}
示例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
);
}
示例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
);
}