<?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"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/rabbit https://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<context:property-placeholder location="classpath:profile.dev.properties" ignore-unresolvable="true" />
<context:component-scan base-package="com.test.rabbitmq.listener" />
<!-- spring amqp默认的是jackson 的一个插件,目的将生产者生产的数据转换为json存入消息队列 -->
<!-- <bean id="jsonMessageConverter" class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter"/> -->
<!-- 创建connectionFactory -->
<!-- org.springframework.amqp.rabbit.connection.CachingConnectionFactory -->
<task:executor id="mqExecutor" pool-size="20-100" keep-alive="600" queue-capacity="2000" rejection-policy="CALLER_RUNS" />
<rabbit:connection-factory id="connectionFactory"
host="${rabbit.host}"
port="${rabbit.port}"
username="${rabbit.username}"
password="${rabbit.password}"
channel-cache-size="1000"
executor="mqExecutor"/>
<!-- org.springframework.amqp.rabbit.core.RabbitAdmin -->
<rabbit:admin connection-factory="connectionFactory" auto-startup="true" ignore-declaration-exceptions="true"/>
<!-- 声明MQ队列 -->
<rabbit:queue id="queueName" name="queueName" durable="true" auto-delete="false" exclusive="false" />
<task:annotation-driven scheduler="myScheduler"/>
<task:scheduler id="myScheduler" pool-size="8" />
<bean id="simpleMessageConverter"
class="org.springframework.amqp.support.converter.SimpleMessageConverter">
<property name="createMessageIds" value="true" />
</bean>
<!-- MQ消费者监听容器 -->
<bean id="receiveMessageListener" class="com.test.rabbitmq.listener.RabbitMQMessageListener"/>
<rabbit:listener-container connection-factory="connectionFactory" acknowledge="auto" requeue-rejected="false"
concurrency="20" message-converter="simpleMessageConverter" >
<rabbit:listener ref="receiveMessageListener" method="onMessage" queues="queueName" />
</rabbit:listener-container>
</beans>