我正在使用spring-amqp、spring-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使用的超时(2s)比RabbitTemplate中的默认回复超时(5s)要小。
服务正在侦听声明的队列并返回应答。
我有一个特定的测试对一个不存在的队列执行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启动器启动器父母: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启动器时:1.3.1.释放:
< sendAndReceive(): OK answer
< sendAndReceive(): getFallback()
< sendAndReceive(): OK answer
谢谢你的帮助/解释。
1条答案
按热度按时间7uzetpgm1#
我不知道有什么变化(但也没有看),但是,无论如何,1.5.0.M1是
milestone
的预发行版,1.5.0.RELEASE是一个发行版。当实际发行版可用时,不应该使用里程碑。当前发行版是1.5.3.RELEASE。