edit-icon download-icon

Query consumer connection

Last Updated: Jan 30, 2018

OnsConsumerConnection interface queries the connection of the current client in the specified Consumer ID (CID).

Usage

This interface tells if the consumer of the specified CID is online and retrieves a list of detailed client connections.

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 The consumer CID to be queried

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Data List(ConnectionDo) The connection information of the specified consumer

ConnectionDo data structure

Member Type Description
ClientId String ID of a consumption instance
ClientAddr String Address and port of the consumption instance
Language String Language of the consumer
Version String The consumer version
  • OnsConsumerStatus: queries the consumption status
  • OnsConsumerAccumulate: queries the consumption accumulation

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. OnsConsumerGetConnectionRequest request = new OnsConsumerGetConnectionRequest();
  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.setConsumerId("RTDSQ_1013_GROUP");
  27. try {
  28. OnsConsumerGetConnectionResponse response=iAcsClient.getAcsResponse(request);
  29. List<OnsConsumerGetConnectionResponse.Data.ConnectionDo> connectionDoList=response.getData().getConnectionList();
  30. for(OnsConsumerGetConnectionResponse.Data.ConnectionDo connectionDo:connectionDoList){
  31. System.out.println(connectionDo.getClientId()+" "+
  32. connectionDo.getClientAddr()+" "+
  33. connectionDo.getLanguage()+" "+
  34. connectionDo.getVersion());
  35. }
  36. } catch (ServerException e) {
  37. e.printStackTrace();
  38. } catch (ClientException e) {
  39. e.printStackTrace();
  40. }
  41. }
Thank you! We've received your feedback.