多线程消息监听容器配置[ 消费者spring-kafka配置文件]
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 http://www.springframework.org/schema/beans/spring-beans.xsd"> 6 7 8 <bean id="consumerProperties" class="java.util.HashMap"> 9 <constructor-arg> 10 <map> 11 <entry key="bootstrap.servers" value="${bootstrap.servers}"/> 12 <!-- 指定消费组名 --> 13 <entry key="group.id" value="friend-group"/> 14 <entry key="enable.auto.commit" value="true"/> 15 <entry key="auto.commit.interval.ms" value="1000"/> 16 <entry key="session.timeout.ms" value="15000"/> 17 <entry key="max.poll.records" value="1"/> 18 <entry key="key.deserializer" value="org.apache.kafka.common.serialization.IntegerDeserializer"/> 19 <!--<entry key="key.deserializer" value="org.apache.kafka.common.serialization.StringDeserializer"/>--> 20 <entry key="value.deserializer" value="org.apache.kafka.common.serialization.StringDeserializer"/> 21 </map> 22 </constructor-arg> 23 </bean> 24 25 <bean id="consumerFactory" class="org.springframework.kafka.core.DefaultKafkaConsumerFactory"> 26 <constructor-arg> 27 <ref bean="consumerProperties"/> 28 </constructor-arg> 29 </bean> 30 31 <!-- 消费消息的服务类 --> 32 <bean id="messageListernerConsumerService" class="com.zhaopin.consumer.ConsumerService"/> 33 34 <!-- 消费者容器配置信息 --> 35 <bean id="containerProperties" class="org.springframework.kafka.listener.config.ContainerProperties"> 36 <constructor-arg value="friend"/> 37 <!--<constructor-arg> 38 <list> 39 <value>zptopic</value> 40 <value>ssmk</value> 41 <value>friend</value> 42 </list> 43 </constructor-arg>--> 44 <property name="messageListener" ref="messageListernerConsumerService"/> 45 </bean> 46 47 <!-- 单线程消息监听容器 --> 48 <!--<bean id="messageListenerContainer" class="org.springframework.kafka.listener.KafkaMessageListenerContainer" init-method="doStart"> 49 <constructor-arg ref="consumerFactory"/> 50 <constructor-arg ref="containerProperties"/> 51 </bean>--> 52 53 <!-- 多线程消息监听容器 --> 54 <bean id="messageListenerContainer" class="org.springframework.kafka.listener.ConcurrentMessageListenerContainer" init-method="doStart"> 55 <constructor-arg ref="consumerFactory"/> 56 <constructor-arg ref="containerProperties"/> 57 <property name="concurrency" value="5"/> 58 </bean> 59 60 </beans>