edit-icon download-icon

Create CID

Last Updated: Oct 17, 2018

This interface is exclusive for MQ Enterprise Platinum edition users. For more information, go to Enterprise Platinum Edition Purchase Page.

Description

OnsSubscribeCreate interface creates a subscription relation with a specified Topic on the server.

Usage

After a new application is enabled and the Topic resource is registered, to subscribe to messages, you must create and register the subscription relation with the target Topic in the MQ console or by calling this API, then you can use the registered CID to subscribe to messages.

Request parameters

Name Type Required Description
OnsRegionId String Yes The region where the queried MQ is currently located. It can be obtained through the OnsRegionList method.
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.
ConsumerId String Yes CID of the created message consumption cluster
Remark String No Remark

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Remark String Remark
  • OnsSubscribeDelete: deletes a subscription relation
  • OnsSubscribeList: queries a list of subscription relations
  • OnsSubscribeGet: precisely queries information of a subscription relation

Example

This example shows the process of creating a subscription relation “CID_MingduanTest” in the daily region to consume the messages of Mingduan_67dd.

  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. OnsSubscriptionCreateRequest request = new OnsSubscriptionCreateRequest();
  19. /**
  20. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  21. *This value must be selected and configured by the list obtained through the OnsRegionList method because OnsRegionId is changing, and cannot be written as a fixed value.
  22. */
  23. request.setOnsRegionId("daily");
  24. request.setPreventCache(System.currentTimeMillis());
  25. request.setAcceptFormat(FormatType.JSON);
  26. request.setTopic("Mingduan_67dd");
  27. request.setConsumerId("CID_MingduanTest");
  28. try {
  29. OnsSubscriptionCreateResponse response=iAcsClient.getAcsResponse(request);
  30. System.out.println(response.getRequestId());
  31. } catch (ServerException e) {
  32. e.printStackTrace();
  33. } catch (ClientException e) {
  34. e.printStackTrace();
  35. }
  36. }
Thank you! We've received your feedback.