edit-icon download-icon

Create PID

Last Updated: Apr 08, 2018

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

Description

OnsPublishCreate interface creates and registers a publishing relation to MQ, and obtain the generated PID for sending messages in the production environment.

Usage

After creating a Topic, this interface is called when the corresponding PID needs to be registered for newly created resources to send messages.

Notes: each Topic only needs one PID. There’s no need to create multiple PIDs because a PID can be reused in multiple applications.

Request parameters

Name Type Required Description
OnsRegionId String Yes The region of the currently queried MQ. It can be obtained with the OnsRegionList method. For more information, see Terms.
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.
ProducerId String Yes PID of the publishing relation to be created.
Topic String Yes The name of the published Topic.

Return parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
  • OnsPublishDelete: deletes a publishing relation
  • OnsPublishList: retrieves a list of publishing relations
  • OnsPublishGet: queries a publishing relation

Example

This example shows the process of accessing from the end point China East, and creating a publishing relation named “PID_Mingduan” in the public beta region. This publishing relation is used for sending messages of Topic “MingduanTestAPI”.

  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. OnsPublishCreateRequest request = new OnsPublishCreateRequest();
  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("publictest");
  24. request.setPreventCache(System.currentTimeMillis());
  25. request.setAcceptFormat(FormatType.JSON);
  26. request.setTopic("MingduanTestAPI");
  27. request.setProducerId("PID_Mingduan");
  28. try {
  29. OnsPublishCreateResponse 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. }

Return result

CC815D34-0950-43BF-A4E8-4187C3C7BF19

Thank you! We've received your feedback.