137.7. 使用连接工厂
若要连接到 RabbitMQ,您必须使用如下登录详细信息设置 ConnectionFactory
(与 JMS 相同)。
建议您使用来自 spring-rabbit 的 cache ConnectionFactory
,因为它附带了连接池。
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"> <property name="uri" value="amqp://lolcalhost:5672"/> </bean>
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<property name="uri" value="amqp://lolcalhost:5672"/>
</bean>
ConnectionFactory
默认自动探测到,因此您只需执行它即可。
<camelContext> <route> <from uri="direct:cheese"/> <to uri="spring-rabbitmq:foo?routingKey=cheese"/> </route> </camelContext>
<camelContext>
<route>
<from uri="direct:cheese"/>
<to uri="spring-rabbitmq:foo?routingKey=cheese"/>
</route>
</camelContext>