List of usage examples for org.springframework.amqp.rabbit.listener BlockingQueueConsumer stop
public synchronized void stop()
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
protected void addAndStartConsumers(int delta) { synchronized (this.consumersMonitor) { if (this.consumers != null) { for (int i = 0; i < delta; i++) { BlockingQueueConsumer consumer = createBlockingQueueConsumer(); this.consumers.put(consumer, true); AsyncMessageProcessingConsumer processor = new AsyncMessageProcessingConsumer(consumer); if (logger.isDebugEnabled()) { logger.debug("Starting a new consumer: " + consumer); }//from w w w . ja v a 2 s . c o m this.taskExecutor.execute(processor); try { FatalListenerStartupException startupException = processor.getStartupException(); if (startupException != null) { this.consumers.remove(consumer); throw new AmqpIllegalStateException("Fatal exception on listener startup", startupException); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } catch (Exception e) { consumer.stop(); logger.error("Error starting new consumer", e); this.cancellationLock.release(consumer); this.consumers.remove(consumer); } } } } }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
private void restart(BlockingQueueConsumer consumer) { synchronized (this.consumersMonitor) { if (this.consumers != null) { try { // Need to recycle the channel in this consumer consumer.stop(); // Ensure consumer counts are correct (another is going // to start because of the exception, but // we haven't counted down yet) this.cancellationLock.release(consumer); this.consumers.remove(consumer); BlockingQueueConsumer newConsumer = createBlockingQueueConsumer(); newConsumer.setBackOffExecution(consumer.getBackOffExecution()); consumer = newConsumer;/*from w w w.j a va 2 s. c om*/ this.consumers.put(consumer, true); } catch (RuntimeException e) { logger.warn( "Consumer failed irretrievably on restart. " + e.getClass() + ": " + e.getMessage()); // Re-throw and have it logged properly by the caller. throw e; } this.taskExecutor.execute(new AsyncMessageProcessingConsumer(consumer)); } } }