RabbitMQ在通过camel连接时设置队列参数

时间:2017-12-08 13:15:20

标签: rabbitmq apache-camel javabeans amqp endpoint

我正在尝试使用apache-camel配置连接到服务器中的RabbitMQ队列。

使用durable字段falseauto-delete字段true创建队列时,它可以正常工作。但是当其中任何一个都没有时,它们都不起作用。

applicationContext.xml文件看起来像这样 -

<bean id="customConnectionFactory" class="com.rabbitmq.client.ConnectionFactory">
    <property name="host" value="localhost" />
    <property name="port" value="5672" />
    <property name="username" value="guest" />
    <property name="password" value="guest" />
    <property name="virtualHost" value="Test" /> 
</bean>

<bean id="testBean" class="test.TestBean" />

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from
            uri="rabbitmq://localhost:5672/ex1?connectionFactory=#customConnectionFactory&amp;queue=Q1&amp;autoDelete=true&amp;durable=true" />
        <to uri="bean:testBean?method=hello" />  <!-- This method consumes and prints the message -->
    </route>
</camelContext>

在这里,我需要为队列autoDelete 而不是交换durable指定属性Q1ex1。 (我已经在URI中指定了交换)

错误是 -

Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'auto_delete' for queue 'Q1' in vhost 'Test': received 'true' but current is 'false', class-id=50, method-id=10)

此处 reply-code = 406 表示队列/交换的参数与实际配置不匹配。这是因为这里有队列属性。

由于我无法访问远程队列,因此无法更改队列的属性。 (我在这里说的例子是localhost)

注意:我要求仅使用spring bean执行此操作。

0 个答案:

没有答案
相关问题