/** * Initializes Camel's type converters by loading default type converters and annotated converters. * * @throws Exception if an error occurs while loading the type converters. */ public void init() throws Exception { _camelContext.addService(this); }
public void afterPropertiesSet() throws Exception { // lets bind the URI to a pojo notNull(uri, "uri"); // Always resolve the camel context by using the camelContextID if (ObjectHelper.isNotEmpty(camelContextId)) { camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId); } notNull(camelContext, "camelContext"); if (serviceRef != null && getService() == null && applicationContext != null) { setService(applicationContext.getBean(serviceRef)); } Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri); notNull(getService(), "service"); Object proxy = getProxyForService(); try { // need to start endpoint before we create consumer ServiceHelper.startService(endpoint); consumer = endpoint.createConsumer(new BeanProcessor(proxy, camelContext)); // add and start consumer camelContext.addService(consumer, true, true); } catch (Exception e) { throw new FailedToCreateConsumerException(endpoint, e); } }
producer = endpoint.createProducer(); camelContext.addService(producer, true, true); serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, getServiceInterface()); } catch (Exception e) {
private static <T> Consumer<T> addServiceToContext(final CamelContext camelContext) { return service -> { try { camelContext.addService(service); } catch (Exception e) { throw new RuntimeException("Unable to add service to Camel context", e); } }; }
@Bean(name = "lra-service") @ConditionalOnMissingBean(CamelSagaService.class) @ConditionalOnProperty(value = "camel.service.lra.enabled", havingValue = "true") public LRASagaService configureLraSagaService() throws Exception { LRASagaService service = new LRASagaService(); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); CamelPropertiesHelper.setCamelProperties(camelContext, service, parameters, false); camelContext.addService(service); return service; } }
private void addMapping(String url) throws Exception { LOG.info("Adding Dozer Mapping file " + url); WatcherDozerTypeConverterLoader loader = new WatcherDozerTypeConverterLoader(camelContext, url, mapper); // add by adding the loader as a service camelContext.addService(loader); loaders.put(url, loader); }
/** * Creates a <code>DozerTypeConverter</code> that will search the given * {@link CamelContext} for instances of {@link Mapper}. Each * discovered instance will be wrapped as a {@link DozerTypeConverter} and * register as a {@link TypeConverter} with the context * * @param camelContext the context to register the * {@link DozerTypeConverter} in */ public DozerTypeConverterLoader(CamelContext camelContext) { this.camelContext = camelContext; try { camelContext.addService(this); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
/** * Sets the {@link CamelContext} <b>and also</b> initializes this loader. * <p/> * The reason why {@link #init(org.apache.camel.CamelContext, com.github.dozermapper.core.Mapper)} is also called * is because making using Dozer in Spring XML files easier, as no need to use the init-method attribute. * * @param camelContext the CamelContext */ public void setCamelContext(CamelContext camelContext) { if (this.camelContext == null) { this.camelContext = camelContext; try { camelContext.addService(this); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } }
@Override public void beforeApplicationStart(CamelContext camelContext) { try { // register custom mbean camelContext.addService(new CamelContextMetadataMBean()); LOGGER.info("Added Syndesis MBean Service"); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { ObjectHelper.wrapRuntimeCamelException(e); } }
/** * Default consumer template for the bootstrapped Camel context. * Create the bean lazy as it should only be created if its in-use. */ // We explicitly declare the destroyMethod to be "" as the Spring @Bean // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise // and in that case Service::close (ConsumerTemplate implements Service) // would be used for bean destruction. And we want Camel to handle the // lifecycle. @Bean(destroyMethod = "") @ConditionalOnMissingBean(ConsumerTemplate.class) @Lazy ConsumerTemplate consumerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception { final ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize()); // we add this consumerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop) camelContext.addService(consumerTemplate); return consumerTemplate; }
@Override protected void doStart() throws Exception { // add by adding as service try { camelContext.addService(this); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } super.doStart(); }
/** * Default fluent producer template for the bootstrapped Camel context. * Create the bean lazy as it should only be created if its in-use. */ // We explicitly declare the destroyMethod to be "" as the Spring @Bean // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise // and in that case Service::close (FluentProducerTemplate implements Service) // would be used for bean destruction. And we want Camel to handle the // lifecycle. @Bean(destroyMethod = "") @ConditionalOnMissingBean(FluentProducerTemplate.class) @Lazy FluentProducerTemplate fluentProducerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception { final FluentProducerTemplate fluentProducerTemplate = camelContext.createFluentProducerTemplate(config.getProducerTemplateCacheSize()); // we add this fluentProducerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop) camelContext.addService(fluentProducerTemplate); return fluentProducerTemplate; }
/** * Default producer template for the bootstrapped Camel context. * Create the bean lazy as it should only be created if its in-use. */ // We explicitly declare the destroyMethod to be "" as the Spring @Bean // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise // and in that case Service::close (ProducerTemplate implements Service) // would be used for bean destruction. And we want Camel to handle the // lifecycle. @Bean(destroyMethod = "") @ConditionalOnMissingBean(ProducerTemplate.class) @Lazy ProducerTemplate producerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception { final ProducerTemplate producerTemplate = camelContext.createProducerTemplate(config.getProducerTemplateCacheSize()); // we add this producerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop) camelContext.addService(producerTemplate); return producerTemplate; }
/** * Registers this {@link ZipkinTracer} on the {@link CamelContext} if not already registered. */ public void init(CamelContext camelContext) { if (!camelContext.hasService(this)) { try { // start this service eager so we init before Camel is starting up camelContext.addService(this, true, true); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } }
/** * Registers this {@link OpenTracingTracer} on the {@link CamelContext} if * not already registered. */ public void init(CamelContext camelContext) { if (!camelContext.hasService(this)) { try { // start this service eager so we init before Camel is starting // up camelContext.addService(this, true, true); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } }
public boolean subscribe(String toTopic, final EventSubscriber subscriber) { try { Endpoint endpoint = camelContext.getEndpoint(prefixed(toTopic)); Consumer consumer = endpoint.createConsumer(new org.apache.camel.Processor() { public void process(Exchange exchange) throws Exception { Event event = (Event) exchange.getIn().getBody(); subscriber.receive(event); } }); camelContext.addService(consumer); synchronized (listeners) { listeners.put(new EventListener(toTopic, subscriber), consumer); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } return true; }
/** * Lazy creation of the CamelReactiveStreamsService * * @return the reactive streams service */ public synchronized CamelReactiveStreamsService getReactiveStreamsService() { if (service == null) { this.service = ReactiveStreamsHelper.resolveReactiveStreamsService( getCamelContext(), this.serviceType, this.internalEngineConfiguration ); try { // Start the service and add it to the Camel context to expose managed attributes getCamelContext().addService(service, true, true); } catch (Exception e) { throw new RuntimeCamelException(e); } } return service; }
@Override protected void doStart() throws Exception { super.doStart(); if (meterRegistry == null) { meterRegistry = MicrometerUtils.getOrCreateMeterRegistry(camelContext.getRegistry(), METRICS_REGISTRY_NAME); } try { MicrometerEventNotifierService registryService = camelContext.hasService(MicrometerEventNotifierService.class); if (registryService == null) { registryService = new MicrometerEventNotifierService(); registryService.setMeterRegistry(getMeterRegistry()); registryService.setPrettyPrint(isPrettyPrint()); registryService.setDurationUnit(getDurationUnit()); registryService.setMatchingTags(Tags.of(SERVICE_NAME, registryService.getClass().getSimpleName())); camelContext.addService(registryService); // ensure registry service is started ServiceHelper.startService(registryService); } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Override protected void doStart() throws Exception { if (meterRegistry == null) { meterRegistry = MicrometerUtils.getOrCreateMeterRegistry(camelContext.getRegistry(), METRICS_REGISTRY_NAME); } try { MicrometerMessageHistoryService messageHistoryService = camelContext.hasService(MicrometerMessageHistoryService.class); if (messageHistoryService == null) { messageHistoryService = new MicrometerMessageHistoryService(); messageHistoryService.setMeterRegistry(getMeterRegistry()); messageHistoryService.setPrettyPrint(isPrettyPrint()); messageHistoryService.setDurationUnit(getDurationUnit()); messageHistoryService.setMatchingTags(Tags.of(SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName())); camelContext.addService(messageHistoryService); } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Override protected void doStart() throws Exception { try { messageHistoryService = camelContext.hasService(MetricsMessageHistoryService.class); if (messageHistoryService == null) { messageHistoryService = new MetricsMessageHistoryService(); messageHistoryService.setMetricsRegistry(getMetricsRegistry()); messageHistoryService.setUseJmx(isUseJmx()); messageHistoryService.setJmxDomain(getJmxDomain()); messageHistoryService.setPrettyPrint(isPrettyPrint()); messageHistoryService.setRateUnit(getRateUnit()); messageHistoryService.setDurationUnit(getDurationUnit()); camelContext.addService(messageHistoryService); } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } // use metrics registry from service if not explicit configured if (metricsRegistry == null) { metricsRegistry = messageHistoryService.getMetricsRegistry(); } ObjectHelper.notNull(metricsRegistry, "metricsRegistry", this); }