Springboot Rest api请求超时或在一定时间内未处理请求则取消

问题描述

我正在尝试在 Springboot Mongodb 应用程序中实现请求超时。流程是这样的。向服务器发送 startCctv 请求。服务器启动cctv并将数据库字段“Status”更新为true。然后我会再调用一个 api 说 getCctvstatus() 来轮询数据库并每分钟检查一次状态字段。如果该字段在 10 分钟内未更新为 true,则应取消原始请求 startCctv 或超时。

这是骨架代码

//Controller class
@PostMapping("/startCctv.on/{id}")
public ResponseEntity startCctv(@PathVariable String cctvId){
  //call to service class
  startCctv(cctvId);
}

//Service class 
public void startCctv(String cctvId) {
sendReqToMainServer(cctvId);
    // main server starts the cctv for the given cctvId and updates the database field "status" to true.
}

//API to check the DB "status" field. The below api should poll the DB and check the "status" 
// field every minute. 
public boolean checkCctvstatus(String cctvId) {
    //DB query to get the status of cctv
    return cctvRepository.getCctvstatus(cctvId);
}   

//If the status is not updated to true within 10 minutes,cancel the original request           
// ie startCctv and send message to the client/user as request timed out. 
@H_502_6@

谁能帮我实现这个目标!? 提前致谢!!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)