@Override protected void doInitialize() { if (this.taskScheduler == null) { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setThreadNamePrefix(getBeanName() + "-consumerMonitor-"); threadPoolTaskScheduler.afterPropertiesSet(); this.taskScheduler = threadPoolTaskScheduler; } if (this.messagesPerAck > 0) { Assert.state(!isChannelTransacted(), "'messagesPerAck' is not allowed with transactions"); } }
try { RabbitUtils.closeMessageConsumer(c.getChannel(), Collections.singletonList(c.getConsumerTag()), isChannelTransacted());
try { RabbitUtils.closeMessageConsumer(c.getChannel(), Collections.singletonList(c.getConsumerTag()), isChannelTransacted());
@Override protected void doInitialize() { if (this.taskScheduler == null) { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setThreadNamePrefix(getBeanName() + "-consumerMonitor-"); threadPoolTaskScheduler.afterPropertiesSet(); this.taskScheduler = threadPoolTaskScheduler; } if (this.messagesPerAck > 0) { Assert.state(!isChannelTransacted(), "'messagesPerAck' is not allowed with transactions"); } }
private void handleAck(long deliveryTag, boolean channelLocallyTransacted) { /* * If we have a TX Manager, but no TX, act like we are locally transacted. */ boolean isLocallyTransacted = channelLocallyTransacted || (isChannelTransacted() && TransactionSynchronizationManager.getResource(this.connectionFactory) == null); try { if (this.ackRequired) { if (this.messagesPerAck > 1) { synchronized (this) { this.latestDeferredDeliveryTag = deliveryTag; this.pendingAcks++; this.lastDeliveryComplete = System.currentTimeMillis(); ackIfNecessary(this.lastDeliveryComplete); } } else if (!isChannelTransacted() || isLocallyTransacted) { getChannel().basicAck(deliveryTag, false); } } if (isLocallyTransacted) { RabbitUtils.commitIfNecessary(getChannel()); } } catch (Exception e) { this.logger.error("Error acking", e); } }
private void handleAck(long deliveryTag, boolean channelLocallyTransacted) { /* * If we have a TX Manager, but no TX, act like we are locally transacted. */ boolean isLocallyTransacted = channelLocallyTransacted || (isChannelTransacted() && TransactionSynchronizationManager.getResource(this.connectionFactory) == null); try { if (this.ackRequired) { if (this.messagesPerAck > 1) { synchronized (this) { this.latestDeferredDeliveryTag = deliveryTag; this.pendingAcks++; this.lastDeliveryComplete = System.currentTimeMillis(); ackIfNecessary(this.lastDeliveryComplete); } } else if (!isChannelTransacted() || isLocallyTransacted) { getChannel().basicAck(deliveryTag, false); } } if (isLocallyTransacted) { RabbitUtils.commitIfNecessary(getChannel()); } } catch (Exception e) { this.logger.error("Error acking", e); } }
private void rollback(long deliveryTag, Exception e) { if (isChannelTransacted()) { RabbitUtils.rollbackIfNecessary(getChannel()); } if (this.ackRequired) { try { if (this.messagesPerAck > 1) { synchronized (this) { if (this.pendingAcks > 0) { sendAck(System.currentTimeMillis()); } } } getChannel().basicNack(deliveryTag, true, ContainerUtils.shouldRequeue(isDefaultRequeueRejected(), e, this.logger)); } catch (IOException e1) { this.logger.error("Failed to nack message", e1); } } if (isChannelTransacted()) { RabbitUtils.commitIfNecessary(getChannel()); } }
private void rollback(long deliveryTag, Exception e) { if (isChannelTransacted()) { RabbitUtils.rollbackIfNecessary(getChannel()); } if (this.ackRequired) { try { if (this.messagesPerAck > 1) { synchronized (this) { if (this.pendingAcks > 0) { sendAck(System.currentTimeMillis()); } } } getChannel().basicNack(deliveryTag, true, ContainerUtils.shouldRequeue(isDefaultRequeueRejected(), e, this.logger)); } catch (IOException e1) { this.logger.error("Failed to nack message", e1); } } if (isChannelTransacted()) { RabbitUtils.commitIfNecessary(getChannel()); } }
@Nullable private SimpleConsumer consume(String queue, Connection connection) { Channel channel = null; SimpleConsumer consumer = null; try { channel = connection.createChannel(isChannelTransacted()); channel.basicQos(getPrefetchCount()); consumer = new SimpleConsumer(connection, channel, queue); channel.queueDeclarePassive(queue); consumer.consumerTag = channel.basicConsume(queue, getAcknowledgeMode().isAutoAck(), (getConsumerTagStrategy() != null ? getConsumerTagStrategy().createConsumerTag(queue) : ""), // NOSONAR never null isNoLocal(), isExclusive(), getConsumerArguments(), consumer); } catch (AmqpApplicationContextClosedException e) { throw new AmqpConnectException(e); } catch (Exception e) { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); consumer = handleConsumeException(queue, consumer, e); } return consumer; }
@Nullable private SimpleConsumer consume(String queue, Connection connection) { Channel channel = null; SimpleConsumer consumer = null; try { channel = connection.createChannel(isChannelTransacted()); channel.basicQos(getPrefetchCount()); consumer = new SimpleConsumer(connection, channel, queue); channel.queueDeclarePassive(queue); consumer.consumerTag = channel.basicConsume(queue, getAcknowledgeMode().isAutoAck(), (getConsumerTagStrategy() != null ? getConsumerTagStrategy().createConsumerTag(queue) : ""), // NOSONAR never null isNoLocal(), isExclusive(), getConsumerArguments(), consumer); } catch (AmqpApplicationContextClosedException e) { throw new AmqpConnectException(e); } catch (Exception e) { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); consumer = handleConsumeException(queue, consumer, e); } return consumer; }