我正在使用spring-rabbit.的spring运行多个测试我的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 starter: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之间是否有任何相关的变化可以回答这个问题?我试着浏览GitHub比较,但没有帮上忙。
第一次更新:
我可以缩小范围。在测试中,我将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 starter:1.2.3,我的日志是:
< 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:
< sendAndReceive(): OK answer
< sendAndReceive(): getFallback()
< sendAndReceive(): OK answer谢谢你的帮助/解释。
发布于 2016-01-26 16:04:25
我不知道有什么变化(但还没有看过),但无论如何,1.5.0.M1是一个预发布的milestone,1.5.0RELEASE是一个发行版。当实际发行版可用时,不应使用里程碑。当前的版本是1.5.3 release。
https://stackoverflow.com/questions/35016910
复制相似问题