文档

新建Client

更新时间:

本文介绍如何通过Java SDK新建一个DashVector Client。

说明

通过DashVector Client可连接DashVector服务端,进行Collection相关操作。

前提条件

接口定义

package com.aliyun.dashvector;

// 通过apiKey和endpoint构造
DashVectorClient(String apiKey, String endpoint);

// 通过DashVectorClientConfig构造
DashVectorClient(DashVectorClientConfig config);

使用示例

说明

需要使用您的api-key替换示例中的YOUR_API_KEY、您的Cluster Endpoint替换示例中的YOUR_CLUSTER_ENDPOINT,代码才能正常运行。

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorClientConfig;
import com.aliyun.dashvector.common.DashVectorException;

public class Main {
    public static void main(String[] args) throws DashVectorException {
        // 通过apiKey和endpoint构造
        DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");
      
        // 通过Builder构造DashVectorClientConfig
        DashVectorClientConfig config = DashVectorClientConfig.builder()
            .apiKey("YOUR_API_KEY")
            .endpoint("YOUR_CLUSTER_ENDPOINT")
            .timeout(10f)
            .build();
        client = new DashVectorClient(config);
    }
}

入参描述

可通过DashVectorClientConfigBuilder构造DashVectorClientConfig对象,其可用方法如下:

方法

必填

默认值

说明

apiKey(String apiKey)

-

api-key

endpoint(String endpoint)

-

Cluster的Endpoint,可在控制台“Cluster详情”中查看

timeout(Float timeout)

10.0f

超时时间(单位:秒),-1 代表不超时。

build()

-

-

构造DashVectorClientConfig对象

说明

endpoint参数,可在控制台Cluster详情中查看。

出参描述

说明

DashVectorClient初始化期间可能抛出DashVectorException异常,可通过具体异常信息分析初始化失败原因。

  • 本页导读 (0)
文档反馈