Search in sources :

Example 16 with Consumer

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

the class SedaEndpointTest method testSedaEndpoint.

public void testSedaEndpoint() throws Exception {
    SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), queue);
    assertNotNull(seda);
    assertEquals(1000, seda.getSize());
    assertSame(queue, seda.getQueue());
    assertEquals(1, seda.getConcurrentConsumers());
    Producer prod = seda.createProducer();
    seda.onStarted((SedaProducer) prod);
    assertEquals(1, seda.getProducers().size());
    Consumer cons = seda.createConsumer(new Processor() {

        public void process(Exchange exchange) throws Exception {
        // do nothing
        }
    });
    seda.onStarted((SedaConsumer) cons);
    assertEquals(1, seda.getConsumers().size());
    assertEquals(0, seda.getExchanges().size());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer)

Example 17 with Consumer

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

the class SedaEndpointTest method testSedaEndpointUnboundedQueue.

public void testSedaEndpointUnboundedQueue() throws Exception {
    BlockingQueue<Exchange> unbounded = new LinkedBlockingQueue<Exchange>();
    SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), unbounded);
    assertNotNull(seda);
    assertEquals(Integer.MAX_VALUE, seda.getSize());
    assertSame(unbounded, seda.getQueue());
    assertEquals(1, seda.getConcurrentConsumers());
    Producer prod = seda.createProducer();
    seda.onStarted((SedaProducer) prod);
    assertEquals(1, seda.getProducers().size());
    Consumer cons = seda.createConsumer(new Processor() {

        public void process(Exchange exchange) throws Exception {
        // do nothing
        }
    });
    seda.onStarted((SedaConsumer) cons);
    assertEquals(1, seda.getConsumers().size());
    assertEquals(0, seda.getExchanges().size());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 18 with Consumer

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

the class RetryRouteScopedUntilRecipientListIssueTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    context.addEndpoint("fail", new DefaultEndpoint() {

        public Producer createProducer() throws Exception {
            return new DefaultProducer(this) {

                public void process(Exchange exchange) throws Exception {
                    exchange.setException(new IllegalArgumentException("Damn"));
                }
            };
        }

        public Consumer createConsumer(Processor processor) throws Exception {
            return null;
        }

        @Override
        protected String createEndpointUri() {
            return "fail";
        }

        public boolean isSingleton() {
            return true;
        }
    });
    context.addEndpoint("not-fail", new DefaultEndpoint() {

        public Producer createProducer() throws Exception {
            return new DefaultProducer(this) {

                public void process(Exchange exchange) throws Exception {
                // noop
                }
            };
        }

        public Consumer createConsumer(Processor processor) throws Exception {
            return null;
        }

        @Override
        protected String createEndpointUri() {
            return "not-fail";
        }

        public boolean isSingleton() {
            return true;
        }
    });
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint) DefaultProducer(org.apache.camel.impl.DefaultProducer) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer) DefaultProducer(org.apache.camel.impl.DefaultProducer) ExchangeException(org.apache.camel.ExchangeException)

Example 19 with Consumer

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

the class DefaultPollingEndpoint method createConsumer.

public Consumer createConsumer(Processor processor) throws Exception {
    Consumer result = new DefaultScheduledPollConsumer(this, processor);
    configureConsumer(result);
    return result;
}
Also used : Consumer(org.apache.camel.Consumer)

Example 20 with Consumer

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

the class DefaultCamelContext method doStop.

protected synchronized void doStop() throws Exception {
    stopWatch.restart();
    log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is shutting down");
    EventHelper.notifyCamelContextStopping(this);
    // stop route inputs in the same order as they was started so we stop the very first inputs first
    try {
        // force shutting down routes as they may otherwise cause shutdown to hang
        shutdownStrategy.shutdownForced(this, getRouteStartupOrder());
    } catch (Throwable e) {
        log.warn("Error occurred while shutting down routes. This exception will be ignored.", e);
    }
    // shutdown await manager to trigger interrupt of blocked threads to attempt to free these threads graceful
    shutdownServices(asyncProcessorAwaitManager);
    shutdownServices(getRouteStartupOrder().stream().sorted(Comparator.comparing(RouteStartupOrder::getStartupOrder).reversed()).map(DefaultRouteStartupOrder.class::cast).map(DefaultRouteStartupOrder::getRouteService).collect(Collectors.toList()), false);
    // do not clear route services or startup listeners as we can start Camel again and get the route back as before
    getRouteStartupOrder().clear();
    // but clear any suspend routes
    suspendedRouteServices.clear();
    // which we need to stop after the routes, as a POJO consumer is essentially a route also
    for (Service service : servicesToStop) {
        if (service instanceof Consumer) {
            shutdownServices(service);
        }
    }
    // shutdown default error handler thread pool
    if (errorHandlerExecutorService != null) {
        // force shutting down the thread pool
        getExecutorServiceManager().shutdownNow(errorHandlerExecutorService);
        errorHandlerExecutorService = null;
    }
    // shutdown debugger
    ServiceHelper.stopAndShutdownService(getDebugger());
    shutdownServices(endpoints.values());
    endpoints.clear();
    shutdownServices(components.values());
    components.clear();
    shutdownServices(languages.values());
    languages.clear();
    try {
        for (LifecycleStrategy strategy : lifecycleStrategies) {
            strategy.onContextStop(this);
        }
    } catch (Throwable e) {
        log.warn("Error occurred while stopping lifecycle strategies. This exception will be ignored.", e);
    }
    // shutdown services as late as possible
    shutdownServices(servicesToStop);
    servicesToStop.clear();
    // must notify that we are stopped before stopping the management strategy
    EventHelper.notifyCamelContextStopped(this);
    // stop the notifier service
    for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) {
        shutdownServices(notifier);
    }
    // shutdown executor service and management as the last one
    shutdownServices(executorServiceManager);
    shutdownServices(managementStrategy);
    shutdownServices(managementMBeanAssembler);
    shutdownServices(lifecycleStrategies);
    // do not clear lifecycleStrategies as we can start Camel again and get the route back as before
    // stop the lazy created so they can be re-created on restart
    forceStopLazyInitialization();
    // stop to clear introspection cache
    IntrospectionSupport.stop();
    stopWatch.stop();
    if (log.isInfoEnabled()) {
        log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") uptime {}", getUptime());
        log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is shutdown in " + TimeUtils.printDuration(stopWatch.taken()));
    }
    // and clear start date
    startDate = null;
    // [TODO] Remove in 3.0
    Container.Instance.unmanage(this);
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Consumer(org.apache.camel.Consumer) LifecycleStrategy(org.apache.camel.spi.LifecycleStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SuspendableService(org.apache.camel.SuspendableService) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder)

Aggregations

Consumer (org.apache.camel.Consumer)76 Endpoint (org.apache.camel.Endpoint)27 Processor (org.apache.camel.Processor)19 Exchange (org.apache.camel.Exchange)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)10 RestConfiguration (org.apache.camel.spi.RestConfiguration)10 Producer (org.apache.camel.Producer)7 PollingConsumer (org.apache.camel.PollingConsumer)6 File (java.io.File)5 PollingConsumerPollStrategy (org.apache.camel.spi.PollingConsumerPollStrategy)5 FileNotFoundException (java.io.FileNotFoundException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 SuspendableService (org.apache.camel.SuspendableService)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelContext (org.apache.camel.CamelContext)3 Component (org.apache.camel.Component)3 NoSuchBeanException (org.apache.camel.NoSuchBeanException)3 Route (org.apache.camel.Route)3