package com.copy.trade.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import com.copy.trade.consumer.MarketListener;


@Configuration
public class RedisConfig {

	@Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory factory,
                                                   MarketListener listener
    ) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(factory);
        //订阅频道redis.news 和 redis.life  这个container 可以添加多个 messageListener
        container.addMessageListener(listener, new ChannelTopic("market-contract"));
        return container;
    }
	
	 @Bean
	 public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
	      RedisTemplate<String,Object> redisTemplate = new RedisTemplate<String,Object>();
	      redisTemplate.setConnectionFactory(redisConnectionFactory);
	      return redisTemplate;
	 }
}
