consumer = endpoint.createConsumer(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); } }
@Override public Consumer createConsumer(Processor processor) throws Exception { return delegate.createConsumer(processor); }
protected Consumer createConsumer() throws JMSException { try { Consumer answer = endpoint.createConsumer(new Processor() { public void process(Exchange exchange) throws Exception { Message message = createMessage(exchange); getMessageListener().onMessage(message); } }); answer.start(); return answer; } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(e); } }
public Consumer createConsumer(Processor processor) throws Exception { return getCamelContext().getEndpoint(child).createConsumer(processor); }
public Consumer createConsumer(Processor processor) throws Exception { return getCamelContext().getEndpoint(child).createConsumer(processor); }
protected Consumer createConsumer() throws JMSException { try { Consumer answer = endpoint.createConsumer(new Processor() { public void process(Exchange exchange) throws Exception { Message message = createMessage(exchange); getMessageListener().onMessage(message); } }); answer.start(); return answer; } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(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; }
protected void onLockOwned() { if (delegate == null) { try { delegate = endpoint.getChildEndpoint().createConsumer(processor); delegateService = null; if (delegate instanceof SuspendableService) { delegateService = (SuspendableService) delegate; } // Lets show we are starting the consumer. CamelNodeState nodeState = createNodeState(); nodeState.started = true; singleton.update(nodeState); ServiceHelper.startService(delegate); } catch (Exception e) { LOG.error("Failed to start master consumer for: " + endpoint + ". Reason: " + e, e); } } }
protected void onLockOwned() { if (delegate == null) { try { delegate = endpoint.getChildEndpoint().createConsumer(processor); delegateService = null; if (delegate instanceof SuspendableService) { delegateService = (SuspendableService) delegate; } // Lets show we are starting the consumer. CamelNodeState nodeState = createNodeState(); nodeState.started = true; singleton.update(nodeState); ServiceHelper.startService(delegate); } catch (Exception e) { LOG.error("Failed to start master consumer for: " + endpoint + ". Reason: " + e, e); } } }
protected void initialize() throws Exception { // start the service here camelEndpoint = getCamelContext().getEndpoint(getCamelEndpointUri()); consumer = camelEndpoint.createConsumer(new ConsumerProcessor()); ServiceHelper.startService(consumer); }
@Override public Consumer createConsumer(final Processor processor) throws Exception { final Processor beforeConsumer = getBeforeConsumer(); final Processor afterConsumer = getAfterConsumer(); // use a pipeline to process before, processor, after in that order // create consumer with the pipeline final Processor pipeline = Pipeline.newInstance(getCamelContext(), beforeConsumer, processor, afterConsumer); final Consumer consumer = endpoint.createConsumer(pipeline); configureConsumer(consumer); return consumer; }
private synchronized void onLeadershipTaken() throws Exception { if (!isRunAllowed()) { return; } if (delegatedConsumer != null) { return; } delegatedConsumer = delegatedEndpoint.createConsumer(processor); if (delegatedConsumer instanceof StartupListener) { getEndpoint().getCamelContext().addStartupListener((StartupListener) delegatedConsumer); } ServiceHelper.startService(delegatedEndpoint); ServiceHelper.startService(delegatedConsumer); LOGGER.info("Leadership taken: consumer started: {}", delegatedEndpoint); }
@Override public Consumer createConsumer(final Processor processor) throws Exception { final Processor beforeConsumer = getBeforeConsumer(); final Processor afterConsumer = getAfterConsumer(); // use a pipeline to process before, processor, after in that order // create consumer with the pipeline final Processor pipeline = Pipeline.newInstance(getCamelContext(), beforeConsumer, processor, afterConsumer); final Consumer consumer = endpoint.createConsumer(pipeline); configureConsumer(consumer); return consumer; }
@Override protected void doStart() throws Exception { super.doStart(); final ServiceEndpoint endpoint = (ServiceEndpoint)getEndpoint(); final ServiceDefinition definition = endpoint.getServiceDefinition(); LOGGER.debug("Using ServiceRegistry instance {} (id={}, type={}) to register: {}", serviceRegistry, serviceRegistry.getId(), serviceRegistry.getClass().getName(), definition ); // register service serviceRegistry.register(definition); // start delegate delegatedConsumer = delegatedEndpoint.createConsumer(processor); if (delegatedConsumer instanceof StartupListener) { getEndpoint().getCamelContext().addStartupListener((StartupListener) delegatedConsumer); } ServiceHelper.startService(delegatedEndpoint); ServiceHelper.startService(delegatedConsumer); }
@Override public T create(CreationalContext<T> creationalContext) { try { CamelContext context = isNotEmpty(exporter.getCamelContextId()) ? getReferenceByName(manager, exporter.getCamelContextId(), CamelContext.class).get() : getReference(manager, CamelContext.class, this.context); Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef())); if (bean == null) { throw new UnsatisfiedResolutionException("No bean with name [" + exporter.getServiceRef() + "] is deployed!"); } @SuppressWarnings("unchecked") T service = (T) manager.getReference(bean, type, manager.createCreationalContext(bean)); Endpoint endpoint = getMandatoryEndpoint(context, exporter.getUri()); try { // need to start endpoint before we create consumer startService(endpoint); Consumer consumer = endpoint.createConsumer(new BeanProcessor(service, context)); // add and start consumer context.addService(consumer, true, true); } catch (Exception cause) { throw new FailedToCreateConsumerException(endpoint, cause); } return service; } catch (Exception cause) { throw new CreationException("Error while creating instance for " + this, cause); } }
protected Runnable onLockOwned() { return () -> { if (delegate == null) { try { // ensure endpoint is also started LOG.info("Elected as master. Starting consumer: {}", endpoint.getConsumerEndpoint()); ServiceHelper.startService(endpoint.getConsumerEndpoint()); delegate = endpoint.getConsumerEndpoint().createConsumer(processor); delegateService = null; if (delegate instanceof SuspendableService) { delegateService = (SuspendableService) delegate; } // Lets show we are starting the consumer. thisNodeState = createNodeState(); thisNodeState.setStarted(true); groupListener.updateState(thisNodeState); ServiceHelper.startService(delegate); } catch (Exception e) { LOG.error("Failed to start master consumer for: {}", endpoint, e); } LOG.info("Elected as master. Consumer started: {}", endpoint.getConsumerEndpoint()); } }; }