因为网上以后有了够多关于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这个属性。
主要还是需要看官网的文档http://docs.spring.io/spring-amqp/reference/htmlsingle/#_with_xml_configuration
