Search in sources :

Example 11 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class AbstractCamelProducerTemplateFactoryBean method getObject.

public ProducerTemplate getObject() throws Exception {
    CamelContext context = getCamelContext();
    if (defaultEndpoint != null) {
        Endpoint endpoint = context.getEndpoint(defaultEndpoint);
        if (endpoint == null) {
            throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint);
        } else {
            template = new DefaultProducerTemplate(context, endpoint);
        }
    } else {
        template = new DefaultProducerTemplate(context);
    }
    // set custom cache size if provided
    if (maximumCacheSize != null) {
        template.setMaximumCacheSize(maximumCacheSize);
    }
    // must start it so its ready to use
    ServiceHelper.startService(template);
    return template;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate)

Example 12 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class CouchDbComponentTest method testEndpointCreated.

@Test
public void testEndpointCreated() throws Exception {
    Map<String, Object> params = new HashMap<String, Object>();
    String uri = "couchdb:http://localhost:5984/db";
    String remaining = "http://localhost:5984/db";
    Endpoint endpoint = new CouchDbComponent(context).createEndpoint(uri, remaining, params);
    assertNotNull(endpoint);
}
Also used : Endpoint(org.apache.camel.Endpoint) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 13 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class CouchDbConsumerIntegrationTest method testMessages.

@Test
public void testMessages() throws InterruptedException {
    final int messageCount = 100;
    to.expectedMessageCount(messageCount);
    // insert json manually into couch, camel will
    // then pick that up and send to mock endpoint
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            for (int k = 0; k < messageCount; k++) {
                JsonElement obj = new Gson().toJsonTree("{ \"randomString\" : \"" + UUID.randomUUID() + "\" }");
                client.save(obj);
            }
        }
    });
    t.start();
    t.join();
    to.assertIsSatisfied();
}
Also used : JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 14 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class CxfBeanTest method testConsumerWithProviders.

/**
     * Test that we have an endpoint with 2 providers.
     */
@Test
public void testConsumerWithProviders() throws Exception {
    boolean testedEndpointWithProviders = false;
    for (Endpoint endpoint : camelContext.getEndpoints()) {
        if (endpoint instanceof CxfBeanEndpoint) {
            CxfBeanEndpoint beanEndpoint = (CxfBeanEndpoint) endpoint;
            if (beanEndpoint.getEndpointUri().equals("customerServiceBean")) {
                assertNotNull("The bean endpoint should have provider", beanEndpoint.getProviders());
                if (beanEndpoint.getProviders().size() == 2) {
                    testedEndpointWithProviders = true;
                    break;
                } else if (beanEndpoint.getProviders().size() != 0) {
                    fail("Unexpected number of providers present");
                }
            }
        }
    }
    assertTrue(testedEndpointWithProviders);
}
Also used : Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 15 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class DisruptorComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
    final int concurrentConsumers = getAndRemoveParameter(parameters, "concurrentConsumers", Integer.class, defaultConcurrentConsumers);
    final boolean limitConcurrentConsumers = getAndRemoveParameter(parameters, "limitConcurrentConsumers", Boolean.class, true);
    if (limitConcurrentConsumers && concurrentConsumers > MAX_CONCURRENT_CONSUMERS) {
        throw new IllegalArgumentException("The limitConcurrentConsumers flag in set to true. ConcurrentConsumers cannot be set at a value greater than " + MAX_CONCURRENT_CONSUMERS + " was " + concurrentConsumers);
    }
    if (concurrentConsumers < 0) {
        throw new IllegalArgumentException("concurrentConsumers found to be " + concurrentConsumers + ", must be greater than 0");
    }
    int size = 0;
    if (parameters.containsKey("size")) {
        size = getAndRemoveParameter(parameters, "size", int.class);
        if (size <= 0) {
            throw new IllegalArgumentException("size found to be " + size + ", must be greater than 0");
        }
    }
    // replacement for the SEDA component.
    if (parameters.containsKey("pollTimeout")) {
        throw new IllegalArgumentException("The 'pollTimeout' argument is not supported by the Disruptor component");
    }
    final DisruptorWaitStrategy waitStrategy = getAndRemoveParameter(parameters, "waitStrategy", DisruptorWaitStrategy.class, defaultWaitStrategy);
    final DisruptorProducerType producerType = getAndRemoveParameter(parameters, "producerType", DisruptorProducerType.class, defaultProducerType);
    final boolean multipleConsumers = getAndRemoveParameter(parameters, "multipleConsumers", boolean.class, defaultMultipleConsumers);
    final boolean blockWhenFull = getAndRemoveParameter(parameters, "blockWhenFull", boolean.class, defaultBlockWhenFull);
    final DisruptorReference disruptorReference = getOrCreateDisruptor(uri, remaining, size, producerType, waitStrategy);
    final DisruptorEndpoint disruptorEndpoint = new DisruptorEndpoint(uri, this, disruptorReference, concurrentConsumers, multipleConsumers, blockWhenFull);
    disruptorEndpoint.setWaitStrategy(waitStrategy);
    disruptorEndpoint.setProducerType(producerType);
    disruptorEndpoint.configureProperties(parameters);
    return disruptorEndpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint)

Aggregations

Endpoint (org.apache.camel.Endpoint)564 Test (org.junit.Test)206 Exchange (org.apache.camel.Exchange)201 Producer (org.apache.camel.Producer)137 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)89 Processor (org.apache.camel.Processor)43 Message (org.apache.camel.Message)38 CamelContext (org.apache.camel.CamelContext)32 HashMap (java.util.HashMap)28 Map (java.util.Map)28 Consumer (org.apache.camel.Consumer)27 RouteBuilder (org.apache.camel.builder.RouteBuilder)24 File (java.io.File)21 Route (org.apache.camel.Route)21 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 DefaultExchange (org.apache.camel.impl.DefaultExchange)16 SpanDecorator (org.apache.camel.opentracing.SpanDecorator)15 ArrayList (java.util.ArrayList)14 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)14