Channel shutdown: channel error: reply-code=406, reply-text=PRECONDITION_FAILED - reply consumer already set
<p>I'm running multiple tests with <strong>spring-amqp</strong>, <strong>spring-rabbit</strong>. My Maven parent is
<strong>spring-boot-starter-parent:1.2.3.RELEASE</strong> which pulls:</p>

<pre><code>spring-rabbit:1.4.3.RELEASE
    spring-amqp:1.4.3.RELEASE
    amqp-client:3.4.2
</code></pre>

<p>At a certain point one of the tests fails with this error and I don't see the reason:</p>

<pre><code>Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,2119)
Channel shutdown: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=406, reply-text=PRECONDITION_FAILED - reply consumer already set, class-id=60, method-id=20)
Detected closed channel on exception.  Re-initializing: null
</code></pre>

<p>If I change to spring-boot-starter-parent:1.3.1.RELEASE all tests are passed.</p>

<p>Digging down in the different versions, it seems I can still reproduce the failed test with</p>

<pre><code>spring-rabbit:1.5.0.M1
    spring-amqp:1.5.0.M1
    amqp-client:3.5.5
</code></pre>

<p>but all tests are passing with</p>

<pre><code>spring-rabbit:1.5.0.RELEASE
    spring-amqp:1.5.0.RELEASE
    amqp-client:3.5.5
</code></pre>

<p>Is there any relevant change between 1.5.0.M1 and 1.5.0.RELEASE that could answer this?
I tried to browse <a href="https://github.com/spring-projects/spring-amqp/compare/v1.5.0.M1...v1.5.0.RELEASE" rel="nofollow">GitHub compare</a> but didn't help.</p>

<p><strong>1st update:</strong></p>

<p>I could narrow down the issue.
In the tests I <strong>call sendAndReceive() to a queue inside a HystrixCommand</strong> (from Netflix). This HystrixCommand uses a smaller (2s) timeout then the default reply timeout (5s) in RabbitTemplate.</p>

<p>A service is listening on that declared queue and returns the answer.</p>

<p>I have a certain test to <strong>do a sendAndReceive() to a non-existing queue</strong>.
When that special test is executed the HystrixCommand times out.</p>

<p>The next test executing sendAndReceive() to the declared queue gives the channel error.</p>

<pre><code>@SpringBootApplication
public class SpringAmqpTestApplication implements CommandLineRunner {

    public static final String QUEUE_NAME = "Spring-AMQP-Test";
    private static final String NONEXISTENT_QUEUE_NAME = UUID.randomUUID().toString() + "@" + System.currentTimeMillis();

    public static void main( String[] args ) {
        SpringApplication.run( SpringAmqpTestApplication.class, args );
    }

    @Autowired
    AmqpTemplate amqpTemplate;

    @Override
    public void run( String... args ) throws Exception {
        sendAndReceive( QUEUE_NAME );

        sendAndReceive( NONEXISTENT_QUEUE_NAME );

        sendAndReceive( QUEUE_NAME );
    }

    private void sendAndReceive( String routingKey ) {
        CustomHystrixCommand customHystrixCommand = new CustomHystrixCommand( amqpTemplate, routingKey );
        String answer = customHystrixCommand.execute();
        System.err.println( "&lt; sendAndReceive(): " + answer );
    }
}
</code></pre>

<p>My HystrixCommand is fairly simple:</p>

<pre><code>public class CustomHystrixCommand extends HystrixCommand&lt;String&gt; {

    private String routingKey;

    AmqpTemplate amqpTemplate;

    public CustomHystrixCommand( AmqpTemplate amqpTemplate, String routingKey ) {
        super( HystrixCommandGroupKey.Factory.asKey( "" ), 2000 );
        this.amqpTemplate = amqpTemplate;
        this.routingKey = routingKey;
    }

    @Override
    protected String run() throws Exception {
        String request = UUID.randomUUID().toString();
        MessageProperties messageProperties = new MessageProperties();
        Message message = new Message( request.getBytes(), messageProperties );
        Message answer = amqpTemplate.sendAndReceive( "", routingKey, message );
        return "OK answer";
    }

    @Override
    protected String getFallback() {
        return "getFallback()";
    }

}
</code></pre>

<p>With spring-boot-starter-parent:1.2.3.RELEASE my logs are:</p>

<pre><code>&lt; sendAndReceive(): OK answer
&lt; sendAndReceive(): getFallback()
2016-01-27 11:47:42.266 ERROR 15007 --- [pool-1-thread-1] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=406, reply-text=PRECONDITION_FAILED - reply consumer already set, class-id=60, method-id=20)
&lt; sendAndReceive(): getFallback()
</code></pre>

<p>while with spring-boot-starter-parent:1.3.1.RELEASE:</p>

<pre><code>&lt; sendAndReceive(): OK answer
&lt; sendAndReceive(): getFallback()
&lt; sendAndReceive(): OK answer
</code></pre>

<p>Thanks for any help / explanation.</p>