edit-icon download-icon

Fetch region information

Last Updated: Dec 21, 2018

OnsRegionList interface returns a list of currently available Regions of MQ.

Application scenario

Information about two Regions needs to be specified when you use SDK to connect to MQ for management and control operations. Information about the second Region is retrieved through OnsRegionList. The following provides more details:

  1. Connecting your applications to MQ: Select the nearest Open API gateway endpoint according to the Region where to deploy your application, and enter a value in regionid. This regionid is only used for accessing the Open API gateway of Alibaba Cloud. MQ uses Alibaba Cloud Open API platform (POP) to provide API services.
  2. Connecting to the Region where management and control operations are performed: Specify a Region to perform operations on its resources, and enter a value for its regionid. This regionid can be retrieved through OnsRegionList interface.

List of request parameters

Name Type Required Description
OnsRegionId String No The region of the currently queried MQ.
OnsPlatform String No The source of the request, which by default is POP platform.
PreventCache Long Yes It’s used for CSRF verification. Set it to the current system time.

List of response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Data List(RegionDo) The query result

RegionDo data structure

Member Type Description
Id Long Number in a database
RegionId String The name of RegionId
RegionName String The alias of Region
ChannelId Long The number of the channel
ChannelName String The alias of the channel
CreateTime Long Time of creation
UpdateTime Long Time of the last update

Example

  1. public static void main(String[] args) {
  2. String regionId = "cn-hangzhou";
  3. String accessKey = "XXXXXXXXXXXXXXXXX";
  4. String secretKey = "XXXXXXXXXXXXXXXXX";
  5. String endPointName ="cn-hangzhou";
  6. String productName ="Ons";
  7. String domain ="ons.cn-hangzhou.aliyuncs.com";
  8. /**
  9. *Select Region based on the region you will access, and set the corresponding access point.
  10. */
  11. try {
  12. DefaultProfile.addEndpoint(endPointNameregionIdproductNamedomain);
  13. } catch (ClientException e) {
  14. e.printStackTrace();
  15. }
  16. IClientProfile profile= DefaultProfile.getProfile(regionIdaccessKeysecretKey);
  17. IAcsClient IAcsClient= new DefaultAcsClient(profile);
  18. OnsRegionListRequest request = new OnsRegionListRequest();
  19. request.setAcceptFormat(FormatType.JSON);
  20. request.setPreventCache(System.currentTimeMillis());
  21. try {
  22. OnsRegionListResponse response = IAcsClient.getAcsResponse(request);
  23. List<OnsRegionListResponse.RegionDo> regionDoList=response.getData();
  24. for (OnsRegionListResponse.RegionDo regionDo:regionDoList){
  25. System.out.println(regionDo.getId()+" "+
  26. regionDo.getOnsRegionId()+" "+
  27. regionDo.getRegionName()+" "+
  28. regionDo.getChannelId()+" "+
  29. regionDo.getChannelName()+" "+
  30. regionDo.getCreateTime()+" "+
  31. regionDo.getUpdateTime());
  32. }
  33. } catch (ClientException e) {
  34. e.printStackTrace();
  35. }
  36. catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. }
Thank you! We've received your feedback.