<?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:rabbit="http://www.springframework.org/schema/rabbit"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/rabbit
     http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd">
    <!--配置connection-factory，指定连接rabbit server参数 -->
    <rabbit:connection-factory id="connectionFactory" virtual-host="/"
                               username="admin" password="admin123" host="192.168.5.123" port="5672"
    />
    <!-- <rabbit:connection-factory id="connectionFactory"
         username="test2" password="test2"
        host="123.206.228.200" port="5672" /> -->

    <!--通过指定下面的admin信息，当前producer中的exchange和queue会在rabbitmq服务器上自动生成 -->
    <rabbit:admin id="connectAdmin" connection-factory="connectionFactory" />

    <!--定义queue -->
    <rabbit:queue name="queueTest" durable="true" auto-delete="false"
                  exclusive="false" declared-by="connectAdmin" />

    <!-- 定义direct exchange，绑定queueTest -->
    <rabbit:direct-exchange name="exchangeTest"
                            durable="true" auto-delete="false" declared-by="connectAdmin">
        <rabbit:bindings>
            <rabbit:binding queue="queueTest" key="queueTestKey"></rabbit:binding>
        </rabbit:bindings>
    </rabbit:direct-exchange>

    <!--定义rabbit template用于数据的接收和发送 -->
    <rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
                     exchange="exchangeTest" />

    <!-- 消息接收者 -->
    <bean id="messageReceiver" class="com.test.MessageConsumer"></bean>

    <!-- queue litener 观察 监听模式 当有消息到达时会通知监听在对应的队列上的监听对象 -->
    <rabbit:listener-container
            connection-factory="connectionFactory">
        <rabbit:listener queues="queueTest" ref="messageReceiver" />
    </rabbit:listener-container>

    <!--定义queue -->
    <rabbit:queue name="queueChris" durable="true"
                  auto-delete="false" exclusive="false" declared-by="connectAdmin" />

    <!-- 定义direct exchange，绑定queueTest -->
    <rabbit:direct-exchange name="exchangeTest"
                            durable="true" auto-delete="false" declared-by="connectAdmin">
        <rabbit:bindings>
            <rabbit:binding queue="queueChris" key="queueTestChris"></rabbit:binding>
        </rabbit:bindings>
    </rabbit:direct-exchange>

    <!-- 消息接收者 -->
    <bean id="receiverChris" class="com.test.ChrisConsumer"></bean>

    <!-- queue litener 观察 监听模式 当有消息到达时会通知监听在对应的队列上的监听对象 -->
    <rabbit:listener-container
            connection-factory="connectionFactory">
        <rabbit:listener queues="queueChris" ref="receiverChris" />
    </rabbit:listener-container>

    <!-- 分隔线 -->
    <!--配置connection-factory，指定连接rabbit server参数 -->
    <rabbit:connection-factory id="connectionFactory2" virtual-host="vhostSJJ"
                               username="shijunjie" password="wssjj123" host="123.206.228.200" port="5672" />

    <!--通过指定下面的admin信息，当前producer中的exchange和queue会在rabbitmq服务器上自动生成 -->
    <rabbit:admin id="connectAdmin2" connection-factory="connectionFactory2" />

    <!--定义queue -->
    <rabbit:queue name="queueShijj" durable="true"
                  auto-delete="false" exclusive="false" declared-by="connectAdmin2" />

    <!-- 定义direct exchange，绑定queueTest -->
    <rabbit:topic-exchange name="exchangeTest2"
                           durable="true" auto-delete="false" declared-by="connectAdmin2">
        <rabbit:bindings>
            <rabbit:binding queue="queueShijj" pattern="shijj.#"></rabbit:binding>
        </rabbit:bindings>
    </rabbit:topic-exchange>

    <!--定义rabbit template用于数据的接收和发送 -->
    <rabbit:template id="amqpTemplate2" connection-factory="connectionFactory2"
                     exchange="exchangeTest2" />

    <!-- 消息接收者 -->
    <bean id="recieverShijj" class="com.test.ShijjConsumer"></bean>

    <!-- queue litener 观察 监听模式 当有消息到达时会通知监听在对应的队列上的监听对象 -->
    <rabbit:listener-container
            connection-factory="connectionFactory2">
        <rabbit:listener queues="queueShijj" ref="recieverShijj" />
    </rabbit:listener-container>
</beans>