首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通道关闭:信道错误:回-代码=406,回-文本=前提_FAILED应答使用者已经设置

通道关闭:信道错误:回-代码=406,回-文本=前提_FAILED应答使用者已经设置
EN

Stack Overflow用户
提问于 2016-01-26 15:00:42
回答 1查看 8.8K关注 0票数 2

我正在使用spring-rabbit.的spring运行多个测试我的Maven父母是spring-boot-starter-parent:1.2.3.RELEASE,它的作用是:

代码语言:javascript
复制
spring-rabbit:1.4.3.RELEASE
    spring-amqp:1.4.3.RELEASE
    amqp-client:3.4.2

在某一点上,其中一个测试失败了,但我不认为原因是:

代码语言:javascript
复制
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 starter:1.3.1.RELEASE,所有测试都会通过。

深入研究不同的版本,我似乎仍然可以用

代码语言:javascript
复制
spring-rabbit:1.5.0.M1
    spring-amqp:1.5.0.M1
    amqp-client:3.5.5

但是所有的测试都通过了

代码语言:javascript
复制
spring-rabbit:1.5.0.RELEASE
    spring-amqp:1.5.0.RELEASE
    amqp-client:3.5.5

在1.5.0.M1和1.5.0之间是否有任何相关的变化可以回答这个问题?我试着浏览GitHub比较,但没有帮上忙。

第一次更新:

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

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

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

对声明的队列执行sendAndReceive()的下一个测试将产生通道错误。

代码语言:javascript
复制
@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相当简单:

代码语言:javascript
复制
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 starter:1.2.3,我的日志是:

代码语言:javascript
复制
< 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 starter:1.3.1.RELEASE:

代码语言:javascript
复制
< sendAndReceive(): OK answer
< sendAndReceive(): getFallback()
< sendAndReceive(): OK answer

谢谢你的帮助/解释。

EN

回答 1

Stack Overflow用户

发布于 2016-01-26 16:04:25

我不知道有什么变化(但还没有看过),但无论如何,1.5.0.M1是一个预发布的milestone,1.5.0RELEASE是一个发行版。当实际发行版可用时,不应使用里程碑。当前的版本是1.5.3 release。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35016910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档