Java源码示例:io.vertx.rxjava.servicediscovery.ServiceDiscovery
示例1
@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))
);
}
示例2
@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);
}
});
}
});
}
示例3
private synchronized JsonArray getBindings(ServiceDiscovery discovery) {
JsonArray array = new JsonArray();
for (ServiceReference ref : discovery.bindings()) {
array.add(ref.toString());
}
return array;
}
示例4
@Override
public void start() {
super.start();
vertx = Vertx.newInstance(super.vertx);
discovery = ServiceDiscovery.newInstance(super.discovery);
}
示例5
/**
* 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;
}