List of usage examples for org.springframework.amqp.rabbit.listener BlockingQueueConsumer getChannel
public Channel getChannel()
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
private boolean receiveAndExecute(final BlockingQueueConsumer consumer) throws Throwable { if (this.transactionManager != null) { try {//from www .ja va 2 s . c om return new TransactionTemplate(this.transactionManager, this.transactionAttribute) .execute(new TransactionCallback<Boolean>() { @Override public Boolean doInTransaction(TransactionStatus status) { ConnectionFactoryUtils.bindResourceToTransaction( new RabbitResourceHolder(consumer.getChannel(), false), getConnectionFactory(), true); try { return doReceiveAndExecute(consumer); } catch (RuntimeException e) { throw e; } catch (Throwable e) { //NOSONAR // ok to catch Throwable here because we re-throw it below throw new WrappedTransactionException(e); } } }); } catch (WrappedTransactionException e) { throw e.getCause(); } } return doReceiveAndExecute(consumer); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
private boolean doReceiveAndExecute(BlockingQueueConsumer consumer) throws Throwable { Channel channel = consumer.getChannel(); for (int i = 0; i < this.txSize; i++) { logger.trace("Waiting for message from consumer."); Message message = consumer.nextMessage(this.receiveTimeout); if (message == null) { break; }//from w ww.java 2 s .c o m try { executeListener(channel, message); } catch (ImmediateAcknowledgeAmqpException e) { break; } catch (Throwable ex) { //NOSONAR consumer.rollbackOnExceptionIfNecessary(ex); throw ex; } } return consumer.commitIfNecessary(isChannelLocallyTransacted(channel)); }