use of io.vertx.core.eventbus.DeliveryOptions in project vertx-camel-bridge by vert-x3.
the class CamelToVertxProcessor method process.
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
Message in = exchange.getIn();
Object body = CamelHelper.convert(inbound, in);
DeliveryOptions delivery = CamelHelper.getDeliveryOptions(in, inbound.isHeadersCopy());
if (inbound.getTimeout() > 0) {
delivery.setSendTimeout(inbound.getTimeout());
}
try {
if (inbound.isPublish()) {
vertx.eventBus().publish(inbound.getAddress(), body, delivery);
} else {
if (ExchangeHelper.isOutCapable(exchange)) {
vertx.eventBus().request(inbound.getAddress(), body, delivery, reply -> {
Message out = exchange.getOut();
if (reply.succeeded()) {
out.setBody(reply.result().body());
MultiMapHelper.toMap(reply.result().headers(), out.getHeaders());
} else {
exchange.setException(reply.cause());
}
// continue callback
callback.done(false);
});
// being routed async so return false
return false;
} else {
// No reply expected.
vertx.eventBus().send(inbound.getAddress(), body, delivery);
}
}
} catch (Throwable e) {
// Mark the exchange as "failed".
exchange.setException(e);
}
callback.done(true);
return true;
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-camel-bridge by vert-x3.
the class CamelHelperTest method testTheCopyOfHeaders.
@Test
public void testTheCopyOfHeaders() {
Message msg = new DefaultMessage(new DefaultCamelContext());
msg.setHeader("CamelRedelivered", false);
msg.setHeader("CamelRedeliveryCounter", 0);
msg.setHeader("JMSCorrelationID", "");
msg.setHeader("JMSDestination", "queue://dev.msy.queue.log.fwd");
msg.setHeader("JMSReplyTo", null);
DeliveryOptions options = CamelHelper.getDeliveryOptions(msg, true);
assertThat(options.getHeaders().get("CamelRedelivered")).isEqualToIgnoringCase("false");
assertThat(options.getHeaders().get("CamelRedeliveryCounter")).isEqualToIgnoringCase("0");
assertThat(options.getHeaders().get("JMSCorrelationID")).isEqualToIgnoringCase("");
assertThat(options.getHeaders().get("JMSDestination")).isEqualToIgnoringCase("queue://dev.msy.queue.log.fwd");
assertThat(options.getHeaders().get("JMSReplyTo")).isNull();
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-examples by vert-x3.
the class SomeDatabaseServiceVertxEBProxy method getDataById.
@Override
public SomeDatabaseService getDataById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return this;
}
JsonObject _json = new JsonObject();
_json.put("id", id);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "getDataById");
_vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body()));
}
});
return this;
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-examples by vert-x3.
the class ProcessorServiceVertxEBProxy method process.
@Override
public void process(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return;
}
JsonObject _json = new JsonObject();
_json.put("document", document);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "process");
_vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body()));
}
});
}
use of io.vertx.core.eventbus.DeliveryOptions in project chili-core by codingchili.
the class ClusteredSession method write.
@Override
public void write(Object object) {
DeliveryOptions delivery = new DeliveryOptions().addHeader(Session.ID, id).addHeader(Session.HOME, home);
sessionFactory.context().bus().send(home, Serializer.json(object), delivery);
}
Aggregations