.创建redis监听的设置类

//初始化监听器
    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
            MessageListenerAdapter listenerAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(listenerAdapter, new PatternTopic("这里是监听的通道的名字"));        return container;
    }
   //利用反射来创建监听到消息之后的执行方法
    @Bean
    MessageListenerAdapter listenerAdapter(RedisReceiver redisReceiver) {        return new MessageListenerAdapter(redisReceiver, "receiveMessage");
    }

2.创建监听之后的receiver方法类

@Service

public class RedisReceiver {

    @Autowired

    RedisService redisService;


    public void receiveMessage(String message) {

        //这里是收到通道的消息之后执行的方法

    }

}