package com.fdkankan.contro.schedule; import com.fdkankan.rabbitmq.util.RabbitMqProducer; import com.fdkankan.rubbersheeting.ScalingService; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Log4j2 @Component public class ScheduleJob { @Value("${rocketmq.autoScaling.num.normal}") private String baseNum; @Autowired private RabbitMqProducer rabbitMqProducer; @Autowired private ScalingService scalingService; @Value("${queue.modeling.modeling-call}") private String queueModelingCall; @Scheduled(cron = "${rocketmq.autoScaling.corn:0 0/5 8-21 * * ?}") public void job8() { try { //当mq排队数大于指定数量时使用弹性升缩 int mqNum = rabbitMqProducer.getMessageCount(queueModelingCall); log.info("每5分钟查询一次排队队列,mqNum:" + mqNum); if(mqNum - Integer.parseInt(baseNum) > 0){ log.info("使用弹性升缩开启一台ECS"); log.info(scalingService.createEcs()); } } catch (Exception e) { log.error("弹性升缩开启失败!", e); log.error(e.getMessage()); } } }