ScheduleJob.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.fdkankan.contro.schedule;
  2. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  3. import com.fdkankan.rubbersheeting.ScalingService;
  4. import lombok.extern.log4j.Log4j2;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. @Log4j2
  10. @Component
  11. public class ScheduleJob {
  12. @Value("${rocketmq.autoScaling.num.normal}")
  13. private String baseNum;
  14. @Autowired
  15. private RabbitMqProducer rabbitMqProducer;
  16. @Autowired
  17. private ScalingService scalingService;
  18. @Value("${queue.modeling.modeling-call}")
  19. private String queueModelingCall;
  20. @Scheduled(cron = "${rocketmq.autoScaling.corn:0 0/5 8-21 * * ?}")
  21. public void job8() {
  22. try {
  23. //当mq排队数大于指定数量时使用弹性升缩
  24. int mqNum = rabbitMqProducer.getMessageCount(queueModelingCall);
  25. log.info("每5分钟查询一次排队队列,mqNum:" + mqNum);
  26. if(mqNum - Integer.parseInt(baseNum) > 0){
  27. log.info("使用弹性升缩开启一台ECS");
  28. log.info(scalingService.createEcs());
  29. }
  30. } catch (Exception e) {
  31. log.error("弹性升缩开启失败!", e);
  32. log.error(e.getMessage());
  33. }
  34. }
  35. }