
package com.tmerclub.cloud.seckill.config;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqAdapter;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author tmerclub
 * @date 2021/3/30
 */
@RefreshScope
@Configuration
public class RocketMqConfig {

    @Autowired
    private RocketMqAdapter rocketMqAdapter;

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate seckillOrderCreateTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SECKILL_ORDER_CREATE_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate seckillOrderTimeOutCancelTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SECKILL_ORDER_TIME_OUT_CANCEL_TOPIC);
    }
    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendActivityOfflineNotifyToShopTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SEND_ACTIVITY_OFFLINE_NOTIFY_TO_SHOP_TOPIC);
    }
    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendActivityAuditNotifyToShopTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SEND_ACTIVITY_AUDIT_NOTIFY_TO_SHOP_TOPIC);
    }
    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate outStockLogTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.OUT_STOCK_LOG_TOPIC);
    }
}
