io.vertx.rxjava.servicediscovery.ServiceDiscovery Java Examples

The following examples show how to use io.vertx.rxjava.servicediscovery.ServiceDiscovery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseMicroserviceRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws Exception {
  discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setBackendConfiguration(config()));
  JsonObject cbOptions = config().getJsonObject("circuit-breaker") != null ?
    config().getJsonObject("circuit-breaker") : new JsonObject();
  circuitBreaker = CircuitBreaker.create(cbOptions.getString("name", "circuit-breaker"), vertx,
    new CircuitBreakerOptions()
      .setMaxFailures(cbOptions.getInteger("maxFailures", 5))
      .setTimeout(cbOptions.getLong("timeout", 10000L))
      .setFallbackOnFailure(true)
      .setResetTimeout(cbOptions.getLong("resetTimeout", 30000L))
  );
}
 
Example #2
Source File: RXHelloServiceConsumer.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws Exception {
  ServiceDiscovery discovery = ServiceDiscovery.create(vertx, DISCOVERY_OPTIONS);

  io.vertx.rxjava.servicediscovery.types.EventBusService.getServiceProxyWithJsonFilter(
    discovery,
    new JsonObject().put("service.interface", io.vertx.it.service.HelloService.class.getName()),
    HelloService.class, // service interface
    ar -> {
      if (ar.failed()) {
        vertx.eventBus().send("result",
          new JsonObject().put("status", "ko").put("message", ar.cause().getMessage()));
      } else {
        HelloService hello = ar.result();
        hello.hello(new JsonObject().put("name", "vert.x"), result -> {
          if (result.failed()) {
            vertx.eventBus().send("result", new JsonObject()
              .put("status", "ko")
              .put("message", result.cause().getMessage()));
          } else {
            vertx.eventBus().send("result", new JsonObject()
              .put("status", "ok")
              .put("message", result.result()));

            ServiceDiscovery.releaseServiceObject(discovery, hello);
          }
        });
      }
    });
}
 
Example #3
Source File: MyRXVerticle.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
private synchronized JsonArray getBindings(ServiceDiscovery discovery) {
  JsonArray array = new JsonArray();
  for (ServiceReference ref : discovery.bindings()) {
    array.add(ref.toString());
  }
  return array;
}
 
Example #4
Source File: RxMicroServiceVerticle.java    From vertx-microservices-workshop with Apache License 2.0 4 votes vote down vote up
@Override
public void start() {
  super.start();
  vertx = Vertx.newInstance(super.vertx);
  discovery = ServiceDiscovery.newInstance(super.discovery);
}
 
Example #5
Source File: CheckoutService.java    From vertx-blueprint-microservice with Apache License 2.0 2 votes vote down vote up
/**
 * Create a shopping checkout service instance
 * @param vertx 
 * @param discovery 
 * @return 
 */
public static CheckoutService createService(Vertx vertx, ServiceDiscovery discovery) { 
  CheckoutService ret = CheckoutService.newInstance(io.vertx.blueprint.microservice.cart.CheckoutService.createService(vertx.getDelegate(), discovery.getDelegate()));
  return ret;
}