fix: 发送OA消息的请求添加超时时间为2分钟,发送失败后的延迟时间设为10分钟

This commit is contained in:
wxyclub
2024-04-19 17:39:05 +08:00
parent 4dcf5237d4
commit 00187403d3
5 changed files with 12 additions and 12 deletions
@@ -144,7 +144,7 @@ public class SendDeleteMQService {
private void restSendDoneTodo(String object, SimpleDateFormat sdf, SendTodoLog sendTodoLog, int againNumNew,String operMesg) throws Exception{
// 发送失败连续持续3次, 如果在失败等待1个小时后重试3次
if(againNumNew < 6){
Thread.sleep(3000);
Thread.sleep(600000);
logger.info("发送失败连续持续"+againNumNew+"次,存入延迟重试队列!!!!!!!!!");
}else {
@@ -140,7 +140,7 @@ public class SendDoneMQService {
private void restSendDoneTodo(NotifyTodoSendContext object, SimpleDateFormat sdf, SendTodoLog sendTodoLog, int againNumNew,String operMesg) throws Exception{
// 发送失败连续持续3次, 如果在失败等待1个小时后重试3次
if(againNumNew < 6){
Thread.sleep(3000);
Thread.sleep(600000);
logger.info("发送失败连续持续"+againNumNew+"次,存入延迟重试队列!!!!!!!!!");
}else {
@@ -175,7 +175,7 @@ public class SendMQService {
private void restSendTodo(BusProcessNew object, SimpleDateFormat sdf, SendTodoLog sendTodoLog, int againNumNew,String operMesg) throws Exception{
// 失败次数小于6次,放入失败队列延迟消费
if((againNumNew < 6)){
Thread.sleep(3000);
Thread.sleep(600000);
logger.info("发送失败连续持续"+againNumNew+"次,存入延迟重试队列!!!!!!!!!");
}else {
logger.info("发送失败连续持续"+againNumNew+"次!!");
@@ -134,7 +134,8 @@ public class SendToBeReadMQService {
private void restSendTodo(BusProcessNew object, SimpleDateFormat sdf, SendTodoLog sendTodoLog, int againNumNew, String operMesg) throws Exception {
// 失败次数小于6次,放入失败队列延迟消费
if ((againNumNew < 6)) {
Thread.sleep(3000);
// 延迟10分钟
Thread.sleep(600000);
logger.info("发送失败连续持续" + againNumNew + "次,存入延迟重试队列!!!!!!!!!");
} else {
logger.info("发送失败连续持续" + againNumNew + "次!!");
@@ -11,6 +11,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Component
public class OkHttpUtil {
@@ -250,6 +251,10 @@ public class OkHttpUtil {
* @return
*/
public String postForJson(String url, String json, Map<String, String> headerParams){
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.MINUTES)//设置连接超时时间
.readTimeout(2, TimeUnit.MINUTES)//设置读取超时时间
.build();
RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), json);
String responseBody = "";
Request.Builder requestBuilder = new Request.Builder().url(url);
@@ -257,20 +262,14 @@ public class OkHttpUtil {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
Request request = requestBuilder.post(requestBody).build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
try (Response response = client.newCall(request).execute()) {
int status = response.code();
if (status == 200) {
return response.body().string();
}
} catch (Exception e) {
logger.error("okhttp post error >> ex = {}", ExceptionUtils.getStackTrace(e));
return "okhttp post error >> ex = {} "+ e.getMessage();
} finally {
if (response != null) {
response.close();
}
return "okhttp post error >> ex = {} " + e.getMessage();
}
return responseBody;
}