use of io.vertx.core.eventbus.DeliveryOptions in project ethereum-ingest by codingchili.
the class BlockService method importTx.
private Future<Void> importTx(StorableBlock block, JsonObject transactions) {
Future<Void> future = Future.future();
DeliveryOptions delivery = new DeliveryOptions().setSendTimeout(ONE_MINUTE);
if (config.isTxImport()) {
context.bus().send(TX_ADDR, transactions, delivery, done -> {
listener.onImported(block.getHash(), block.getNumber());
if (done.succeeded()) {
Throwable result = (Throwable) done.result().body();
if (result == null) {
future.complete();
} else {
future.fail(result);
}
} else {
future.fail(done.cause());
}
});
} else {
future.complete();
}
return future;
}
use of io.vertx.core.eventbus.DeliveryOptions in project Eidolons by IDemiurge.
the class GuiEventManagerVertx method trigger_.
public static void trigger_(final GuiEventType type, Object obj) {
if (CoreEngine.isGraphicsOff())
return;
DeliveryOptions options = new DeliveryOptions();
options.setSendTimeout(50000);
options.setCodecName("default-codec");
EventCallbackParam callbackParam;
if (!(obj instanceof EventCallbackParam)) {
callbackParam = new EventCallbackParam(obj);
} else {
callbackParam = (EventCallbackParam) obj;
}
getInstance().publish(type.name(), callbackParam, options);
}
use of io.vertx.core.eventbus.DeliveryOptions in project transmittable-thread-local by alibaba.
the class VertxTransformletTest method testTransmitThreadLocal_InEventbus.
@Test
public void testTransmitThreadLocal_InEventbus() throws Exception {
final TransmittableThreadLocal<String> transmittableThreadLocal = new TransmittableThreadLocal<>();
final InheritableThreadLocal<String> inheritableThreadLocal = new InheritableThreadLocal<>();
final String transmittedData = "transmitted_data";
final String inheritedData = "inherited_data_ttl";
final String message = "message_42";
final Vertx vertx = Vertx.vertx();
final String address = "consumer";
vertx.eventBus().consumer(address, msg -> {
// be executed in netty event loop thread
System.out.println("========================================");
assertEquals(message, msg.body());
if (TtlAgent.isTtlAgentLoaded()) {
System.out.println("Test **WITH** TTL Agent");
assertEquals(transmittedData, transmittableThreadLocal.get());
} else {
System.out.println("Test WITHOUT TTL Agent");
assertNull(transmittableThreadLocal.get());
}
// InheritableThreadLocal is always null
assertNull(inheritableThreadLocal.get());
System.out.println("========================================");
// reply message can be get by {messageFuture.toCompletionStage().toCompletableFuture().get().body()} or {listener}
msg.reply(message);
});
transmittableThreadLocal.set(transmittedData);
inheritableThreadLocal.set(inheritedData);
// delivery message
final DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setSendTimeout(1000);
final Future<Message<Object>> messageFuture = vertx.eventBus().request(address, message, deliveryOptions);
messageFuture.toCompletionStage().toCompletableFuture().get();
assertEquals(message, messageFuture.toCompletionStage().toCompletableFuture().get().body());
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-web by vert-x3.
the class RouteToEBServiceHandler method handle.
@Override
public void handle(RoutingContext routingContext) {
eventBus.request(address, buildPayload(routingContext), deliveryOptions, (AsyncResult<Message<JsonObject>> res) -> {
if (res.succeeded()) {
OperationResponse op = new OperationResponse(res.result().body());
HttpServerResponse response = routingContext.response().setStatusCode(op.getStatusCode());
if (op.getStatusMessage() != null)
response.setStatusMessage(op.getStatusMessage());
if (op.getHeaders() != null)
op.getHeaders().forEach(h -> response.putHeader(h.getKey(), h.getValue()));
if (op.getPayload() != null)
response.end(op.getPayload());
else
response.end();
} else {
routingContext.fail(res.cause());
}
});
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-web by vert-x3.
the class OpenAPI3RouterBuilderImpl method mountServicesFromExtensions.
@Override
public RouterBuilder mountServicesFromExtensions() {
for (Map.Entry<String, OperationImpl> opEntry : operations.entrySet()) {
OperationImpl operation = opEntry.getValue();
Object extensionVal = OpenAPI3Utils.getAndMergeServiceExtension(OPENAPI_EXTENSION, OPENAPI_EXTENSION_ADDRESS, OPENAPI_EXTENSION_METHOD_NAME, operation.getPathModel(), operation.getOperationModel());
if (extensionVal != null) {
if (extensionVal instanceof String) {
operation.mountRouteToService((String) extensionVal, opEntry.getKey());
} else if (extensionVal instanceof JsonObject) {
JsonObject extensionMap = (JsonObject) extensionVal;
String address = extensionMap.getString(OPENAPI_EXTENSION_ADDRESS);
String methodName = extensionMap.getString(OPENAPI_EXTENSION_METHOD_NAME);
JsonObject sanitizedMap = OpenAPI3Utils.sanitizeDeliveryOptionsExtension(extensionMap);
if (address == null)
// TODO specify where
throw RouterBuilderException.createWrongExtension("Extension " + OPENAPI_EXTENSION + " must define " + OPENAPI_EXTENSION_ADDRESS);
if (methodName == null)
operation.mountRouteToService(address, opEntry.getKey(), new DeliveryOptions(sanitizedMap));
else
operation.mountRouteToService(address, methodName, new DeliveryOptions(sanitizedMap));
} else {
throw RouterBuilderException.createWrongExtension("Extension " + OPENAPI_EXTENSION + " must be or string or" + // TODO specify where
" a JsonObject");
}
}
}
return this;
}
Aggregations