public EndpointMessageListener getEndpointMessageListener() { if (messageListener == null) { createMessageListener(getEndpoint(), getProcessor()); } return messageListener; }
public AbstractMessageListenerContainer getListenerContainer() throws Exception { if (listenerContainer == null) { createMessageListenerContainer(); } return listenerContainer; }
@Override protected void doResume() throws Exception { // we may not have been started before, and now the end user calls resume, so lets handle that and start it first if (!initialized) { doStart(); } else { if (listenerContainer != null) { startListenerContainer(); } else { log.warn("The listenerContainer is not instantiated. Probably there was a timeout during the Suspend operation. Please restart your consumer route."); } } }
protected void prepareAndStartListenerContainer() { listenerContainer.afterPropertiesSet(); // only start listener if auto start is enabled or we are explicit invoking start later if (initialized || getEndpoint().isAutoStartup()) { // should we pre test connections before starting? if (getEndpoint().isTestConnectionOnStartup()) { testConnectionOnStartup(); } startListenerContainer(); } }
@Override protected void doStart() throws Exception { super.doStart(); // create listener container if (listenerContainer == null) { createMessageListenerContainer(); } getEndpoint().onListenerContainerStarting(listenerContainer); if (getEndpoint().getConfiguration().isAsyncStartListener()) { getEndpoint().getAsyncStartStopExecutorService().submit(new Runnable() { @Override public void run() { try { prepareAndStartListenerContainer(); } catch (Throwable e) { log.warn("Error starting listener container on destination: " + getDestinationName() + ". This exception will be ignored.", e); } } @Override public String toString() { return "AsyncStartListenerTask[" + getDestinationName() + "]"; } }); } else { prepareAndStartListenerContainer(); } // mark as initialized for the first time initialized = true; }
protected void createMessageListenerContainer() throws Exception { listenerContainer = getEndpoint().createMessageListenerContainer(); getEndpoint().configureListenerContainer(listenerContainer, this); listenerContainer.setMessageListener(getEndpointMessageListener()); }
/** * Pre tests the connection before starting the listening. * <p/> * In case of connection failure the exception is thrown which prevents Camel from starting. * * @throws FailedToCreateConsumerException is thrown if testing the connection failed */ protected void testConnectionOnStartup() throws FailedToCreateConsumerException { try { log.debug("Testing JMS Connection on startup for destination: {}", getDestinationName()); Connection con = listenerContainer.getConnectionFactory().createConnection(); JmsUtils.closeConnection(con); log.debug("Successfully tested JMS Connection on startup for destination: {}", getDestinationName()); } catch (Exception e) { String msg = "Cannot get JMS Connection on startup for destination " + getDestinationName(); throw new FailedToCreateConsumerException(getEndpoint(), msg, e); } }
@Override protected void doStop() throws Exception { if (listenerContainer != null) { if (getEndpoint().getConfiguration().isAsyncStopListener()) { getEndpoint().getAsyncStartStopExecutorService().submit(new Runnable() { @Override public void run() { try { stopAndDestroyListenerContainer(); } catch (Throwable e) { log.warn("Error stopping listener container on destination: " + getDestinationName() + ". This exception will be ignored.", e); } } @Override public String toString() { return "AsyncStopListenerTask[" + getDestinationName() + "]"; } }); } else { stopAndDestroyListenerContainer(); } } super.doStop(); }
protected void stopAndDestroyListenerContainer() { if (listenerContainer != null) { try { listenerContainer.stop(); listenerContainer.destroy(); } finally { getEndpoint().onListenerContainerStopped(listenerContainer); } } // null container and listener so they are fully re created if this consumer is restarted // then we will use updated configuration from jms endpoint that may have been managed using JMX listenerContainer = null; messageListener = null; initialized = false; // shutdown thread pool if listener container was using a private thread pool if (shutdownExecutorService && executorService != null) { getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executorService); } executorService = null; }
@Override public void run() { try { prepareAndStartListenerContainer(); } catch (Throwable e) { log.warn("Error starting listener container on destination: " + getDestinationName() + ". This exception will be ignored.", e); } }
/** * Starts the JMS listener container * <p/> * Can be used to start this consumer later if it was configured to not auto startup. */ public void startListenerContainer() { log.trace("Starting listener container {} on destination {}", listenerContainer, getDestinationName()); listenerContainer.start(); log.debug("Started listener container {} on destination {}", listenerContainer, getDestinationName()); }
public JmsConsumer(JmsEndpoint endpoint, Processor processor, AbstractMessageListenerContainer listenerContainer) { super(endpoint, processor); this.listenerContainer = listenerContainer; this.listenerContainer.setMessageListener(getEndpointMessageListener()); }
/** * Creates a consumer using the given processor and listener container * * @param processor the processor to use to process the messages * @param listenerContainer the listener container * @return a newly created consumer * @throws Exception if the consumer cannot be created */ public JmsConsumer createConsumer(Processor processor, AbstractMessageListenerContainer listenerContainer) throws Exception { JmsConsumer consumer = new JmsConsumer(this, processor, listenerContainer); configureListenerContainer(listenerContainer, consumer); configureConsumer(consumer); return consumer; }
consumer.setListenerContainerExecutorService((ExecutorService) configuration.getTaskExecutor(), false); consumer.setListenerContainerExecutorService(executor, true); } else {
protected void createMessageListener(JmsEndpoint endpoint, Processor processor) { messageListener = new EndpointMessageListener(endpoint, processor); getEndpoint().getConfiguration().configureMessageListener(messageListener); messageListener.setBinding(endpoint.getBinding()); messageListener.setAsync(endpoint.getConfiguration().isAsyncConsumer()); }