spring-amqp 整合rabbitmq生产者配置与代码

<?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.0.xsd">
 
     
   <!-- 连接服务配置  -->
   <rabbit:connection-factory id="mqConnectionFactory" host="localhost" username="guest"
        password="guest" port="5672"  />
         
   <rabbit:admin connection-factory="mqConnectionFactory"/>
    
   <!-- queue 队列声明-->
   <rabbit:queue id="queue_one" durable="true" auto-delete="false" exclusive="false" name="queue_one"/>
    
   <!-- exchange queue binging key 绑定 -->
    <rabbit:direct-exchange name="my-mq-exchange" durable="true" auto-delete="false" id="my-mq-exchange">
        <rabbit:bindings>
            <rabbit:binding queue="queue_one" key="queue_one_key"/>
        </rabbit:bindings>
    </rabbit:direct-exchange>
     <!-- 声明消息转换器为SimpleMessageConverter -->
	<bean id="mqMessageConverter"
		class="org.springframework.amqp.support.converter.SimpleMessageConverter">
	</bean>
    <!-- spring template声明-->
    <rabbit:template exchange="my-mq-exchange" id="amqpTemplate" routing-key= "queue_one_key" queue="queue_one"  connection-factory="mqConnectionFactory" message-converter="mqMessageConverter" />
</beans>

使用:直接在service层进行@Autowired template就可以了

你可能感兴趣的:(spring-amqp 整合rabbitmq生产者配置与代码)