package com.chushang.common.canal.config;


import com.chushang.common.canal.client.SimpleCanalClient;
import com.chushang.common.canal.client.transfer.MessageTransponders;
import com.chushang.common.canal.util.BeanUtil;
import com.chushang.common.canal.client.CanalClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;


public class CanalClientAutoConfiguration {

    private final static Logger logger = LoggerFactory.getLogger(CanalClientAutoConfiguration.class);

    @Autowired
    private CanalConfig canalConfig;

    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public BeanUtil beanUtil() {
        return new BeanUtil();
    }

    @Bean
    private CanalClient canalClient() {

        CanalClient canalClient =
                new SimpleCanalClient(canalConfig, MessageTransponders.defaultMessageTransponder());

        canalClient.start();

        logger.info("Starting canal client....");

        return canalClient;
    }


}
