From f76ecfe074afc84220c577f2b1ccb633dd9bde5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BA=B7=E5=AE=81?= Date: Mon, 23 Oct 2023 10:40:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEhutool=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=8C=85httpRequest=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/dynamictp/common/entity/NotifyPlatform.java | 6 ++++++ .../dynamictp/core/notifier/base/AbstractHttpNotifier.java | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/dromara/dynamictp/common/entity/NotifyPlatform.java b/common/src/main/java/org/dromara/dynamictp/common/entity/NotifyPlatform.java index 2faebc1a..a8efabb8 100644 --- a/common/src/main/java/org/dromara/dynamictp/common/entity/NotifyPlatform.java +++ b/common/src/main/java/org/dromara/dynamictp/common/entity/NotifyPlatform.java @@ -54,4 +54,10 @@ public class NotifyPlatform { * Receivers, split by , */ private String receivers = "all"; + + /** + * http请求超时时间,单位(毫秒)
+ * 默认5000毫秒 + */ + private Integer timeOut = 5000; } diff --git a/core/src/main/java/org/dromara/dynamictp/core/notifier/base/AbstractHttpNotifier.java b/core/src/main/java/org/dromara/dynamictp/core/notifier/base/AbstractHttpNotifier.java index 398fc726..92412a86 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/notifier/base/AbstractHttpNotifier.java +++ b/core/src/main/java/org/dromara/dynamictp/core/notifier/base/AbstractHttpNotifier.java @@ -38,7 +38,11 @@ public abstract class AbstractHttpNotifier extends AbstractNotifier { protected void send0(NotifyPlatform platform, String content) { val url = buildUrl(platform); val msgBody = buildMsgBody(platform, content); - HttpResponse response = HttpRequest.post(url).body(msgBody).execute(); + HttpRequest request = HttpRequest.post(url) + .setConnectionTimeout(platform.getTimeOut()) + .setReadTimeout(platform.getTimeOut()) + .body(msgBody); + HttpResponse response = request.execute(); if (Objects.nonNull(response)) { log.info("DynamicTp notify, {} send success, response: {}, request: {}", platform(), response.body(), msgBody); -- Gitee