package com.changhong.epc.admin.config; import com.changhong.epc.admin.service.mq.AutoFormConsumer; import com.changhong.epc.constter.base.MQConst; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; import javax.annotation.Resource; //@Configuration public class MQConsumerConfig implements MQConst { @Resource private AutoFormConsumer autoFormConsumer; /** * 创建连接工厂 * @param connectionFactory * @return */ @Bean public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory){ RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addMessageListener(new MessageListenerAdapter(autoFormConsumer) ,new PatternTopic(AUTO_NUMBER)); return container; } }