Help Center> ServiceStage> API Reference> CSE API> Microservice Instance> Querying Microservice Instances in Batches

Querying Microservice Instances in Batches

Function

This API is used to query registered microservice instances in batches based on microservice version rules or field filter criteria.

Constraints

When using special characters such as version 0+, you need to transcode them. For a curl command, you can use quotation marks ('' '') between the content, for example, curl -k "https://{endpoint}/v4/{project_id}/registry/instances?appId=AppTest&serviceName=helloworld&version=0+".

URI

POST /v4/{project_id}/registry/instances/action

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Unique ID of a tenant sub-project. Length: 1–64 characters.

Table 2 Query parameters

Parameter

Mandatory

Type

Description

type

Yes

String

Operation. Currently, only the query operation is supported.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

x-domain-name

Yes

String

Tenant account name.

X-consumer_id

Yes

String

Microservice consumer ID, which must be unique.

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

services

No

Array of FindService objects

Struct of the request for querying services.

instances

No

Array of FindInstance objects

Struct of the request for querying instances.

Table 5 FindService

Parameter

Mandatory

Type

Description

service

No

DependencyKey object

Basic information about the microservice.

rev

No

String

Version number cached on the client.

Table 6 DependencyKey

Parameter

Mandatory

Type

Description

environment

No

String

development|testing|acceptance|production

appId

Yes

String

Application ID, which must be unique.

serviceName

Yes

String

Microservice name. For a provider microservice, the name can be set to an asterisk (*), indicating that the microservice depends on all services of the same tenant. When the microservice name is *, appId and version can be left blank. For a consumer microservice, the name cannot be set to *.

version

Yes

String

Microservice version. For a provider microservice, the version can be subsequent versions of a certain version (example: 1.0.1+, which indicates a version later than 1.0.1), a fixed version, or the latest version. For a consumer microservice, the version must be a fixed version.

Table 7 FindInstance

Parameter

Mandatory

Type

Description

instance

No

HeartbeatSetElement object

Struct of the request for querying a microservice instance.

rev

No

String

Version number cached on the client.

Table 8 HeartbeatSetElement

Parameter

Mandatory

Type

Description

serviceId

No

String

Microservice ID.

instanceId

No

String

Microservice instance ID.

Response Parameters

Status code: 200

Table 9 Response body parameters

Parameter

Type

Description

services

BatchFindResult object

Struct of the result for batch queries.

instances

BatchFindResult object

Struct of the result for batch queries.

Table 10 BatchFindResult

Parameter

Type

Description

failed

Array of FindFailedResult objects

Struct of the response for querying failed results.

notModified

Array of integers

Index set corresponding to the request array.

updated

Array of FindResult objects

Query result struct list.

Table 11 FindFailedResult

Parameter

Type

Description

indexes

Array of integers

Index set corresponding to the request array.

error

Error object

Error struct.

Table 12 Error

Parameter

Type

Description

errorCode

String

Error code.

errorMessage

String

Error information.

detail

String

Location details.

Table 13 FindResult

Parameter

Type

Description

index

Integer

Index corresponding to the request array.

rev

String

Versions returned by the server. If the versions are the same as the versions cached on the client, the instances parameter is left empty.

instances

Array of MicroServiceInstance objects

Instance list.

Table 14 MicroServiceInstance

Parameter

Type

Description

instanceId

String

Instance ID, which must be unique. During instance creation, instanceId is generated by the service center.

serviceId

String

Microservice ID, which must be unique. During instance creation, the service ID in the URL instead of the service ID here is used.

version

String

Microservice version.

hostName

String

Host information.

endpoints

Array of strings

Access address.

status

String

Instance status. Value: UP (default), DOWN, STARTING, or OUTOFSERVICE.

properties

Object

Extended attribute. You can customize a key and value. The value contains at least 1 byte.

healthCheck

HealthCheck object

Health check information.

dataCenterInfo

DataCenterInfo object

Data center information.

timestamp

String

Instance creation timestamp, which is automatically generated.

modTimestamp

String

Update time.

Table 15 HealthCheck

Parameter

Type

Description

mode

String

Heartbeat mode. Value: push or pull.

port

Integer

Port.

interval

Integer

Interval for sending heartbeat messages, in seconds.

times

Integer

Number of failures that are allowed.

Table 16 DataCenterInfo

Parameter

Type

Description

name

String

Region name.

region

String

Region.

availableZone

String

AZ.

Status code: 400

Table 17 Response body parameters

Parameter

Type

Description

errorCode

String

Error code.

errorMessage

String

Error information.

detail

String

Location details.

Status code: 500

Table 18 Response body parameters

Parameter

Type

Description

errorCode

String

Error code.

errorMessage

String

Error information.

detail

String

Location details.

Example Requests

GET https://{endpoint}/v4/{project_id}/registry/instances/action

{
  "services" : [ {
    "service" : {
      "appId" : "TestApp",
      "serviceName" : "helloworld1",
      "version" : "0+"
    },
    "rev" : "1.0.0"
  }, {
    "service" : {
      "appId" : "TestApp",
      "serviceName" : "helloworld2",
      "version" : "latest"
    },
    "rev" : "1.0.0"
  } ]
}

Example Responses

Status code: 200

OK

"{\n  \"services\": {\n    \"failed\": [\n      {\n        \"indexes\": [\n          0\n        ],\n        \"error\": {\n          \"errorCode\": \"string\",\n          \"errorMessage\": \"string\",\n          \"detail\": \"string\"\n        }\n      }\n    ],\n    \"notModified\": [\n      0\n    ],\n    \"updated\": [\n      {\n        \"index\": 0,\n        \"rev\": \"string\",\n        \"instances\": [\n          {\n            \"instanceId\": \"string\",\n            \"serviceId\": \"string\",\n            \"version\": \"string\",\n            \"hostName\": \"string\",\n            \"endpoints\": [\n              \"string\",\n              \"string\"\n            ],\n            \"status\": \"string\",\n            \"null\": null,\n            \"healthCheck\": {\n              \"mode\": \"string\",\n              \"port\": 0,\n              \"interval\": 0,\n              \"times\": 0\n            },\n            \"dataCenterInfo\": {\n              \"name\": \"string\",\n              \"region\": \"string\",\n              \"availableZone\": \"string\"\n            },\n            \"timestamp\": \"string\",\n            \"modTimestamp\": \"string\"\n          }\n        ]\n      }\n    ]\n  },\n  \"instances\": {\n    \"failed\": [\n      {\n        \"indexes\": [\n          0\n        ],\n        \"error\": {\n          \"errorCode\": \"string\",\n          \"errorMessage\": \"string\",\n          \"detail\": \"string\"\n        }\n      }\n    ],\n    \"notModified\": [\n      0\n    ],\n    \"updated\": [\n      {\n        \"index\": 0,\n        \"rev\": \"string\",\n        \"instances\": [\n          {\n            \"instanceId\": \"string\",\n            \"serviceId\": \"string\",\n            \"version\": \"string\",\n            \"hostName\": \"string\",\n            \"endpoints\": [\n              \"string\",\n              \"string\"\n            ],\n            \"status\": \"string\",\n            \"null\": null,\n            \"healthCheck\": {\n              \"mode\": \"string\",\n              \"port\": 0,\n              \"interval\": 0,\n              \"times\": 0\n            },\n            \"dataCenterInfo\": {\n              \"name\": \"string\",\n              \"region\": \"string\",\n              \"availableZone\": \"string\"\n            },\n            \"timestamp\": \"string\",\n            \"modTimestamp\": \"string\"\n          }\n        ]\n      }\n    ]\n  }\n}"

Status Codes

Status Code

Description

200

OK

400

Bad Request

500

Internal Server Error

Error Codes

See Error Codes.