Search in sources :

Example 11 with DeliveryOptions

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;
}
Also used : Message(org.apache.camel.Message) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 12 with DeliveryOptions

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();
}
Also used : DefaultMessage(org.apache.camel.support.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.support.DefaultMessage) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 13 with DeliveryOptions

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;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 14 with DeliveryOptions

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()));
        }
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 15 with DeliveryOptions

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);
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Aggregations

DeliveryOptions (io.vertx.core.eventbus.DeliveryOptions)96 JsonObject (io.vertx.core.json.JsonObject)39 Message (io.vertx.core.eventbus.Message)23 EventBus (io.vertx.core.eventbus.EventBus)21 Test (org.junit.Test)20 JsonArray (io.vertx.core.json.JsonArray)17 CountDownLatch (java.util.concurrent.CountDownLatch)16 Handler (io.vertx.core.Handler)15 AsyncResult (io.vertx.core.AsyncResult)14 Utils.handlerToAsyncHandler (fr.wseduc.webutils.Utils.handlerToAsyncHandler)10 Vertx (io.vertx.core.Vertx)10 Either (fr.wseduc.webutils.Either)9 Context (io.vertx.core.Context)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Buffer (io.vertx.core.buffer.Buffer)8 MultiMap (io.vertx.core.MultiMap)7 Span (io.vertx.test.faketracer.Span)6 java.util (java.util)6 io.vertx.core (io.vertx.core)5 Future (io.vertx.core.Future)5