返回顶部
a

alibabacloud-sdk-client-initialization-for-java

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.0.2-beta
安全检测
已通过
72
下载量
0
收藏
概述
安装方式
版本历史

alibabacloud-sdk-client-initialization-for-java

# Client Initialization Best Practices (Java) ## Core Rules - **Client is thread-safe** — safe to share across threads without synchronization. - **Use singleton pattern** — do NOT create new client instances per request. Frequent `new Client()` calls waste resources and hurt performance. - Prefer **explicit endpoint** over region-based endpoint resolution. - preview version ## Recommended Client Creation ```java public class ClientFactory { private static volatile com.aliyun.ecs20140526.Client instance; public static com.aliyun.ecs20140526.Client getInstance() throws Exception { if (instance == null) { synchronized (ClientFactory.class) { if (instance == null) { com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")) .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")); config.setEndpoint("ecs.cn-hangzhou.aliyuncs.com"); instance = new com.aliyun.ecs20140526.Client(config); } } } return instance; } } ``` ## Endpoint Configuration Priority: explicit `endpoint` > region-based resolution via `regionId`. ```java // Preferred: explicit endpoint config.setEndpoint("ecs.cn-hangzhou.aliyuncs.com"); // Alternative: SDK resolves endpoint from region config.setRegionId("cn-hangzhou"); ``` ### VPC Endpoints Use VPC endpoints when running inside Alibaba Cloud VPC (hybrid cloud, leased lines, multi-region): ```java config.setEndpoint("ecs-vpc.cn-hangzhou.aliyuncs.com"); ``` ### File Upload APIs (Advance) For file upload APIs (e.g., Visual Intelligence), set **both** `regionId` and `endpoint` to the same region. Otherwise you may see timeouts due to cross-region OSS access: ```java config.setRegionId("cn-shanghai"); config.setEndpoint("objectdet.cn-shanghai.aliyuncs.com"); // For VPC file upload authorization: client._openPlatformEndpoint = "openplatform-vpc.cn-shanghai.aliyuncs.com"; ``` ## Synchronous vs Asynchronous | Mode | SDK Artifact | When to Use | |------|-------------|-------------| | Synchronous | `com.aliyun:{productCode}{version}` | Simple flows, low concurrency, easier debugging | | Asynchronous | `com.aliyun:alibabacloud-{productCode}{version}` | High concurrency/throughput, non-blocking I/O | Async example: ```java AsyncClient client = AsyncClient.builder() .region("cn-hangzhou") .credentialsProvider(provider) .overrideConfiguration(ClientOverrideConfiguration.create() .setEndpointOverride("ecs.cn-chengdu.aliyuncs.com")) .build(); CompletableFuture<DescribeRegionsResponse> response = client.describeRegions(request); response.thenAccept(resp -> System.out.println(new Gson().toJson(resp))) .exceptionally(throwable -> { System.out.println(throwable.getMessage()); return null; }); // Always close async client when done client.close(); ```

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 alibabacloud-sdk-client-initialization-for-java-1776023285 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 alibabacloud-sdk-client-initialization-for-java-1776023285 技能

通过命令行安装

skillhub install alibabacloud-sdk-client-initialization-for-java-1776023285

下载 Zip 包

⬇ 下载 alibabacloud-sdk-client-initialization-for-java v0.0.2-beta

文件大小: 2.3 KB | 发布时间: 2026-4-13 09:19

v0.0.2-beta 最新 2026-4-13 09:19
- Bumped version to 0.0.2-beta.
- Added "preview version" mention to Core Rules section in documentation.
- No other changes to guidance, examples, or API recommendations.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部