Source:
<code>public <T> T invoke(OperationsCallback<T> action) { final Channel currentChannel = this.dedicatedChannels.get(); Assert.state(currentChannel == null, () -> "Nested invoke() calls are not supported; channel '" + currentChannel + "' is already associated with this thread"); this.activeTemplateCallbacks.incrementAndGet(); RabbitResourceHolder resourceHolder = null; Connection connection = null; Channel channel; if (isChannelTransacted()) { resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); channel = resourceHolder.getChannel(); if (channel == null) { ConnectionFactoryUtils.releaseResources(resourceHolder); throw new IllegalStateException("Resource holder returned a null channel"); } } else { connection = getConnectionFactory().createConnection(); if (connection == null) { throw new IllegalStateException("Connection factory returned a null connection"); } try { channel = connection.createChannel(false); if (channel == null) { throw new IllegalStateException("Connection returned a null channel"); } RabbitUtils.setPhysicalCloseRequired(true); this.dedicatedChannels.set(channel); } catch (RuntimeException e) { RabbitUtils.closeConnection(connection); throw e; } } try { return action.doInRabbit(this); } finally { this.activeTemplateCallbacks.decrementAndGet(); this.dedicatedChannels.remove(); if (resourceHolder != null) { ConnectionFactoryUtils.releaseResources(resourceHolder); } else { RabbitUtils.closeChannel(channel); if (!(channel instanceof ChannelProxy)) { <START> RabbitUtils.isPhysicalCloseRequired(); <END> } RabbitUtils.closeConnection(connection); } } }</code><technical_language>need this in finally of doExecute() well</technical_language>

Target:
public <T> T invoke(OperationsCallback<T> action) { final Channel currentChannel = this.dedicatedChannels.get(); Assert.state(currentChannel == null, () -> "Nested invoke() calls are not supported; channel '" + currentChannel + "' is already associated with this thread"); this.activeTemplateCallbacks.incrementAndGet(); RabbitResourceHolder resourceHolder = null; Connection connection = null; Channel channel; if (isChannelTransacted()) { resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); channel = resourceHolder.getChannel(); if (channel == null) { ConnectionFactoryUtils.releaseResources(resourceHolder); throw new IllegalStateException("Resource holder returned a null channel"); } } else { connection = getConnectionFactory().createConnection(); if (connection == null) { throw new IllegalStateException("Connection factory returned a null connection"); } try { channel = connection.createChannel(false); if (channel == null) { throw new IllegalStateException("Connection returned a null channel"); } RabbitUtils.setPhysicalCloseRequired(channel, true); this.dedicatedChannels.set(channel); } catch (RuntimeException e) { RabbitUtils.closeConnection(connection); throw e; } } try { return action.doInRabbit(this); } finally { this.activeTemplateCallbacks.decrementAndGet(); this.dedicatedChannels.remove(); if (resourceHolder != null) { ConnectionFactoryUtils.releaseResources(resourceHolder); } else { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); } } }