Search in sources :

Example 21 with Synchronization

use of org.apache.camel.spi.Synchronization in project vertx-camel-bridge by vert-x3.

the class InboundEndpointTest method testNoReceiver.

@Test
public void testNoReceiver(TestContext tc) throws Exception {
    Async async = tc.async();
    Endpoint endpoint = camel.getEndpoint("direct:foo");
    bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel(endpoint).toVertx("test").setTimeout(5000)));
    camel.start();
    BridgeHelper.startBlocking(bridge);
    // Unlike the previous test, we don't register a consumer.
    ProducerTemplate producer = camel.createProducerTemplate();
    producer.asyncCallbackRequestBody(endpoint, "ping", new Synchronization() {

        @Override
        public void onComplete(Exchange exchange) {
            tc.fail("The interaction should fail");
        }

        @Override
        public void onFailure(Exchange exchange) {
            tc.assertTrue(exchange.getException().getMessage().contains("No handlers for address test"));
            async.complete();
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Endpoint(org.apache.camel.Endpoint) Async(io.vertx.ext.unit.Async) Synchronization(org.apache.camel.spi.Synchronization) Test(org.junit.Test)

Example 22 with Synchronization

use of org.apache.camel.spi.Synchronization in project webofneeds by researchstudio-sat.

the class MessagingServiceImpl method sendInOutMessageGeneric.

/**
 * This method shall be used for Request-Reply messaging.
 *
 * @param properties
 * @param headers
 * @param body
 * @param endpoint
 * @return
 */
public ListenableFuture<String> sendInOutMessageGeneric(Map properties, Map headers, Object body, String endpoint) {
    Exchange exchange = new DefaultExchange(getCamelContext());
    // TODO: the method name shall be set in the header of the message.
    Endpoint ep = getCamelContext().getEndpoint(endpoint);
    if (properties != null) {
        if (properties.containsKey("methodName")) {
            exchange.setProperty("methodName", properties.get("methodName"));
        }
    }
    if (headers != null) {
        exchange.getIn().setHeaders(headers);
    }
    // exchange.getIn().getHeaders().put("CamelJmsRequestTimeout",DEFAULT_JMS_EXPIRATION_TIME);
    // exchange.setProperty("JMSExpiration",DEFAULT_JMS_EXPIRATION_TIME);
    exchange.getIn().setBody(body);
    // exchange.getOut().setBody(body);
    exchange.setPattern(ExchangePattern.InOut);
    final SettableFuture<String> result = SettableFuture.create();
    logger.debug("sending inout message");
    producerTemplate.asyncCallback(ep, exchange, new Synchronization() {

        @Override
        public void onComplete(Exchange exchange) {
            String resultObject = (String) exchange.getOut().getBody();
            result.set(resultObject);
        }

        @Override
        public void onFailure(Exchange exchange) {
            if (exchange.getException() != null) {
                logger.warn("caught exception while sending jms message", exchange.getException());
            }
            result.cancel(true);
        }
    });
    return result;
}
Also used : DefaultExchange(org.apache.camel.support.DefaultExchange) DefaultExchange(org.apache.camel.support.DefaultExchange) Synchronization(org.apache.camel.spi.Synchronization)

Aggregations

Synchronization (org.apache.camel.spi.Synchronization)22 Exchange (org.apache.camel.Exchange)12 AsyncCallback (org.apache.camel.AsyncCallback)4 Endpoint (org.apache.camel.Endpoint)4 ArrayList (java.util.ArrayList)3 Async (io.vertx.ext.unit.Async)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 SynchronizationRouteAware (org.apache.camel.spi.SynchronizationRouteAware)2 Test (org.junit.Test)2 File (java.io.File)1 URL (java.net.URL)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 DirectConsumerNotAvailableException (org.apache.camel.component.direct.DirectConsumerNotAvailableException)1 ReactiveStreamsConsumer (org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer)1 AbstractMessageHandler (org.apache.camel.component.sjms.consumer.AbstractMessageHandler)1 InOnlyMessageHandler (org.apache.camel.component.sjms.consumer.InOnlyMessageHandler)1 InOutMessageHandler (org.apache.camel.component.sjms.consumer.InOutMessageHandler)1