本文整理汇总了Java中io.vertx.servicediscovery.types.EventBusService类的典型用法代码示例。如果您正苦于以下问题:Java EventBusService类的具体用法?Java EventBusService怎么用?Java EventBusService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventBusService类属于io.vertx.servicediscovery.types包,在下文中一共展示了EventBusService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testLookupWithNonMatchingQuery
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Test
public void testLookupWithNonMatchingQuery() throws UnsupportedEncodingException {
HelloService svc = new HelloServiceImpl("stuff");
ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
Record record1 = EventBusService.createRecord("Hello", "address", HelloService.class,
new JsonObject().put("key", "foo"));
Record record2 = EventBusService.createRecord("Hello-2", "address", HelloService.class,
new JsonObject().put("key", "bar"));
discovery.publish(record1, (r) -> {
});
discovery.publish(record2, (r) -> {
});
await().until(() -> record1.getRegistration() != null);
await().until(() -> record2.getRegistration() != null);
JsonArray services = given()
.param("query", "{\"stuff\":\"*\"}")
.get("/discovery")
.asJsonArray();
assertThat(services.size()).isEqualTo(0);
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:26,代码来源:ServiceDiscoveryRestEndpointTest.java
示例2: authUaaHandler
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
private void authUaaHandler(RoutingContext context) {
if (context.user() != null) {
JsonObject principal = context.user().principal();
String username = null; // TODO: Only for demo. Complete this in next version.
// String username = KeycloakHelper.preferredUsername(principal);
if (username == null) {
context.response()
.putHeader("content-type", "application/json")
.end(new Account().setId("TEST666").setUsername("Eric").toString()); // TODO: no username should be an error
} else {
Future<AccountService> future = Future.future();
EventBusService.getProxy(discovery, AccountService.class, future.completer());
future.compose(accountService -> {
Future<Account> accountFuture = Future.future();
accountService.retrieveByUsername(username, accountFuture.completer());
return accountFuture.map(a -> {
ServiceDiscovery.releaseServiceObject(discovery, accountService);
return a;
});
})
.setHandler(resultHandlerNonEmpty(context)); // if user does not exist, should return 404
}
} else {
context.fail(401);
}
}
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:27,代码来源:APIGatewayVerticle.java
示例3: onSetup
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Override
protected void onSetup() {
metadata.put("service.interface", TestService.class.getName());
record = new Record().setName(SERVICE_NAME).setType(EventBusService.TYPE)
.setMetadata(metadata).setLocation(new JsonObject().put("endpoint", "endpoint"));
otherRecord = new Record().setName("other service name");
}
开发者ID:GwtDomino,项目名称:domino,代码行数:8,代码来源:VertxServiceDiscoveryTest.java
示例4: getPortfolioService
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
private Future<PortfolioService> getPortfolioService(ServiceDiscovery discovery) {
Future<PortfolioService> future = Future.future();
EventBusService.getServiceProxy(discovery,
rec -> rec.getName().equalsIgnoreCase("portfolio"),
PortfolioService.class,
future);
return future;
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:9,代码来源:CallbackTraderVerticle.java
示例5: getServiceProxy
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Override
public <T> void getServiceProxy(JsonObject filter, Class<T> clazz, Handler<AsyncResult<T>> handler) {
flow.getServiceRef(filter, filter.getString("name"), ar -> {
if (ar.succeeded()) {
EventBusService.getProxy(flow.discovery, clazz, ar2 -> {
T t = ar2.result();
handler.handle(Future.succeededFuture(t));
});
}
});
}
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:16,代码来源:ServiceFlowBase.java
示例6: start
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Override
public void start(Future<Void> future) {
super.start();
// Get configuration
config = ConfigFactory.load();
String company = TraderUtils.pickACompany();
int numberOfShares = TraderUtils.pickANumber();
EventBus eventBus = vertx.eventBus();
EventBusService.getProxy(discovery, PortfolioService.class, ar -> {
if (ar.failed()) {
System.out.println("Portfolio service could not be retrieved: " + ar.cause());
} else {
// Our services:
PortfolioService portfolio = ar.result();
MessageConsumer<JsonObject> marketConsumer = eventBus.consumer(config.getString("market.address"));
// Listen to the market...
marketConsumer.handler(message -> {
JsonObject quote = message.body();
TraderUtils.dumbTradingLogic(company, numberOfShares, portfolio, quote);
});
}
});
}
开发者ID:docker-production-aws,项目名称:microtrader,代码行数:28,代码来源:CompulsiveTraderVerticle.java
示例7: example1
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
public void example1(ServiceDiscovery discovery) {
Record record = EventBusService.createRecord(
"some-eventbus-service", // The service name
"address", // the service address,
MyService.class // the service interface
);
discovery.publish(record, ar -> {
// ...
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:13,代码来源:EventBusServiceJavaExamples.java
示例8: example3
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
public void example3(ServiceDiscovery discovery) {
EventBusService.getProxy(discovery, MyService.class, ar -> {
if (ar.succeeded()) {
MyService service = ar.result();
// Dont' forget to release the service
ServiceDiscovery.releaseServiceObject(discovery, service);
}
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:11,代码来源:EventBusServiceJavaExamples.java
示例9: example1
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
public void example1(ServiceDiscovery discovery) {
Record record = EventBusService.createRecord(
"some-eventbus-service", // The service name
"address", // the service address,
"examples.MyService", // the service interface as string
new JsonObject()
.put("some-metadata", "some value")
);
discovery.publish(record, ar -> {
// ...
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:14,代码来源:EventBusServiceExamples.java
示例10: example31
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
public void example31(ServiceDiscovery discovery) {
EventBusService.getServiceProxyWithJsonFilter(discovery,
new JsonObject().put("service.interface", "org.acme.MyService"), // The java interface
MyService.class, // The expect client
ar -> {
if (ar.succeeded()) {
MyService service = ar.result();
// Dont' forget to release the service
ServiceDiscovery.releaseServiceObject(discovery, service);
}
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:14,代码来源:EventBusServiceExamples.java
示例11: testThatWeGetTheTwoPublishedServicesWithMetadata
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Test
public void testThatWeGetTheTwoPublishedServicesWithMetadata() {
HelloService svc = new HelloServiceImpl("stuff");
ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
Record record1 = EventBusService.createRecord("Hello", "address", HelloService.class,
new JsonObject().put("key", "foo"));
Record record2 = EventBusService.createRecord("Hello-2", "address", HelloService.class,
new JsonObject().put("key", "bar"));
discovery.publish(record1, (r) -> {
});
discovery.publish(record2, (r) -> {
});
await().until(() -> record1.getRegistration() != null);
await().until(() -> record2.getRegistration() != null);
Restafari.Response response = get("/discovery");
JsonArray services = new JsonArray(response.asString());
assertThat(services.size()).isEqualTo(2);
for (Object json : services) {
Record rec = new Record((JsonObject) json);
assertThat(rec.getStatus()).isEqualTo(Status.UP);
assertThat(rec.getRegistration()).isNotNull();
assertThat(rec.getName()).startsWith("Hello");
assertThat(rec.getMetadata().getString("key")).isNotNull();
get("/discovery/" + rec.getRegistration()).then().body("name", not(nullValue()));
}
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:34,代码来源:ServiceDiscoveryRestEndpointTest.java
示例12: testLookupWithQuery
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Test
public void testLookupWithQuery() throws UnsupportedEncodingException {
HelloService svc = new HelloServiceImpl("stuff");
ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
Record record1 = EventBusService.createRecord("Hello", "address", HelloService.class,
new JsonObject().put("key", "foo"));
Record record2 = EventBusService.createRecord("Hello-2", "address", HelloService.class,
new JsonObject().put("key", "bar"));
discovery.publish(record1, (r) -> {
});
discovery.publish(record2, (r) -> {
});
await().until(() -> record1.getRegistration() != null);
await().until(() -> record2.getRegistration() != null);
JsonArray services =
given()
.param("query", "{\"name\":\"Hello\"}")
.get("/discovery")
.asJsonArray();
assertThat(services.size()).isEqualTo(1);
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:28,代码来源:ServiceDiscoveryRestEndpointTest.java
示例13: retrieveCounter
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
/**
* Fetch global counter of order from the cache infrastructure.
*
* @param key counter key (type)
* @return async result of the counter
*/
private Future<Long> retrieveCounter(String key) {
Future<Long> future = Future.future();
EventBusService.getProxy(discovery, CounterService.class,
ar -> {
if (ar.succeeded()) {
CounterService service = ar.result();
service.addThenRetrieve(key, future.completer());
} else {
future.fail(ar.cause());
}
});
return future;
}
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:20,代码来源:CheckoutServiceImpl.java
示例14: getCurrentCart
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
private Future<ShoppingCart> getCurrentCart(String userId) {
Future<ShoppingCartService> future = Future.future();
EventBusService.getProxy(discovery, ShoppingCartService.class, future.completer());
return future.compose(service -> {
Future<ShoppingCart> cartFuture = Future.future();
service.getShoppingCart(userId, cartFuture.completer());
return cartFuture.compose(c -> {
if (c == null || c.isEmpty())
return Future.failedFuture(new IllegalStateException("Invalid shopping cart"));
else
return Future.succeededFuture(c);
});
});
}
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:15,代码来源:CheckoutServiceImpl.java
示例15: saveCheckoutEvent
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
/**
* Save checkout cart event for current user.
*
* @param userId user id
* @return async result
*/
private Future<Void> saveCheckoutEvent(String userId) {
Future<ShoppingCartService> future = Future.future();
EventBusService.getProxy(discovery, ShoppingCartService.class, future.completer());
return future.compose(service -> {
Future<Void> resFuture = Future.future();
CartEvent event = CartEvent.createCheckoutEvent(userId);
service.addCartEvent(event, resFuture.completer());
return resFuture;
});
}
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:17,代码来源:CheckoutServiceImpl.java
示例16: start
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
@Override
public void start(Future<Void> future) {
super.start();
//----
// Initialize the trader
String company = TraderUtils.pickACompany();
int numberOfShares = TraderUtils.pickANumber();
System.out.println("Java compulsive trader configured for company " + company + " and shares: " + numberOfShares);
// We need to retrieve two services, create two futures object that will get the services
Future<MessageConsumer<JsonObject>> marketFuture = Future.future();
Future<PortfolioService> portfolioFuture = Future.future();
// Retrieve the services, use the "special" completed to assign the future
MessageSource.getConsumer(discovery, new JsonObject().put("name", "market-data"), marketFuture);
EventBusService.getProxy(discovery, PortfolioService.class, portfolioFuture);
// When done (both services retrieved), execute the handler
CompositeFuture.all(marketFuture, portfolioFuture).setHandler(ar -> {
if (ar.failed()) {
future.fail("One of the required service cannot " +
"be retrieved: " + ar.cause());
} else {
// Our services:
PortfolioService portfolio = portfolioFuture.result();
MessageConsumer<JsonObject> marketConsumer = marketFuture.result();
// Listen the market...
marketConsumer.handler(message -> {
JsonObject quote = message.body();
TraderUtils.dumbTradingLogic(company, numberOfShares, portfolio, quote);
});
future.complete();
}
});
// ----
}
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:39,代码来源:JavaCompulsiveTraderVerticle.java
示例17: publishEventBusService
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
protected Single<Void> publishEventBusService(String name, String address, Class serviceClass) {
return publish(EventBusService.createRecord(name, address, serviceClass));
}
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:4,代码来源:BaseRxVerticle.java
示例18: getAllEventbusServices
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
private Single<List<Record>> getAllEventbusServices() {
return discovery.rxGetRecords(record -> record.getType().equals(EventBusService.TYPE));
}
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:4,代码来源:GatewayVerticle.java
示例19: createEventBusRecord
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
private Record createEventBusRecord(EventBusServiceConfiguration configuration) {
return EventBusService.createRecord(configuration.getName(),
configuration.getAddress(),
configuration.getServiceClass(),
configuration.getMetadata());
}
开发者ID:GwtDomino,项目名称:domino,代码行数:7,代码来源:EventBusServiceDiscovery.java
示例20: getProxy
import io.vertx.servicediscovery.types.EventBusService; //导入依赖的package包/类
public <T> void getProxy(Class<T> serviceClass, Handler<AsyncResult<T>> handler) {
EventBusService.getProxy(serviceDiscovery, serviceClass, handler);
}
开发者ID:GwtDomino,项目名称:domino,代码行数:4,代码来源:EventBusServiceDiscovery.java
注:本文中的io.vertx.servicediscovery.types.EventBusService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论