private void delegateWithCircuitBreaker(RoutingContext rc) { HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("currency-3rdparty-service")) .flatMap(client -> { // TODO // Use the circuit breaker (circuit) to call the service. Use the rxExecuteCommandWithFallback` method. // This methods takes 2 parameters: the first one if a function taking a `Future` as parameter and // needs to report the success or failure on this future. The second method is a function providing // the fallback result. You must provide a JSON object as response. For the fallback use: // new JsonObject() // .put("amount", rc.getBodyAsJson().getDouble("amount")) // .put("currency", "USD")) // In the first function, use the given client, emit a POST request on / containing the incoming // payload (rc.getBodyAsJson()). Extract the response payload as JSON (bodyAsJsonObject). Don't // forget to subscribe (you can use subscribe(toObserver(fut)). You can have a look to the `delegate` // method as example. // ----- return Single.just(new JsonObject().put("amount", 0.0).put("currency", "N/A")); }) // ---- .map(JsonObject::toBuffer) .map(Buffer::new) .subscribe(toObserver(rc)); }
HttpEndpoint.getClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> { if (ar.failed()) { HttpEndpoint.getWebClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> { if (ar.failed()) {
Path path = klass.getAnnotation(Path.class); if(serviceName != null) { Record record = HttpEndpoint.createRecord(serviceName.value(), host, port, path.value()); records = records.andThen(discovery.rxPublish(record).ignoreElement()); methodPathString += methodPath.value(); Record record = HttpEndpoint.createRecord(methodServiceName.value(), host, port, methodPathString); records = records.andThen(discovery.rxPublish(record).ignoreElement());
/** * Example of method not using a circuit breaker. * * @param rc the routing context */ private void delegate(RoutingContext rc) { HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("currency-3rdparty-service")) .flatMap(client -> client.post("/").rxSendJsonObject(rc.getBodyAsJson())) .map(HttpResponse::bodyAsBuffer) .subscribe(toObserver(rc)); }