Search in sources :

Example 41 with PollingConsumer

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

the class CamelPostProcessorHelper method createInjectionPollingConsumer.

/**
     * Factory method to create a started
     * {@link org.apache.camel.PollingConsumer} to be injected into a POJO
     */
protected PollingConsumer createInjectionPollingConsumer(Endpoint endpoint, Object bean, String beanName) {
    try {
        PollingConsumer consumer = endpoint.createPollingConsumer();
        startService(consumer, endpoint.getCamelContext(), bean, beanName);
        return consumer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) NoSuchBeanException(org.apache.camel.NoSuchBeanException) ProxyInstantiationException(org.apache.camel.ProxyInstantiationException)

Example 42 with PollingConsumer

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

the class ConsumerCache method receiveNoWait.

public Exchange receiveNoWait(Endpoint endpoint) {
    LOG.debug("<<<< {}", endpoint);
    PollingConsumer consumer = null;
    try {
        consumer = doGetPollingConsumer(endpoint, true);
        return consumer.receiveNoWait();
    } finally {
        if (consumer != null) {
            releasePollingConsumer(endpoint, consumer);
        }
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 43 with PollingConsumer

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

the class ConsumerCache method doStop.

protected void doStop() throws Exception {
    // when stopping we intend to shutdown
    ServiceHelper.stopAndShutdownServices(statistics, pool);
    try {
        ServiceHelper.stopAndShutdownServices(consumers.values());
    } finally {
        // ensure consumers are removed, and also from JMX
        for (PollingConsumer consumer : consumers.values()) {
            getCamelContext().removeService(consumer);
        }
    }
    consumers.clear();
    if (statistics != null) {
        statistics.clear();
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 44 with PollingConsumer

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

the class ConsumerCache method receive.

public Exchange receive(Endpoint endpoint, long timeout) {
    LOG.debug("<<<< {}", endpoint);
    PollingConsumer consumer = null;
    try {
        consumer = acquirePollingConsumer(endpoint);
        return consumer.receive(timeout);
    } finally {
        if (consumer != null) {
            releasePollingConsumer(endpoint, consumer);
        }
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 45 with PollingConsumer

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

the class DefaultConsumerCacheTest method testCacheConsumers.

public void testCacheConsumers() throws Exception {
    ConsumerCache cache = new ConsumerCache(this, context);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    // test that we cache at most 1000 consumers to avoid it eating to much memory
    for (int i = 0; i < 1003; i++) {
        Endpoint e = context.getEndpoint("direct:queue:" + i);
        PollingConsumer p = cache.getConsumer(e);
        assertNotNull("the polling consumer should not be null", p);
    }
    // the eviction is async so force cleanup
    cache.cleanUp();
    assertEquals("Size should be 1000", 1000, cache.size());
    cache.stop();
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint)

Aggregations

PollingConsumer (org.apache.camel.PollingConsumer)73 Exchange (org.apache.camel.Exchange)41 Test (org.junit.Test)27 HashMap (java.util.HashMap)21 CamelContext (org.apache.camel.CamelContext)21 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)21 RouteBuilder (org.apache.camel.builder.RouteBuilder)19 Endpoint (org.apache.camel.Endpoint)10 Connection (javax.jms.Connection)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ConnectionFactory (javax.jms.ConnectionFactory)7 JMSException (javax.jms.JMSException)7 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)5 ProducerTemplate (org.apache.camel.ProducerTemplate)4 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)4 Message (javax.jms.Message)3 Session (javax.jms.Session)3 TextMessage (javax.jms.TextMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 File (java.io.File)2