272.4. 使用连接工厂
要连接到 RabbitMQ,您可以使用登录详细信息设置 ConnectionFactory (与 JMS 相同):
<bean id="rabbitConnectionFactory" class="com.rabbitmq.client.ConnectionFactory">
<property name="host" value="localhost"/>
<property name="port" value="5672"/>
<property name="username" value="camel"/>
<property name="password" value="bugsbunny"/>
</bean>
And then refer to the connection factory in the endpoint uri as shown below:
<camelContext>
<route>
<from uri="direct:rabbitMQEx2"/>
<to uri="rabbitmq:ex2?connectionFactory=#rabbitConnectionFactory"/>
</route>
</camelContext>
默认情况下,Camel 2.21 中会自动探测到 ConnectionFactory,因此您只需执行
<camelContext>
<route>
<from uri="direct:rabbitMQEx2"/>
<to uri="rabbitmq:ex2"/>
</route>
</camelContext>