--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/85831de8-34eb-4f78-88da-3a7c748993ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
/**
* Sends out a 'Bucket-call' for every bucket in the given list.
* Calls the handler if all calls are completed.
* The handler will fail if one of the bucket calls fails.
* If all bucket calls have succeeded, calls the handler with the merged result
*
* @param buckets
* @param handler
*/
private void handleBuckets(List<JsonObject> buckets, Handler<AsyncResult<JsonObject>> handler) {
ArrayList futureList = new ArrayList();
JsonObject result = new JsonObject();
for (JsonObject bucket : buckets) {
Future<JsonObject> future = Future.future();
futureList.add(future);
vertx.eventBus().send("Bucket-call", bucket, h -> {
if(h.failed()) {
future.fail(h.cause());
} else {
JsonObject bucketResult = (JsonObject)h.result().body();
result.mergeIn(bucketResult)
future.complete(bucketResult);
}
});
}
CompositeFuture.all(futureList).setHandler(h -> {
if(h.failed()) {
handler.handle(Future.failedFuture(h.cause()));
} else {
handler.handle(Future.succeededFuture(result));
}
});
}
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/fb90c46d-edc8-4756-9ecb-f7cce425820a%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/DEKJuViujcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/19618BF2-4FA1-4F07-BBC2-062761AE67DF%40julienviet.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/9A1892C2-FE01-40A9-B467-EC9A48B0ED8D%40gmail.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVyt7iZU4Ckd2YYzwryHjQ5hjEHu3erL_ym7gzSEX_WDAA%40mail.gmail.com.
3.5.0
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVyt7iZU4Ckd2YYzwryHjQ5hjEHu3erL_ym7gzSEX_WDAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/A8515D79-9324-4E15-8845-6A810D90636B%40julienviet.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVxoTq%2BAc6c9JvcyyqCNdE%2B8bLJSK%2Be2aweH-PYFA-oGJA%40mail.gmail.com.
Julien
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVxoTq%2BAc6c9JvcyyqCNdE%2B8bLJSK%2Be2aweH-PYFA-oGJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/B20752B9-A6A3-4C53-BA07-0E550A49711F%40julienviet.com.
public void execute(RoutingContext event) {
List<Future> futures = new ArrayList<Future>();
trigger(HttpMethod.GET, "https://reqres.in/api/users?page=2", null, null).setHandler(handler -> {
if (!handler.succeeded()) {
handler.cause().printStackTrace();
event.response().putHeader("content-type", "application/json").end(new JsonObject().put("Execute failed: ", handler.cause().getMessage()).toString());
} else {
final JsonObject response = handler.result();
final JsonArray users = response.getJsonArray("data");
users.forEach(r -> {
final JsonObject user = ((JsonObject) r);
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.add("Content-Type", "application/json");
futures.add(trigger(HttpMethod.GET, "https://reqres.in/api/unknown/" + user.getLong("id"), null, headers));
});
CompositeFuture.all(futures).setHandler(ar -> {
if (ar.succeeded()) {
System.out.println("Success");
event.response().putHeader("content-type", "application/json").end(new JsonObject().put("Execute complete success", "Ok").toString());
} else {
ar.cause().printStackTrace();
event.response().putHeader("content-type", "application/json").end(new JsonObject().put("Execute complete failed: ", ar.cause().getMessage()).toString());
}
});
}
});
}
public Future<JsonObject> trigger(final HttpMethod method, final String url, final JsonObject payload, final MultiMap headers) {
Future<JsonObject> future = Future.future();
HttpRequest<Buffer> request = webClient.requestAbs(method, url);
Buffer buffer = Buffer.buffer();
if (null != payload) {
buffer = Buffer.buffer(payload.toString());
request.headers().add(HttpHeaders.CONTENT_LENGTH.toString(), buffer.length() + "");
}
if (null != headers)
request.headers().addAll(headers);
request.send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Received response with status code: " + response.statusCode());
future.complete(response.bodyAsJsonObject());
} else {
ar.cause().printStackTrace();
future.fail(ar.cause());
}
});
return future;
}
Julien
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/fb90c46d-edc8-4756-9ecb-f7cce425820a%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVyt7iZU4Ckd2YYzwryHjQ5hjEHu3erL_ym7gzSEX_WDAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/A8515D79-9324-4E15-8845-6A810D90636B%40julienviet.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVxoTq%2BAc6c9JvcyyqCNdE%2B8bLJSK%2Be2aweH-PYFA-oGJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
// Step 1
// Step 2
// Step 3
WebClientOptions options = new WebClientOptions()
.setDefaultHost("http://myhost.com")
.setDefaultPort(8080);
WebClient webClient = WebClient.create(vertx, options);
return Single.create(caller -> {
List<Observable<Object>> remoteCalls = new ArrayList<>();
for (Json json : ...) {
Observable remoteCall = webClient.request(HttpMethod.POST, "/my/api/path/to/process/json")
.timeout(5000)
.rxSendBuffer(Buffer.buffer(json.string()))
.toObservable();
remoteCalls.add(remoteCall);
}
List<Object> remoteResponse = new ArrayList<>();
Observable.concat(remoteCalls)
.subscribe(jsonResponse -> {
// Step 4
remoteResponse.add(jsonResponse);
}, ex -> {
caller.onError(ex);
}, () -> {
// Step 5
caller.onSuccess(remoteResponse);
});
});
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CANz9GVz9MXWm9jwcVsDuL2Q_m5gkjV8pn4QRV_VAEA1Kx7hx3w%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/cb179b93-fec7-49e1-b535-f3ee8561b002%40googlegroups.com.