use of io.vertx.core.eventbus.DeliveryOptions in project gateleen by swisspush.
the class EventBusWriter method flush.
@Override
public void flush() throws IOException {
if (buffer != null) {
DeliveryOptions options = new DeliveryOptions();
if (deliveryOptionsHeaders != null) {
options.setHeaders(deliveryOptionsHeaders);
}
if (TransmissionMode.send == transmissionMode) {
eventBus.request(address, buffer.toString(), options, (Handler<AsyncResult<Message<JsonObject>>>) reply -> {
if (reply.succeeded() && "ok".equals(reply.result().body().getString("status"))) {
log.debug("Successfully sent to (and got reply from) eventBus address {}", address);
} else {
log.error("Failed to send (not publish) to the eventBus: {}", reply.cause());
}
});
} else {
eventBus.publish(address, buffer.toString(), options);
}
buffer = null;
}
}
use of io.vertx.core.eventbus.DeliveryOptions in project gateleen by swisspush.
the class QueueProcessorTest method testInactiveQueueCircuitBreaker.
/**
* Not active QueueCircuitBreakers should not execute any tasks. Therefore, the actual queue requests must always be made.
* <p>This tests verifies the following conditions:</p>
*
* <ul>
* <li>{@link QueueCircuitBreaker#isCircuitCheckEnabled()} is called exactly once to check whether QueueCircuitBreaker is active</li>
* <li>{@link QueueCircuitBreaker#handleQueuedRequest(String, HttpRequest)} is never called</li>
* <li>{@link HttpClient#request(HttpMethod, String, Handler)} is called exactly once</li>
* </ul>
*
* @param context the test context
*/
@Test
public void testInactiveQueueCircuitBreaker(TestContext context) {
Async async = context.async();
QueueCircuitBreaker circuitBreaker = Mockito.spy(new ConfigurableQueueCircuitBreaker(QueueCircuitState.OPEN, false, true));
new QueueProcessor(vertx, httpClient, monitoringHandler, circuitBreaker);
vertx.eventBus().request(Address.queueProcessorAddress(), buildQueueEventBusMessage("my_queue"), new DeliveryOptions().setSendTimeout(1000), event -> {
verify(circuitBreaker, times(1)).isCircuitCheckEnabled();
verify(circuitBreaker, never()).handleQueuedRequest(anyString(), any(HttpRequest.class));
verify(httpClient, times(1)).request(any(HttpMethod.class), anyString());
async.complete();
});
}
use of io.vertx.core.eventbus.DeliveryOptions in project commons by mosip.
the class VidPoolCheckerVerticle method start.
@Override
public void start(Future<Void> startFuture) {
EventBus eventBus = vertx.eventBus();
MessageConsumer<String> checkPoolConsumer = eventBus.consumer(EventType.CHECKPOOL);
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setSendTimeout(environment.getProperty("mosip.kernel.vid.pool-population-timeout", Long.class));
checkPoolConsumer.handler(handler -> {
long noOfFreeVids = vidService.fetchVidCount(VidLifecycleStatus.AVAILABLE);
LOGGER.info("no of vid free present are {}", noOfFreeVids);
if (noOfFreeVids < threshold && !locked.get()) {
locked.set(true);
eventBus.send(EventType.GENERATEPOOL, noOfFreeVids, deliveryOptions, replyHandler -> {
if (replyHandler.succeeded()) {
locked.set(false);
LOGGER.info("population of pool done");
} else if (replyHandler.failed()) {
locked.set(false);
LOGGER.error("population failed with cause ", replyHandler.cause());
}
});
} else {
LOGGER.info("event type is send {} eventBus{}", handler.isSend(), eventBus);
LOGGER.info("locked generation");
}
});
MessageConsumer<String> initPoolConsumer = eventBus.consumer(EventType.INITPOOL);
initPoolConsumer.handler(initPoolHandler -> {
long start = System.currentTimeMillis();
long noOfFreeVids = vidService.fetchVidCount(VidLifecycleStatus.AVAILABLE);
LOGGER.info("no of vid free present are {}", noOfFreeVids);
LOGGER.info("value of threshold is {} and lock is {}", threshold, locked.get());
boolean isEligibleForPool = noOfFreeVids < threshold && !locked.get();
LOGGER.info("is eligible for pool {}", isEligibleForPool);
if (isEligibleForPool) {
locked.set(true);
eventBus.send(EventType.GENERATEPOOL, noOfFreeVids, deliveryOptions, replyHandler -> {
if (replyHandler.succeeded()) {
locked.set(false);
deployHttpVerticle(start);
LOGGER.info("population of init pool done");
} else if (replyHandler.failed()) {
locked.set(false);
LOGGER.error("population failed with cause ", replyHandler.cause());
initPoolHandler.fail(100, replyHandler.cause().getMessage());
}
});
} else {
deployHttpVerticle(start);
}
});
}
use of io.vertx.core.eventbus.DeliveryOptions in project entcore by opendigitaleducation.
the class DefaultImportService method validate.
@Override
public void validate(ImportInfos importInfos, UserInfos user, final Handler<Either<JsonObject, JsonObject>> handler) {
try {
final AdmlValidate admlValidate = new AdmlValidate(user, handler).invoke();
if (admlValidate.is())
return;
final JsonObject action = new JsonObject(mapper.writeValueAsString(importInfos)).put("action", "validate").put("adml-structures", admlValidate.getAdmlStructures());
eb.send(Directory.FEEDER, action, new DeliveryOptions().setSendTimeout(TIMEOUT), handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> res) {
if ("ok".equals(res.body().getString("status"))) {
JsonObject r = res.body().getJsonObject("result", new JsonObject());
if (r.getJsonObject("errors", new JsonObject()).size() > 0) {
handler.handle(new Either.Left<JsonObject, JsonObject>(r.getJsonObject("errors")));
} else {
JsonObject f = r.getJsonObject("files");
if (r.getJsonObject("softErrors") != null) {
f.put("softErrors", r.getJsonObject("softErrors"));
}
if (isNotEmpty(r.getString("_id"))) {
f.put("importId", r.getString("_id"));
}
handler.handle(new Either.Right<JsonObject, JsonObject>(f));
}
} else {
handler.handle(new Either.Left<JsonObject, JsonObject>(new JsonObject().put("global", new fr.wseduc.webutils.collections.JsonArray().add(res.body().getString("message", "")))));
}
}
}));
} catch (JsonProcessingException e) {
handler.handle(new Either.Left<JsonObject, JsonObject>(new JsonObject().put("global", new fr.wseduc.webutils.collections.JsonArray().add("unexpected.error"))));
log.error(e.getMessage(), e);
}
}
use of io.vertx.core.eventbus.DeliveryOptions in project entcore by opendigitaleducation.
the class DefaultImportService method sendCommand.
protected void sendCommand(final Handler<Either<JsonObject, JsonObject>> handler, JsonObject action) {
eb.send("entcore.feeder", action, new DeliveryOptions().setSendTimeout(600000L), handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> event) {
if ("ok".equals(event.body().getString("status"))) {
JsonObject r = event.body().getJsonObject("result", new JsonObject());
r.remove("status");
if (r.getJsonObject("errors", new JsonObject()).size() > 0) {
handler.handle(new Either.Left<JsonObject, JsonObject>(r));
} else {
handler.handle(new Either.Right<JsonObject, JsonObject>(r));
}
} else {
handler.handle(new Either.Left<JsonObject, JsonObject>(new JsonObject().put("global", new JsonArray().add(event.body().getString("message", "")))));
}
}
}));
}
Aggregations