GetResponse resp = channel.basicGet(this.queue, false); if (resp == null) { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); return null; RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); throw RabbitExceptionTranslator.convertRabbitAccessException(e);
private String processStackTrace(Throwable cause) { String stackTraceAsString = getStackTraceAsString(cause); if (this.maxStackTraceLength < 0) { int maxStackTraceLen = RabbitUtils .getMaxFrame(((RabbitTemplate) this.errorTemplate).getConnectionFactory()); if (maxStackTraceLen > 0) { maxStackTraceLen -= this.frameMaxHeadroom; this.maxStackTraceLength = maxStackTraceLen; } } if (this.maxStackTraceLength > 0 && stackTraceAsString.length() > this.maxStackTraceLength) { stackTraceAsString = stackTraceAsString.substring(0, this.maxStackTraceLength); this.logger.warn("Stack trace in republished message header truncated due to frame_max limitations; " + "consider increasing frame_max on the broker or reduce the stack trace depth", cause); } return stackTraceAsString; }
@Override public void log(Log logger, String message, Throwable t) { if (t instanceof ShutdownSignalException) { ShutdownSignalException cause = (ShutdownSignalException) t; if (RabbitUtils.isPassiveDeclarationChannelClose(cause)) { if (logger.isDebugEnabled()) { logger.debug(message + ": " + cause.getMessage()); } } else if (RabbitUtils.isExclusiveUseChannelClose(cause)) { if (logger.isInfoEnabled()) { logger.info(message + ": " + cause.getMessage()); } } else if (!RabbitUtils.isNormalChannelClose(cause)) { logger.error(message + ": " + cause.getMessage()); } } else { logger.error("Unexpected invocation of " + this.getClass() + ", with message: " + message, t); } }
private void finalizeConsumer() { RabbitUtils.setPhysicalCloseRequired(getChannel(), true); RabbitUtils.closeChannel(getChannel()); RabbitUtils.closeConnection(this.connection); DirectMessageListenerContainer.this.cancellationLock.release(this); consumerRemoved(this); }
@Override public void log(Log logger, String message, Throwable t) { if (t instanceof ShutdownSignalException) { ShutdownSignalException cause = (ShutdownSignalException) t; if (RabbitUtils.isExclusiveUseChannelClose(cause)) { if (logger.isWarnEnabled()) { logger.warn(message + ": " + cause.toString()); } } else if (!RabbitUtils.isNormalChannelClose(cause)) { logger.error(message + ": " + cause.getMessage()); } } else { if (logger.isErrorEnabled()) { logger.error("Unexpected invocation of " + this.getClass() + ", with message: " + message, t); } } }
public void closeAll() { for (Channel channel : this.channels) { try { if (channel != ConsumerChannelRegistry.getConsumerChannel()) { channel.close(); } else { if (logger.isDebugEnabled()) { logger.debug("Skipping close of consumer channel: " + channel.toString()); } } } catch (Exception ex) { logger.debug("Could not close synchronized Rabbit Channel after transaction", ex); } } for (Connection con : this.connections) { //NOSONAR RabbitUtils.closeConnection(con); } this.connections.clear(); this.channels.clear(); this.channelsPerConnection.clear(); }
RabbitUtils.setPhysicalCloseRequired(channel, true); RabbitUtils.closeConnection(connection); throw e;
public void rollbackAll() { for (Channel channel : this.channels) { if (logger.isDebugEnabled()) { logger.debug("Rolling back messages to channel: " + channel); } RabbitUtils.rollbackIfNecessary(channel); if (this.deliveryTags.containsKey(channel)) { for (Long deliveryTag : this.deliveryTags.get(channel)) { try { channel.basicReject(deliveryTag, this.requeueOnRollback); } catch (IOException ex) { throw new AmqpIOException(ex); } } // Need to commit the reject (=nack) RabbitUtils.commitIfNecessary(channel); } } }
CompletableFuture<Delivery> future = new CompletableFuture<>(); ShutdownListener shutdownListener = c -> { if (!RabbitUtils.isNormalChannelClose(c)) { future.completeExceptionally(c); RabbitUtils.setPhysicalCloseRequired(channel, true);
private CountDownLatch[] setUpChannelLatches(ApplicationContext context) { CachingConnectionFactory cf = context.getBean(CachingConnectionFactory.class); final CountDownLatch cancelLatch = new CountDownLatch(1); final CountDownLatch mismatchLatch = new CountDownLatch(1); final CountDownLatch preventContainerRedeclareQueueLatch = new CountDownLatch(1); cf.addChannelListener((ShutDownChannelListener) s -> { if (RabbitUtils.isNormalChannelClose(s)) { cancelLatch.countDown(); try { preventContainerRedeclareQueueLatch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else if (RabbitUtils.isMismatchedQueueArgs(s)) { mismatchLatch.countDown(); } }); return new CountDownLatch[] { cancelLatch, mismatchLatch, preventContainerRedeclareQueueLatch }; }
RabbitUtils.setPhysicalCloseRequired(channelToClose, true);
public synchronized void stop() { if (this.abortStarted == 0) { // signal handle delivery to use offer this.abortStarted = System.currentTimeMillis(); } if (!this.cancelled()) { try { RabbitUtils.closeMessageConsumer(this.channel, getConsumerTags(), this.transactional); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Error closing consumer " + this, e); } } } if (logger.isDebugEnabled()) { logger.debug("Closing Rabbit Channel: " + this.channel); } RabbitUtils.setPhysicalCloseRequired(this.channel, true); ConnectionFactoryUtils.releaseResources(this.resourceHolder); this.deliveryTags.clear(); this.consumers.clear(); this.queue.clear(); // in case we still have a client thread blocked }
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.amqpAdmin != null) { try { this.amqpAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } else { try { Connection connection = getConnectionFactory().createConnection(); // NOSONAR if (connection != null) { connection.close(); } } catch (Exception e) { logger.info("Broker not available; cannot force queue declarations during start"); } } }
RabbitUtils.commitIfNecessary(this.channel);
ClosingRecoveryListener.addRecoveryListenerIfNecessary(channel); ShutdownListener shutdownListener = c -> { if (!RabbitUtils.isNormalChannelClose(c)) { pendingReply.completeExceptionally(c);
public static void closeMessageConsumer(Channel channel, Collection<String> consumerTags, boolean transactional) { if (!channel.isOpen() && !(channel instanceof ChannelProxy && ((ChannelProxy) channel).getTargetChannel() instanceof AutorecoveringChannel) && !(channel instanceof AutorecoveringChannel)) { return; } try { for (String consumerTag : consumerTags) { cancel(channel, consumerTag); } if (transactional) { /* * Re-queue in-flight messages if any (after the consumer is cancelled to prevent the broker from simply * sending them back to us). Does not require a tx.commit. */ channel.basicRecover(true); } /* * If not transactional then we are auto-acking (at least as of 1.0.0.M2) so there is nothing to recover. * Messages are going to be lost in general. */ } catch (Exception ex) { throw RabbitExceptionTranslator.convertRabbitAccessException(ex); } }
.forEach(c -> { try { RabbitUtils.closeMessageConsumer(c.getChannel(), Collections.singletonList(c.getConsumerTag()), isChannelTransacted());
private void finalizeConsumer() { RabbitUtils.setPhysicalCloseRequired(getChannel(), true); RabbitUtils.closeChannel(getChannel()); RabbitUtils.closeConnection(this.connection); DirectMessageListenerContainer.this.cancellationLock.release(this); consumerRemoved(this); }
public void closeAll() { for (Channel channel : this.channels) { try { if (channel != ConsumerChannelRegistry.getConsumerChannel()) { channel.close(); } else { if (logger.isDebugEnabled()) { logger.debug("Skipping close of consumer channel: " + channel.toString()); } } } catch (Exception ex) { logger.debug("Could not close synchronized Rabbit Channel after transaction", ex); } } for (Connection con : this.connections) { //NOSONAR RabbitUtils.closeConnection(con); } this.connections.clear(); this.channels.clear(); this.channelsPerConnection.clear(); }
RabbitUtils.setPhysicalCloseRequired(channel, true); RabbitUtils.closeConnection(connection); throw e;