edit-icon download-icon

Access instruction

Last Updated: Jun 21, 2018

This topic explains how to access MQ Open API, including how to obtain SDK and set initialization parameters.

1. Obtain SDK

Use the following POM configuration to add dependency on the SDK of Open API.

  1. <dependencies>
  2. <dependency>
  3. <groupId>com.aliyun</groupId>
  4. <artifactId>aliyun-java-sdk-core</artifactId>
  5. <optional>true</optional>
  6. <version>3.2.8</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>com.aliyun</groupId>
  10. <artifactId>aliyun-java-sdk-ons</artifactId>
  11. <version>2.0.1</version>
  12. </dependency>
  13. </dependencies>

2. Public parameter setting

To use Open API, start the Open API client, and when you do this, set the access point and parameters such as AccessKey and SecretKey. Here’s an example:

  1. /**
  2. *Open API's access point; set as the target Region
  3. */
  4. String regionId = "XXXXX";
  5. /**
  6. *AccessKey used for authenticating; obtained from the Console on the Alibaba Cloud official website
  7. */
  8. String accessKey = "XXXXXXXXXXXXXXXXX";
  9. /**
  10. *SecretKey used for authenticating; obtained from the Console on the Alibaba Cloud official website
  11. */
  12. String secretKey = "XXXXXXXXXXXXXXXXX";
  13. /*
  14. *The name of cloud products accessed through Open API; set as Ons
  15. */
  16. String productName ="Ons";
  17. /**
  18. *The access point domain name corresponding to the endPoint access point
  19. */
  20. String domain ="ons.XXXXX.aliyuncs.com";
  21. try {
  22. DefaultProfile.addEndpoint(regionIdregionIdproductNamedomain);
  23. } catch (ClientException e) {
  24. e.printStackTrace();
  25. }
  26. IClientProfile profile= DefaultProfile.getProfile(regionIdaccessKeysecretKey);
  27. IAcsClient iAcsClient= new DefaultAcsClient(profile);

Parameter descriptions

  • regionId: the region where the API gateway is located, currently supported ones are cn-beijing, cn-hangzhou, cn-qingdao, cn-shenzhen, etc.
  • accessKey: AK obtained by a user on the Alibaba ECS Management Console.
  • secretKey: SK obtained by a user on the Alibaba ECS Management Console.
  • endPointName: the access point name, consistent with RegionId.
  • productName: the product name of Open API. Can be simply set as Ons.
  • domain: the access point domain of Open API. The rule is ons.${RegionId}.aliyuncs.com. Regions with Open API support are summarized in the following table.
Region Name RegionId Domain Note
North China 2 in public cloud cn-beijing ons.cn-beijing.aliyuncs.com Recommended for users who use the Region of North China 2 in public cloud.
Internet cn-qingdao ons.cn-qingdao.aliyuncs.com Recommended for users who use the Region of Internet.
East China 1 in public cloud cn-hangzhou ons.cn-hangzhou.aliyuncs.com Recommended for users who use the Region of East China 1 in public cloud.
East China 2 in public cloud cn-shanghai ons.cn-shanghai.aliyuncs.com Recommended for users who use the Region of East China 2 in public cloud.
South China 1 in public cloud cn-shenzhen ons.cn-shenzhen.aliyuncs.com Recommended for users who use the Region of South China 1 in public cloud.
Singapore in public cloud ap-southeast-1 ons.ap-southeast-1.aliyuncs.com Recommended for users who use the Region of Singapore in public cloud.
East China 1 in AntCloud cn-hangzhou-finance ons.cn-hangzhou-finance.aliyuncs.com Recommended for users who use the Region of East China 1 in AntCloud.
South China 1 in AntCloud cn-shenzhen-finance ons.cn-shenzhen-finance.aliyuncs.com Recommended for users who use the Region of South China 1 in AntCloud.
East China 2 in AntCloud cn-shanghai-finance ons.cn-shanghai-finance.aliyuncs.com Recommended for users who use the Region of East China 2 in AntCloud.
Thank you! We've received your feedback.