title: Fallback service spring Boot
body: <p>We execute run a API to download a groups files with api below:
  curl -X POST localhost:port/manager/createTask
  Rest API: (manager)</p>
  
  <pre><code>@RestController
  @RequestMapping("/manager")
  public class ClusterResource {
      @Autowired
      private MyService myService;
      @PostMapping("/createTask")
      @ResponseBody
      public ResponseEntity doTasks() throws Exception {
          myService.doTask();
          return new ResponseEntity&lt;&gt;(HttpStatus.OK);
      }
  }
  </code></pre>
  
  <p>MyService class:</p>
  
  <pre><code>@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 &lt; 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;
          }
     }
  }
  </code></pre>
  
  <p>DownloadService class:</p>
  
  <pre><code>@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);
  }
  </code></pre>
  
  <p>we are public 2 microservice of manager as Manager1, Manager2
  when api called then assumed: assume it will be consumed by the manager1.</p>
  
  <p>If the microservice manager1 was crashed when receiving too much request tasks.</p>
  
  <p><strong>Question :</strong>
  How to manager2 known the progress services manager1 to continue createTask ?
  Example: Manager1 has done  3 steps (download and setup task) before its crashed.</p>