package com.ruoyi.web.controller.common;

import com.alicom.mns.tools.DefaultAlicomMessagePuller;
import com.ruoyi.system.service.AlicomMessageListenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**上行短信监听启动
 * @author tjf
 * @Date: 2021/12/28/10:04
 */
@Component
public class AliMnsApplicationRunner implements ApplicationRunner {//启动项目即启动监听

    @Value("${sms_aliyun_accessKeyId}")
    String accessKeyId;// accessKeyId
    @Value("${sms_aliyun_accessKeySecret}")
    String accessKeySecret;// accessKeySecret
    @Value("${sms_aliyun_smsUpQueueName}")
    String smsUpQueueName;// accessKeySecret

    @Autowired
    private AlicomMessageListenterService alicomMessageListenerService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        DefaultAlicomMessagePuller puller=new DefaultAlicomMessagePuller();
        System.out.println("开启短信监听线程池");
        //设置异步线程池大小及任务队列的大小，还有无数据线程休眠时间
        puller.setConsumeMinThreadSize(6);
        puller.setConsumeMaxThreadSize(16);
        puller.setThreadQueueSize(200);
        puller.setPullMsgThreadSize(1);
        //和服务端联调问题时开启，平时无需开启，消耗性能
        puller.openDebugLog(false);
        String messageType="SmsUp";
        if(alicomMessageListenerService!=null){
            puller.startReceiveMsg(accessKeyId,accessKeySecret ,messageType,smsUpQueueName, alicomMessageListenerService);
        }
    }
}
