package com.bizzan.bitrade.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.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import com.bizzan.bitrade.consumer.MarketListener;
import com.bizzan.bitrade.consumer.SpotListener;

@Configuration
public class RedisConfig {

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