如何让Spring RabbitMQ创建一个新的队列?
根据我对Rabbit-mq的(有限的)经验,如果您为尚不存在的队列创建新的侦听器,则会自动创建该队列。我试图将Spring AMQP项目与rabbit-
mq一起使用来设置侦听器,但是却出现错误。这是我的xml配置:
<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日志中得到了这个:
=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'}
还有来自AMQP的类似错误:
2013-05-03 23:17:24,059 ERROR [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) - Consumer received fatal exception on startuporg.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.
从堆栈跟踪中可以看出,队列是在“被动”模式下创建的-任何人都可以指出我如何不使用被动模式来创建队列,这样我就不会看到此错误?还是我想念其他东西?
回答:
解决我问题的方法似乎是添加一个管理员。这是我的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>
以上是 如何让Spring RabbitMQ创建一个新的队列? 的全部内容, 来源链接: utcz.com/qa/407470.html