schedule定时任务调整,fallback熔断机制改为factory模式

yun-zuoyi
alwaysfrin 6 years ago
parent 89242cb04d
commit 0a857b8857

@ -46,7 +46,7 @@ public class DemoCloudController {
@GetMapping(value="/test")
@ApiOperation(value="core测试",notes = "core测试")
public BaseResultBean testCore(String test) {
LOGGER.info("{}{}【impp-core接受数据】{}",ipAddress,serverPort,test);
LOGGER.info("iWmsDemoCloud:{},ip:{},port:{}【impp-core接受数据】{}",iWmsDemoCloud,ipAddress,serverPort,test);
//return ResultBean.success("返回:" + test).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
return BaseResultBean.buildBaseResultBean(true,"");
}
@ -54,7 +54,7 @@ public class DemoCloudController {
@GetMapping(value="/test-wms")
@ApiOperation(value="wms测试",notes = "wms测试")
public ResultBean testWms(String test) {
LOGGER.info("【{}{}impp-core接受数据 -> wms】{}",ipAddress,serverPort,test);
LOGGER.info("iWmsDemoCloud:{},ip:{},port:{}【impp-core接受数据】{}",iWmsDemoCloud,ipAddress,serverPort,test);
BaseResultBean result = iWmsDemoCloud.testWms(test);
if(result.isSuccess()){

@ -1,6 +1,8 @@
package cn.estsh.i3plus.core.apiservice.controller;
import cn.estsh.i3plus.icloud.wms.sdk.IWmsScheduleJobCloud;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.quartz.ScheduleTool;
@ -33,74 +35,123 @@ public class DemoScheduleController extends CoreBaseController{
@Autowired
private ScheduleTool scheduleTool;
@Autowired
private IWmsScheduleJobCloud wmsScheduleJobCloud;
@GetMapping(value="/list-task")
@ApiOperation(value="查询定时任务",notes="查询所有定时任务")
public ResultBean listTask(){
List<TaskInfo> taskList = scheduleTool.queryJobList();
public ResultBean listTask(int sourceType){
List<TaskInfo> taskList = null;
if(sourceType == 1) {
//本地任务
taskList = ScheduleTool.queryJobList(scheduleTool.getScheduler());
if(taskList != null) {
for (TaskInfo ti : taskList) {
LOGGER.info("任务:{}",ti);
}
}else{
LOGGER.info("任务列表为空");
}
}else if(sourceType == 2){
//wms任务
BaseResultBean<TaskInfo> baseResult = wmsScheduleJobCloud.listTask();
LOGGER.info("任务数量:{}",baseResult.getResultList().size());
taskList = baseResult.getResultList();
if (taskList != null) {
for (TaskInfo ti : taskList) {
System.out.println(ti);
LOGGER.info("任务:{}",ti);
}
} else {
LOGGER.info("任务列表为空");
}
}
return new ResultBean(true,"");
return new ResultBean(true,taskList);
}
@GetMapping(value="/add-task")
@ApiOperation(value="添加定时任务",notes="添加定时任务")
public ResultBean addTask(String packageName,String className,String jobName,String jobGroup,String cronExpression){
//String packageName = "cn.estsh.impp.framework.boot.quartz.job";
//String className = "ImppJob";
public ResultBean addTask(int sourceType,
String packageName,String className,String jobName,String jobGroup,String cronExpression){
if(sourceType == 1) {
scheduleTool.addJob(new TaskInfo(packageName,className,jobName,jobGroup,cronExpression,"测试任务"));
}else if(sourceType == 2){
wmsScheduleJobCloud.addTask(packageName,className,jobName,jobGroup,cronExpression,"wms新任务");
}
return new ResultBean(true,"");
}
@GetMapping(value="/delete-task")
@ApiOperation(value="删除定时任务",notes="删除定时任务")
public ResultBean deleteTask(String jobName,String jobGroup){
public ResultBean deleteTask(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.deleteJob(jobName,jobGroup);
}else if(sourceType == 2){
wmsScheduleJobCloud.deleteTask(jobName,jobGroup);
}
return new ResultBean(true,"");
return new ResultBean(true);
}
@GetMapping(value="/pause-task")
@ApiOperation(value="暂停定时任务",notes="暂停定时任务")
public ResultBean pauseJob(String jobName,String jobGroup){
public ResultBean pauseJob(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.pauseJob(jobName,jobGroup);
}else if(sourceType == 2){
wmsScheduleJobCloud.pauseJob(jobName,jobGroup);
}
return new ResultBean(true,"");
return new ResultBean(true);
}
@GetMapping(value="/resume-task")
@ApiOperation(value="继续定时任务",notes="继续定时任务")
public ResultBean resumeJob(String jobName,String jobGroup){
public ResultBean resumeJob(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.resumeJob(jobName,jobGroup);
}else if(sourceType == 2){
wmsScheduleJobCloud.resumeJob(jobName,jobGroup);
}
return new ResultBean(true,"");
return new ResultBean(true);
}
@GetMapping(value="/exceute-task")
@ApiOperation(value="立即执行定时任务",notes="立即执行定时任务")
public ResultBean excuteJob(String jobName,String jobGroup){
public ResultBean excuteJob(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.executeJob(jobName,jobGroup);
}else if(sourceType == 2){
wmsScheduleJobCloud.excuteJob(jobName,jobGroup);
}
return new ResultBean(true,"");
return new ResultBean(true);
}
@GetMapping(value="/stand-by-schedule")
@ApiOperation(value="定时器待机",notes="定时器待机")
public ResultBean restartJob(String jobName,String jobGroup){
public ResultBean restartJob(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.standBySchedule();
}else if(sourceType == 2){
wmsScheduleJobCloud.standBySchedule();
}
return new ResultBean(true,"");
return new ResultBean(true);
}
@GetMapping(value="/start-schedule")
@ApiOperation(value="启动定时器",notes="启动定时器")
public ResultBean startSchedule(String jobName,String jobGroup){
public ResultBean startSchedule(int sourceType,String jobName,String jobGroup){
if(sourceType == 1) {
scheduleTool.startSchedule();
}else if(sourceType == 2){
wmsScheduleJobCloud.startSchedule();
}
return new ResultBean(true,"");
return new ResultBean(true);
}
}

@ -63,4 +63,12 @@ public class I3CoreQueueConfig {
//LOGGER.info("【DEMO_RETURN_QUEUE队列】");
return new Queue(DEMO_RETURN_QUEUE);
}
//测试wms微服队列
public static final String DEMO_CLOUD_WMS = "DEMO_CLOUD_WMS";
@Bean
public Queue getDemoCloudWmsQueue() throws Exception {
//LOGGER.info("【DEMO_CLOUD_WMS】");
return new Queue(DEMO_CLOUD_WMS);
}
}

@ -1,10 +1,13 @@
package cn.estsh.i3plus.core.apiservice.mq;
import cn.estsh.i3plus.icloud.wms.sdk.IWmsDemoCloud;
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
import cn.estsh.i3plus.pojo.platform.bean.SysMessage;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
@ -20,6 +23,9 @@ import java.io.IOException;
public class I3CoreQueueReceiver {
private static final Logger LOGGER = LoggerFactory.getLogger(I3CoreQueueReceiver.class);
@Autowired
IWmsDemoCloud iWmsDemoCloud;
/**
*
* @param msg
@ -46,6 +52,34 @@ public class I3CoreQueueReceiver {
}
}
/**
*
* @param msg
* @param channel
* @param message
* rabbitTemplate.convertAndSend(I3CoreQueueConfig.IMPP_MESSAGE_QUEUE, new SysMessage(....));
*/
@RabbitListener(queues = I3CoreQueueConfig.DEMO_CLOUD_WMS)
public void processCloud(String msg, Channel channel, Message message) {
try {
LOGGER.info("【MQ-DEMO_CLOUD_WMS】数据接收成功{}",msg);
BaseResultBean result = iWmsDemoCloud.testWms(msg);
LOGGER.info("微服返回结果:{}",result);
//信息已处理
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
} catch (IOException e) {
LOGGER.error("【MQ-DEMO_CLOUD_WMS】处理出错{}",e.getMessage(),e);
//丢弃这条消息
try {
// 未成功处理,重新发送
channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
/********************* 消息队列处理demo *******************/

@ -0,0 +1,29 @@
package cn.estsh.i3plus.core.apiservice.schedulejob;
import cn.estsh.impp.framework.base.schedule.BaseImppScheduleJob;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import io.swagger.annotations.ApiOperation;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @Description :
* @Reference :
* @Author : alwaysfrin
* @CreateDate : 2019-03-12 17:51
* @Modify:
**/
@ApiOperation("测试微服定时任务demo")
public class DemoCloudJob extends BaseImppScheduleJob {
public static final Logger LOGGER = LoggerFactory.getLogger(DemoJob.class);
public DemoCloudJob() {
super(DemoJob.class,"测试微服定时任务demo");
}
@Override
public void executeImppJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
System.out.println("==============测试微服定时任务demo===========");
}
}

@ -24,13 +24,9 @@ public class WmsDualTransStockJob extends BaseImppScheduleJob {
super(WmsDualTransStockJob.class,"定时处理库存移动单信息");
}
@Autowired
private IWmsScheduleJobCloud scheduleJobCloud;
@Override
public void executeImppJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
System.out.println("定时任务被执行");
LOGGER.info("projectName{},port:{}",applicationProperties.getApplicationName(),applicationProperties.getServerPort());
scheduleJobCloud.dualMovementJob();
}
}

@ -1,8 +1,11 @@
package cn.estsh.i3plus.core.apiservice.websocket;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.Random;
/**
* @Description :
* @Reference :
@ -16,5 +19,38 @@ public class TestMain {
System.out.println(RandomStringUtils.random(15, true, false));
// StringEscapeUtils.escapeHtml();
/*long workerIdBits = 5L;
long maxWorkerId = -1L ^ (-1L << workerIdBits);
System.out.println("5 --> "+maxWorkerId);
workerIdBits = 6L;
maxWorkerId = -1L ^ (-1L << workerIdBits);
System.out.println("6 --> "+maxWorkerId);
workerIdBits = 8L;
maxWorkerId = -1L ^ (-1L << workerIdBits);
System.out.println("8 --> " + maxWorkerId);*/
int wId = new Random().nextInt(29) + 1;
System.out.println("random id -> "+wId);
SnowflakeIdMaker m = new SnowflakeIdMaker(wId,3);
m = new SnowflakeIdMaker(wId,3);
int i = 0;
long id;
int c = 0;
long l1 = System.currentTimeMillis();
while(i < 1000){
if(m.nextId() < 0) {
System.out.println("======="+m.nextId());
c++;
}else{
//System.out.println(m.nextId());
}
i++;
}
System.out.println("耗时:" + (System.currentTimeMillis()-l1));
System.out.println("====end====error:" + c);
}
}

Loading…
Cancel
Save