本文介紹Java SDK快速入門流程。

  1. 建立AcsClient執行個體。
    DefaultProfile profile = DefaultProfile.getProfile(
                 mpsRegionId,      // 地區ID
                 accessKeyId,      // RAM帳號的AccessKey ID
                 accessKeySecret); // RAM帳號Access Key Secret
    IAcsClient client = new DefaultAcsClient(profile);
  2. 建立request,並設定參數。
    SubmitJobsRequest request = new SubmitJobsRequest();
  3. 發起API請求並顯示傳回值。
    response = client.getAcsResponse(request);
    System.out.println("PipelineName is:" + response.getPipelineList().get(0).getName());
    System.out.println("PipelineId is:" + response.getPipelineList().get(0).getId());
完整代碼
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
public class Quick {
    private static String accessKeyId = "xxx";
    private static String accessKeySecret = "xxx";
    private static String[] mpsRegionIds = new String[] {
            "cn-hangzhou", "cn-beijing","cn-shenzhen", "cn-shanghai",
            "cn-hongkong", "us-west-1", "ap-southeast-1", "ap-northeast-1",
            "eu-central-1", "ap-south-1"
    };
    public static void main(String[] args) {
        for (String mpsRegionId : mpsRegionIds) {
            System.out.println("region id is:" + mpsRegionId);
            // 建立DefaultAcsClient執行個體並初始化
            DefaultProfile profile = DefaultProfile.getProfile(
                    mpsRegionId,      // 地區ID
                    accessKeyId,      // RAM帳號的AccessKey ID
                    accessKeySecret); // RAM帳號Access Key Secret
            IAcsClient client = new DefaultAcsClient(profile);
            // 建立API請求並設定參數
            SearchPipelineRequest request = new SearchPipelineRequest();
            // 發起請求並處理應答或異常
            SearchPipelineResponse response;
            try {
                response = client.getAcsResponse(request);
                System.out.println("PipelineName is:" + response.getPipelineList().get(0).getName());
                System.out.println("PipelineId is:" + response.getPipelineList().get(0).getId());
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
}