如何使用
2025/7/10小于 1 分钟
如何使用
🚀 使用步骤
添加Maven依赖
<dependency> <groupId>top.codelong</groupId> <artifactId>send-sdk</artifactId> <version>1.0.0</version> </dependency>
配置参数(application.yml)
api: gateway: sdk: base-url: http://gateway-center:8080 safe-key: your_safe_key safe-secret: your_safe_secret connect-timeout: 5000 socket-timeout: 10000 max-connections: 100
代码调用示例
// 1. 注入GatewayClient @Resource private GatewayClient gatewayClient; // 2. GET请求 Map<String, Object> params = Map.of("name", "codelong"); String result = gatewayClient.get("/api/test", params); // 3. POST请求 User user = new User("Alice", 28); String response = gatewayClient.post("/api/users", null, user);
异常处理
try { gatewayClient.get("/api/data", params); } catch (AuthException e) { // 认证失败处理 } catch (TimeoutException e) { // 超时重试逻辑 }
🔧 配置参数说明
参数 | 默认值 | 说明 |
---|---|---|
base-url | - | 网关中心地址 |
safe-key | - | 安全密钥Key |
safe-secret | - | 安全密钥Secret |
connect-timeout | 5000ms | 连接超时时间 |
socket-timeout | 10000ms | 读取超时时间 |
max-connections | 100 | 连接池最大连接数 |