Search in sources :

Example 46 with Route

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

the class CamelJob method lookupQuartzEndpoint.

protected QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, JobExecutionContext quartzContext) throws JobExecutionException {
    TriggerKey triggerKey = quartzContext.getTrigger().getKey();
    JobDetail jobDetail = quartzContext.getJobDetail();
    JobKey jobKey = jobDetail.getKey();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Looking up existing QuartzEndpoint with triggerKey={}", triggerKey);
    }
    // as we prefer to use the existing endpoint from the routes
    for (Route route : camelContext.getRoutes()) {
        Endpoint endpoint = route.getEndpoint();
        if (endpoint instanceof DelegateEndpoint) {
            endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
        }
        if (endpoint instanceof QuartzEndpoint) {
            QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;
            TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
            if (LOG.isTraceEnabled()) {
                LOG.trace("Checking route endpoint={} with checkTriggerKey={}", quartzEndpoint, checkTriggerKey);
            }
            if (triggerKey.equals(checkTriggerKey) || (jobDetail.requestsRecovery() && jobKey.getGroup().equals(checkTriggerKey.getGroup()) && jobKey.getName().equals(checkTriggerKey.getName()))) {
                return quartzEndpoint;
            }
        }
    }
    // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
    String endpointUri = quartzContext.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_ENDPOINT_URI);
    QuartzEndpoint result = null;
    // Even though the same camelContext.getEndpoint call, but if/else display different log.
    if (camelContext.hasEndpoint(endpointUri) != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Getting Endpoint from camelContext.");
        }
        result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    } else if ((result = searchForEndpointMatch(camelContext, endpointUri)) != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found match for endpoint URI = " + endpointUri + " by searching endpoint list.");
        }
    } else {
        LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
        result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    }
    if (result == null) {
        throw new JobExecutionException("No QuartzEndpoint could be found with endpointUri: " + endpointUri);
    }
    return result;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobExecutionException(org.quartz.JobExecutionException) Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) Route(org.apache.camel.Route)

Example 47 with Route

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

the class QuartzEndpoint method ensureNoDupTriggerKey.

private void ensureNoDupTriggerKey() {
    for (Route route : getCamelContext().getRoutes()) {
        if (route.getEndpoint() instanceof QuartzEndpoint) {
            QuartzEndpoint quartzEndpoint = (QuartzEndpoint) route.getEndpoint();
            TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
            if (triggerKey.equals(checkTriggerKey)) {
                throw new IllegalArgumentException("Trigger key " + triggerKey + " is already in use by " + quartzEndpoint);
            }
        }
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) Route(org.apache.camel.Route)

Example 48 with Route

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

the class QuartzScheduledPollConsumerJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    LOG.trace("Execute job: {}", context);
    CamelContext camelContext = getCamelContext(context);
    Runnable task = (Runnable) context.getJobDetail().getJobDataMap().get("task");
    if (task == null) {
        // if not task then use the route id to lookup the consumer to be used as the task
        String routeId = (String) context.getJobDetail().getJobDataMap().get("routeId");
        if (routeId != null && camelContext != null) {
            // find the consumer
            for (Route route : camelContext.getRoutes()) {
                if (route.getId().equals(routeId)) {
                    Consumer consumer = route.getConsumer();
                    if (consumer instanceof Runnable) {
                        task = (Runnable) consumer;
                        break;
                    }
                }
            }
        }
    }
    if (task != null) {
        LOG.trace("Running task: {}", task);
        task.run();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) Consumer(org.apache.camel.Consumer) Route(org.apache.camel.Route)

Example 49 with Route

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

the class CamelAutoConfigurationTest method shouldDetectRoutes.

@Test
public void shouldDetectRoutes() {
    // When
    Route route = camelContext.getRoute(TestConfig.ROUTE_ID);
    // Then
    assertNotNull(route);
}
Also used : Route(org.apache.camel.Route) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 50 with Route

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

the class EtcdRoutePolicy method startAllStoppedConsumers.

private void startAllStoppedConsumers() {
    synchronized (lock) {
        try {
            for (Route route : suspendedRoutes) {
                LOGGER.debug("Starting consumer for {} ({})", route.getId(), route.getConsumer());
                startConsumer(route.getConsumer());
            }
            suspendedRoutes.clear();
        } catch (Exception e) {
            handleException(e);
        }
    }
}
Also used : Route(org.apache.camel.Route) RuntimeCamelException(org.apache.camel.RuntimeCamelException) TimeoutException(java.util.concurrent.TimeoutException) EtcdException(mousio.etcd4j.responses.EtcdException)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4