我正在用rabbitmq和两个微服务建立一个项目。一个发布消息,一个消费消息。为了进行测试,我在docker compose文件中运行rabbitmq。
version: '3.3'
services:
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
当我重新启动虚拟机并运行docker compose时,整个系统运行良好。问题是当我关闭rabbitmq容器时
docker-compose down
或
docker-compose down -v
然后再次重新启动它当我重新启动我的消费者时,我得到以下堆栈跟踪:
2020-09-03 14:28:30.835 WARN 18140 --- [ntContainer#0-1] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue: employee
2020-09-03 14:28:30.841 WARN 18140 --- [ntContainer#0-1] o.s.a.r.listener.BlockingQueueConsumer : Queue declaration failed; retries left=3
org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[employee]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:700) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.passiveDeclarations(BlockingQueueConsumer.java:584) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1350) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.io.IOException: null
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:147) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:1012) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:46) ~[amqp-client-5.9.0.jar:5.9.0]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:1184) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
at com.sun.proxy.$Proxy48.queueDeclarePassive(Unknown Source) ~[na:na]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:679) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
... 5 common frames omitted
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'employee' in vhost '/', class-id=50, method-id=10)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:502) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:293) ~[amqp-client-5.9.0.jar:5.9.0]
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:141) ~[amqp-client-5.9.0.jar:5.9.0]
... 14 common frames omitted
这里是订户代码:
@Configuration
public class EmployeeMessageSubscriberConfig {
@Bean
@Qualifier("employeeQueue")
Queue queue() {
return new Queue(RabbitMqConstants.EMPLOYEE_QUEUE, false);
}
@Bean
@Qualifier("employeeExchange")
TopicExchange exchange() {
return new TopicExchange(RabbitMqConstants.EXCHANGE_NAME);
}
@Bean
@Qualifier("employeeQueueExchangeBinding")
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with("foo.bar.#");
}
@Bean
public Jackson2JsonMessageConverter producerMessageConverter() {
return new Jackson2JsonMessageConverter();
}
}
我还想知道,即使是入门指南也没有使用rabbitadmin。另外,备用amqp文档在“配置代理”一章中提到,应该使用rabbitadmin接口。所以另一个问题是:为什么在我不使用这个接口的时候还要启动呢?
暂无答案!
目前还没有任何答案,快来回答吧!