【问题标题】:Channel shutdown: channel error: reply-code=406, reply-text=PRECONDITION_FAILED - reply consumer already set频道关闭:频道错误:回复代码 = 406,回复文本 = PRECONDITION_FAILED - 回复消费者已设置
【发布时间】:2016-01-26 15:00:42
【问题描述】:

我正在使用 spring-amqpspring-rabbit 运行多个测试。我的 Maven 父母是 spring-boot-starter-parent:1.2.3.RELEASE 拉动:

spring-rabbit:1.4.3.RELEASE
    spring-amqp:1.4.3.RELEASE
    amqp-client:3.4.2

在某个时候,其中一个测试因此错误而失败,我看不出原因:

Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,2119)
Channel shutdown: channel error; protocol method: #method<channel.close>(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

如果我改为 spring-boot-starter-parent:1.3.1.RELEASE 所有测试都通过了。

在不同的版本中挖掘,似乎我仍然可以重现失败的测试

spring-rabbit:1.5.0.M1
    spring-amqp:1.5.0.M1
    amqp-client:3.5.5

但所有测试都通过了

spring-rabbit:1.5.0.RELEASE
    spring-amqp:1.5.0.RELEASE
    amqp-client:3.5.5

1.5.0.M1 和 1.5.0.RELEASE 之间是否有任何相关的变化可以回答这个问题? 我尝试浏览GitHub compare,但没有帮助。

第一次更新:

我可以缩小问题的范围。 在测试中,我将 sendAndReceive() 调用到 HystrixCommand 内的队列中(来自 Netflix)。此 HystrixCommand 使用比 RabbitTemplate 中的默认回复超时 (5s) 更小的 (2s) 超时。

服务正在侦听该声明的队列并返回答案。

我有一个特定的测试来对不存在的队列执行 sendAndReceive()。 当执行该特殊测试时,HystrixCommand 会超时。

对声明的队列执行 sendAndReceive() 的下一个测试给出了通道错误。

@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( "< sendAndReceive(): " + answer );
    }
}

我的 HystrixCommand 相当简单:

public class CustomHystrixCommand extends HystrixCommand<String> {

    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()";
    }

}

使用 spring-boot-starter-parent:1.2.3.RELEASE 我的日志是:

< sendAndReceive(): OK answer
< 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<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - reply consumer already set, class-id=60, method-id=20)
< sendAndReceive(): getFallback()

同时使用 spring-boot-starter-parent:1.3.1.RELEASE:

< sendAndReceive(): OK answer
< sendAndReceive(): getFallback()
< sendAndReceive(): OK answer

感谢任何帮助/解释。

【问题讨论】:

  • 请分享那个测试。如果你说spring-amqp:1.4.3.RELEASE中没有修复,那么我们可以在本地播放和复现。当您确认在 1.5 或更高版本中一切正常时,从另一方不确定战斗是否有意义。

标签: rabbitmq spring-amqp spring-rabbit


【解决方案1】:

我不知道有任何更改(但还没有查看),但无论如何,1.5.0.M1 是一个预发布版milestone,而 1.5.0.RELEASE 是一个发布版。当实际版本可用时,绝不应使用里程碑。当前版本是 1.5.3.RELEASE。

【讨论】:

    猜你喜欢
    • 2018-07-27
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多