[英]Failed to create RabbitMQ queue
I received a suggestion on this question , on a comment, saying that I might not have the Exchange I needed because my queues already existed.我在评论中收到了关于这个问题的建议,说我可能没有我需要的 Exchange,因为我的队列已经存在。 So, I manually deleted them all.
所以,我手动将它们全部删除。
However, when re-deploying the application, I had the following exception for all the queues I had:但是,在重新部署应用程序时,我拥有的所有队列都出现以下异常:
org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[myInput.group]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:721)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:598)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1472)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)
at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.queueDeclarePassive(AutorecoveringChannel.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)
at com.sun.proxy.$Proxy166.queueDeclarePassive(Unknown Source)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:700)
... 3 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'myInput.group' in vhost 'production', class-id=50, method-id=10)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)
... 12 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'myInput.group' in vhost 'production', class-id=50, method-id=10)
at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)
at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)
at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)
at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)
at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)
at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)
... 1 more
I'm not sure what this means, since I obviously want to create the queue myInput.group
, and it seems to be complaining it does not exists...我不确定这意味着什么,因为我显然想创建队列
myInput.group
,而且似乎在抱怨它不存在......
I've also checked on this question that my problem could be permissions.我还检查了这个问题,我的问题可能是权限。 But I should have them - otherwise I believe I wouldn't be able to delete the queues...
但是我应该拥有它们 - 否则我相信我将无法删除队列......
Can you guide me to a solution?你能指导我解决问题吗?
The code from my previous question, to help you with the investigation:我上一个问题中的代码,可帮助您进行调查:
@Component
public class HandlerDlq {
private static final Logger LOGGER = LoggerFactory.getLogger(HandlerDlq.class);
private static final String X_RETRIES_HEADER = "x-retries";
private static final String X_DELAY_HEADER = "x-delay";
private static final int NUMBER_OF_RETRIES = 3;
private static final int DELAY_MS = 300000;
private RabbitTemplate rabbitTemplate;
@Autowired
public HandlerDlq(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}
@RabbitListener(queues = MessageInputProcessor.DLQ)
public void rePublish(Message failedMessage) {
Map<String, Object> headers = failedMessage.getMessageProperties().getHeaders();
Integer retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
if (retriesHeader == null) {
retriesHeader = 0;
}
if (retriesHeader > NUMBER_OF_RETRIES) {
LOGGER.warn("Message {} added to failed messages queue", failedMessage);
this.rabbitTemplate.send(MessageInputProcessor.FAILED, failedMessage);
throw new ImmediateAcknowledgeAmqpException("Message failed after " + NUMBER_OF_RETRIES + " attempts");
}
retriesHeader++;
headers.put(X_RETRIES_HEADER, retriesHeader);
headers.put(X_DELAY_HEADER, DELAY_MS * retriesHeader);
LOGGER.warn("Retrying message, {} attempts", retriesHeader);
this.rabbitTemplate.send(MessageInputProcessor.DELAY_EXCHANGE, MessageInputProcessor.INPUT_DESTINATION, failedMessage);
}
@Bean
public DirectExchange delayExchange() {
DirectExchange exchange = new DirectExchange(MessageInputProcessor.DELAY_EXCHANGE);
exchange.setDelayed(true);
return exchange;
}
@Bean
public Binding bindOriginalToDelay() {
return BindingBuilder.bind(new Queue(MessageInputProcessor.INPUT_DESTINATION)).to(delayExchange()).with(MessageInputProcessor.INPUT_DESTINATION);
}
@Bean
public Queue parkingLot() {
return new Queue(MessageInputProcessor.FAILED);
}
}
My MessageInputProcessor
interface:我的
MessageInputProcessor
接口:
public interface MessageInputProcessor {
String INPUT = "myInput";
String INPUT_DESTINATION = "myInput.group";
String DLQ = INPUT_DESTINATION + ".dlq"; //from application.properties file
String FAILED = INPUT + "-failed";
String DELAY_EXCHANGE = INPUT_DESTINATION + "-DlqReRouter";
@Input
SubscribableChannel storageManagerInput();
@Input(MessageInputProcessor.FAILED)
SubscribableChannel storageManagerFailed();
}
And my properties file:还有我的属性文件:
#dlx/dlq setup - retry dead letter 5 minutes later (300000ms later)
spring.cloud.stream.rabbit.bindings.myInput.consumer.auto-bind-dlq=true
spring.cloud.stream.rabbit.bindings.myInput.consumer.republish-to-dlq=true
spring.cloud.stream.rabbit.bindings.myInput.consumer.dlq-ttl=3000
#input
spring.cloud.stream.bindings.myInput.destination=myInput
spring.cloud.stream.bindings.myInput.group=group
EDIT:编辑:
I do have EnableBinding
annotation in another component on the project (and now I've tried to add to the class HandlerDlq, but the error was the same), and I have the log entry:我在项目的另一个组件中有
EnableBinding
注释(现在我已经尝试添加到类 HandlerDlq,但错误是相同的),并且我有日志条目:
2019-12-17 08:45:11.584 INFO 96124 --- [ main] csbrpRabbitExchangeQueueProvisioner : declaring queue for inbound: myInput.group, bound to: myInput
2019-12-17 08:45:11.584 INFO 96124 --- [main] csbrpRabbitExchangeQueueProvisioner:声明入站队列:myInput.group,绑定到:myInput
After that, there is an error message without stacktrace.之后,有一条没有stacktrace的错误信息。 Content below:
内容如下:
{ "written_at":"2019-12-17T14:06:59.263Z","written_ts":460692906701698,"type":"log","logger":"org.springframework.amqp.rabbit.connection.CachingConnectionFactory","thread":"AMQP Connection <ip>:5672","level":"ERROR","categories":[],"msg":"Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=503, reply-text=COMMAND_INVALID - unknown exchange type 'x-delayed-message', class-id=40, method-id=10)","tenant_id":"-","component_type":"application","component_id":"******","space_name":"dev","component_name":"*******","component_instance":"0","organization_id":"****","correlation_id":"-","organization_name":"****","space_id":"*****","container_id":"***","custom_fields":{} }
Do you have @EnableBinding(MessageInputProcessor.class)
on a configuration class?你在配置类上有
@EnableBinding(MessageInputProcessor.class)
吗?
If so check the startup logs;如果是,请检查启动日志; you should see
你应该看到
2019-12-17 08:45:11.584 INFO 96124 --- [ main] csbrpRabbitExchangeQueueProvisioner : declaring queue for inbound: myInput.group, bound to: myInput
2019-12-17 08:45:11.584 INFO 96124 --- [main] csbrpRabbitExchangeQueueProvisioner:声明入站队列:myInput.group,绑定到:myInput
Look for any errors there.在那里寻找任何错误。
If you don't have @EnableBinding
the provisioning is not performed and you will have to manually provision with @Bean
s like your other queue.如果您没有
@EnableBinding
,则不会执行配置,您必须像其他队列一样手动配置@Bean
。
If this "DLQ reprocessing" is a different app to the main stream app, then you should not have @EnableBinding
here, you should properly configure the binding in the main app.如果此“DLQ 重新处理”是与主流应用程序不同的应用程序,那么您不应在此处使用
@EnableBinding
,您应该在主应用程序中正确配置绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.