fix: 修复 Coze 工作流调用 SocketTimeoutException
CozeAPI.Builder 默认超时仅 5 秒,导致营养分析等耗时工作流请求超时。 将 YAML 中已配置的 connect-timeout(30s) 和 read-timeout(60s) 正确传入 CozeAPI 客户端。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,12 @@ public class CozeConfig {
|
|||||||
@Value("${coze.api.public-key-id:}")
|
@Value("${coze.api.public-key-id:}")
|
||||||
private String publicKeyId;
|
private String publicKeyId;
|
||||||
|
|
||||||
|
@Value("${coze.api.connect-timeout:30000}")
|
||||||
|
private int connectTimeout;
|
||||||
|
|
||||||
|
@Value("${coze.api.read-timeout:60000}")
|
||||||
|
private int readTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 Bot ID - 食谱计算器 Bot
|
* 默认 Bot ID - 食谱计算器 Bot
|
||||||
*/
|
*/
|
||||||
@@ -75,6 +81,8 @@ public class CozeConfig {
|
|||||||
return new CozeAPI.Builder()
|
return new CozeAPI.Builder()
|
||||||
.baseURL(baseUrl)
|
.baseURL(baseUrl)
|
||||||
.auth(new TokenAuth(token))
|
.auth(new TokenAuth(token))
|
||||||
|
.connectTimeout(connectTimeout)
|
||||||
|
.readTimeout(readTimeout)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,4 +156,12 @@ public class CozeConfig {
|
|||||||
public String getDefaultUserId() {
|
public String getDefaultUserId() {
|
||||||
return defaultUserId;
|
return defaultUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getConnectTimeout() {
|
||||||
|
return connectTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.zbkj.common.request.coze.CozeListMessageRequest;
|
|||||||
import com.zbkj.common.request.coze.CozeRetrieveChatRequest;
|
import com.zbkj.common.request.coze.CozeRetrieveChatRequest;
|
||||||
import com.zbkj.common.request.coze.CozeWorkflowRequest;
|
import com.zbkj.common.request.coze.CozeWorkflowRequest;
|
||||||
import com.zbkj.common.request.coze.CozeWorkflowResumeRequest;
|
import com.zbkj.common.request.coze.CozeWorkflowResumeRequest;
|
||||||
|
import com.zbkj.common.config.CozeConfig;
|
||||||
import com.zbkj.common.response.CozeBaseResponse;
|
import com.zbkj.common.response.CozeBaseResponse;
|
||||||
import com.zbkj.common.utils.SseEmitterUtil;
|
import com.zbkj.common.utils.SseEmitterUtil;
|
||||||
import com.zbkj.service.service.tool.ToolCozeService;
|
import com.zbkj.service.service.tool.ToolCozeService;
|
||||||
@@ -55,6 +56,9 @@ public class ToolCozeServiceImpl implements ToolCozeService {
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private JWTOAuthClient jwtOAuthClient;
|
private JWTOAuthClient jwtOAuthClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CozeConfig cozeConfig;
|
||||||
|
|
||||||
@Value("${coze.api.base-url:https://api.coze.cn}")
|
@Value("${coze.api.base-url:https://api.coze.cn}")
|
||||||
private String baseUrl;
|
private String baseUrl;
|
||||||
|
|
||||||
@@ -74,6 +78,8 @@ public class ToolCozeServiceImpl implements ToolCozeService {
|
|||||||
return new CozeAPI.Builder()
|
return new CozeAPI.Builder()
|
||||||
.baseURL(baseUrl)
|
.baseURL(baseUrl)
|
||||||
.auth(new TokenAuth(accessToken))
|
.auth(new TokenAuth(accessToken))
|
||||||
|
.connectTimeout(cozeConfig.getConnectTimeout())
|
||||||
|
.readTimeout(cozeConfig.getReadTimeout())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Coze API not configured properly. Please configure 'coze.api.token' (PAT) or JWT auth.");
|
throw new RuntimeException("Coze API not configured properly. Please configure 'coze.api.token' (PAT) or JWT auth.");
|
||||||
|
|||||||
Reference in New Issue
Block a user