【发布时间】:2019-03-18 12:59:16
【问题描述】:
我们使用下面的 api 执行运行 API 来下载组文件: curl -X POST localhost:port/manager/createTask 休息 API:(经理)
@RestController
@RequestMapping("/manager")
public class ClusterResource {
@Autowired
private MyService myService;
@PostMapping("/createTask")
@ResponseBody
public ResponseEntity doTasks() throws Exception {
myService.doTask();
return new ResponseEntity<>(HttpStatus.OK);
}
}
MyService 类:
@Service
public class MyService
private String templateFileName = "example";
@Autowired
private DownloadService downloadService;
@Async
public ResponseTaskDto doTasks() throws Exception {
ResponseTaskDto result = new ResponseTaskDto();
int downloadFlag;
int taskFlag;
for (int i = 0; i < 10; i ++) {
if (doTask(i)) {
downloadFlag |= i; // downloaded file
result.setDownloadFlag(downloadFlag);
// execute some code to move file downloaded to correct location
// Execute setup proxy network, rollout services use resource file
taskFlag |= i; // setup done task
result.setTaskFlag(taskFlag);
}
}
return clusterResult;
}
private boolen doTask(int number) throws Exception {
String file = new String(templateFileName + number + ".mp4");
try {
downloadService.downloadFile(file);
} catch (Exception ex) {
// download service work well. can not here
//throw ex;
return false; // download filed: invalid url, ...
}
return true;
}
public class ResponseTaskDto {
int downloadFlag;
int taskFlag;
public void setDownloadFlag(int flag) {
this.downloadFlag = flag;
}
public int getDownloadFlag() {
return this.downloadFlag;
}
public void setTaskFlag(int flag) {
this.taskFlag = flag;
}
public int getTaskFlag() {
return this.taskFlag;
}
}
}
下载服务类:
@FeignClient(value = "http://downloader")
public interface DownloadService {
@RequestMapping(value = "/downloader/api/", method = RequestMethod.POST, produces = {
MediaType.APPLICATION_JSON_VALUE })
void downloadFile(@PathVariable("file") String fileName);
}
我们是manager1的public 2 microservice,Manager2 调用 api 时假设:假设它会被 manager1 使用。
如果微服务管理器1在接收到过多的请求任务时崩溃了。
问题: 如何让 manager2 知道进度服务 manager1 继续 createTask ? 示例:Manager1 在崩溃之前已经完成了 3 个步骤(下载和设置任务)。
【问题讨论】:
标签: java spring-boot failover fallback