問(wèn)題描述
根據(jù)我對(duì) rabbit-mq 的(有限)經(jīng)驗(yàn),如果您為尚不存在的隊(duì)列創(chuàng)建新偵聽(tīng)器,則會(huì)自動(dòng)創(chuàng)建隊(duì)列.我正在嘗試將 Spring AMQP 項(xiàng)目與 rabbit-mq 一起使用來(lái)設(shè)置偵聽(tīng)器,但我得到了一個(gè)錯(cuò)誤.這是我的 xml 配置:
In my (limited) experience with rabbit-mq, if you create a new listener for a queue that doesn't exist yet, the queue is automatically created. I'm trying to use the Spring AMQP project with rabbit-mq to set up a listener, and I'm getting an error instead. This is my xml config:
<rabbit:connection-factory id="rabbitConnectionFactory" host="172.16.45.1" username="test" password="password" />
<rabbit:listener-container connection-factory="rabbitConnectionFactory" >
<rabbit:listener ref="testQueueListener" queue-names="test" />
</rabbit:listener-container>
<bean id="testQueueListener" class="com.levelsbeyond.rabbit.TestQueueListener">
</bean>
我在我的 RabbitMq 日志中得到了這個(gè):
I get this in my RabbitMq logs:
=ERROR REPORT==== 3-May-2013::23:17:24 ===
connection <0.1652.0>, channel 1 - soft error:
{amqp_error,not_found,"no queue 'test' in vhost '/'",'queue.declare'}
還有來(lái)自 AMQP 的類(lèi)似錯(cuò)誤:
And a similar error from AMQP:
2013-05-03 23:17:24,059 ERROR [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) - Consumer received fatal exception on startup
org.springframework.amqp.rabbit.listener.FatalListenerStartupException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.
從堆棧跟蹤看來(lái),隊(duì)列是在被動(dòng)"模式下創(chuàng)建的 - 誰(shuí)能指出我將如何創(chuàng)建不使用被動(dòng)模式的隊(duì)列,所以我看不到這個(gè)錯(cuò)誤?還是我錯(cuò)過(guò)了什么?
It would seem from the stack trace that the queue is getting created in a "passive" mode- Can anyone point out how I would create the queue not using the passive mode so I don't see this error? Or am I missing something else?
推薦答案
似乎解決我的問(wèn)題的是添加管理員.這是我的xml:
What seemed to resolve my issue was adding an admin. Here is my xml:
<rabbit:listener-container connection-factory="rabbitConnectionFactory" >
<rabbit:listener ref="orderQueueListener" queues="test.order" />
</rabbit:listener-container>
<rabbit:queue name="test.order"></rabbit:queue>
<rabbit:admin id="amqpAdmin" connection-factory="rabbitConnectionFactory"/>
<bean id="orderQueueListener" class="com.levelsbeyond.rabbit.OrderQueueListener">
</bean>
這篇關(guān)于如何讓 Spring RabbitMQ 創(chuàng)建一個(gè)新隊(duì)列?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!