package com.qiaoba.common.database.config;

import com.qiaoba.common.database.listener.SwitchPrimaryListener;
import com.qiaoba.common.redis.manager.RedisChannelManager;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * DatasourceRedisMessageConfig
 *
 * @author ailanyin
 * @version 1.0
 * @since 2023/7/17 10:38
 */
@Configuration
@RequiredArgsConstructor
public class DatasourceRedisMessageConfig {

    private final RedisChannelManager redisChannelManager;

    @Bean
    public SwitchPrimaryListener switchPrimaryListener() {
        SwitchPrimaryListener switchPrimaryListener = new SwitchPrimaryListener();
        redisChannelManager.addChannelListener("test", switchPrimaryListener);
        return switchPrimaryListener;
    }
}
