spring配置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"
	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>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值