256.3. 接続ファクトリーの使用
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>
<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>
<camelContext>
<route>
<from uri="direct:rabbitMQEx2"/>
<to uri="rabbitmq:ex2"/>
</route>
</camelContext>