1. 程式人生 > >RabbitMQ+spring rabbit 配置多vhost

RabbitMQ+spring rabbit 配置多vhost

因為網上以後有了夠多關於RbbitMQ示例說明,我在這裡就不詳細的介紹了。在這裡主要講述一下自己工作是遇到問題,如何配置多個vhost。

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
       xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
       xmlns:context=”http://www.springframework.org/schema/context”
       xmlns:rabbit=”http://www.springframework.org/schema/rabbit”
       xsi:schemaLocation=”
            http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/rabbit
                http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd”>

   <rabbit:connection-factory id=”connectionFactory” host=”192.168.1.1” username=”admin”  password=”admin” port=”5611″ virtual-host=”″/>
   <rabbit:admin  id=”admin1”  connection-factory=”connectionFactory”/>

    <!– spring template宣告 –>
    <rabbit:template exchange=”exchange1” id=”amqpTemplate”  connection-factory=”connectionFactory” />

   <!– queue 佇列宣告–>
   <rabbit:queue id=”queue1” name=”queue1”  durable=”false” auto-delete=”false” exclusive=”false”declared-by=”admin1” />
   
   <!– exchange queue binging key 繫結 –>
    <rabbit:direct-exchange  id=”exchange1”  name=”exchange1” durable=”false” auto-delete=”false” declared-by=”admin1”

 >
        <rabbit:bindings>
            <rabbit:binding queue=”queue1” key=”queue1”/>
        </rabbit:bindings>
    </rabbit:direct-exchange>

 <rabbit:connection-factory id=”connectionFactory2″ host=”192.168.1.1” username=”admin”   password=”admin” port=”5611″ virtual-host=”test″/>
<rabbit:admin  id=”admin2”  connection-factory=”connectionFactory2″/>

   <!– queue 佇列宣告–>
   <rabbit:queue id=”queue2” durable=”false” auto-delete=”false” exclusive=”false” name=”queue2” declared-by=”admin2” />
   
   <!– exchange queue binging key 繫結 –>
    <rabbit:direct-exchange name=”exchange2″ durable=”false” auto-delete=”false” id=”exchange2” declared-by=”admin2” >
        <rabbit:bindings>
            <rabbit:binding queue=”queue2” key=”queue2”/>
        </rabbit:bindings>
    </rabbit:direct-exchange>
    

    <!– spring template宣告 –>
    <rabbit:template exchange=”exchange2” id=”amqpTemplate2”  connection-factory=”connectionFactory2″ />

</beans>

需要注意必須使用http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd,還有declared-by這個屬性。