本文整理汇总了Java中io.vertx.servicediscovery.types.EventBusService类的典型用法代码示例。如果您正苦于以下问题:Java EventBusService类的具体用法?Java EventBusService怎么用?Java EventBusService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventBusService类属于io.vertx.servicediscovery.types包,在下文中一共展示了EventBusService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
示例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");
}
示例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;
}
示例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));
});
}
});
}
示例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);
});
}
});
}
示例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 -> {
// ...
});
}
示例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);
}
});
}
示例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 -> {
// ...
});
}
示例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);
}
});
}
示例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()));
}
}
示例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);
}
示例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;
}
示例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);
});
});
}
示例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;
});
}