解決RabbitMq queue異常導(dǎo)致consumer停止問(wèn)題
RabbitMq queue異常導(dǎo)致consumer停止
偶發(fā)性rabbitmq出問(wèn)題或者認(rèn)為操作錯(cuò)誤,訪(fǎng)問(wèn)不了queue,導(dǎo)致消費(fèi)端停止消費(fèi)
org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:599)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[s.message.like.add]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)
... 2 common frames omitted
Caused by: java.io.IOException: null
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.ChannelN.queueDeclarePassive(ChannelN.java:50)
at sun.reflect.GeneratedMethodAccessor711.invoke(Unknown Source)
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.$Proxy231.queueDeclarePassive(Unknown Source)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)
... 3 common frames omitted
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - failed to perform operation on queue 'q.hell' in vhost '/' due to timeout, 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)
... 11 common frames omitted
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - failed to perform operation on queue 's.message.like.add' in vhost '/' due to timeout, 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 common frames omitted
Stopping container from aborted consumer
跟蹤
SimpleMessageListenerContainer
catch (QueuesNotAvailableException ex) {
logger.error("Consumer received fatal=" + SimpleMessageListenerContainer.this.mismatchedQueuesFatal
+ " exception on startup", ex);
if (SimpleMessageListenerContainer.this.missingQueuesFatal) {
logger.error("Consumer received fatal exception on startup", ex);
this.startupException = ex;
// Fatal, but no point re-throwing, so just abort.
aborted = true;
}
publishConsumerFailedEvent("Consumer queue(s) not available", aborted, ex);
}SimpleMessageListenerContainer.this.missingQueuesFatal = true 將aborted
查代碼跟蹤,如下配置設(shè)置
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitConfiguration {
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer,
ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
//Whether to fail if the queues declared by the container are not available on the broker and/or whether to stop the container if one or more queues are deleted at runtime.
factory.setMissingQueuesFatal(false);
configurer.configure(factory, connectionFactory);
return factory;
}
}至此涉及queue訪(fǎng)問(wèn)失敗場(chǎng)景 會(huì)一直重試 直到可用,默認(rèn)5次
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- spring AMQP代碼生成rabbitmq的exchange and queue教程
- PHP使用enqueue/amqp-lib實(shí)現(xiàn)rabbitmq任務(wù)處理
- RabbitMQ排他性隊(duì)列Exclusive Queue詳解
- RabbitMQ中的channel信道、exchange交換機(jī)和queue隊(duì)列詳解
- RabbitMQ實(shí)現(xiàn)Work Queue工作隊(duì)列的示例詳解
- 詳解rabbitmq創(chuàng)建queue時(shí)arguments參數(shù)注釋
- 在RabbitMQ中實(shí)現(xiàn)Work queues工作隊(duì)列模式
相關(guān)文章
SpringBoot連接Hive實(shí)現(xiàn)自助取數(shù)的示例
這篇文章主要介紹了SpringBoot連接Hive實(shí)現(xiàn)自助取數(shù)的示例,幫助大家更好的理解和使用springboot框架,感興趣的朋友可以了解下2020-12-12
Java實(shí)現(xiàn)ArrayList自動(dòng)擴(kuò)容
ArrayList的擴(kuò)容規(guī)則是非常簡(jiǎn)單的,它會(huì)根據(jù)需要自動(dòng)擴(kuò)容,本文就來(lái)介紹一下Java實(shí)現(xiàn)ArrayList自動(dòng)擴(kuò)容,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
解決Java中的java.io.IOException: Broken pipe問(wèn)題
這篇文章主要介紹了解決Java中 java.io.IOException: Broken pipe的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
淺談Java繼承中的轉(zhuǎn)型及其內(nèi)存分配
這篇文章主要介紹了淺談Java繼承中的轉(zhuǎn)型及其內(nèi)存分配,首先分享了簡(jiǎn)單的代碼及運(yùn)行結(jié)果,然后對(duì)其進(jìn)行分析,繼而引出了2017-11-11
Java語(yǔ)言----三種循環(huán)語(yǔ)句的區(qū)別介紹
下面小編就為大家?guī)?lái)一篇Java語(yǔ)言----三種循環(huán)語(yǔ)句的區(qū)別介紹。小編舉得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
JavaScript中棧和隊(duì)列應(yīng)用詳情
這篇文章主要介紹了JavaScript中棧和隊(duì)列應(yīng)用詳情,棧如果用數(shù)組模擬的話(huà)是類(lèi)似于一個(gè)U形桶狀堆??臻g,文章圍繞制圖展開(kāi)詳細(xì)的內(nèi)容展開(kāi)更多相關(guān)內(nèi)容,需要的小伙伴可以參考一下2022-06-06
Spring mvc Controller和RestFul原理解析
這篇文章主要介紹了Spring mvc Controller和RestFul原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
spring boot 測(cè)試單元修改數(shù)據(jù)庫(kù)不成功的解決
這篇文章主要介紹了spring boot 測(cè)試單元修改數(shù)據(jù)庫(kù)不成功的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09

