Updated on 2025-09-03 GMT+08:00

Querying a Message with a Specified Time Period

Function

This API is used to query a message with a specified time period.

URI

GET /v2/{project_id}/instances/{instance_id}/management/topics/{topic}/messages

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description:

Project ID. For details, see Obtaining a Project ID.

Constraints:

N/A

Value range:

N/A

Default value:

N/A

instance_id

Yes

String

Definition:

Instance ID. You can call the API for querying all instances to obtain the instance ID. The instance ID is in the response body.

Constraints:

N/A

Range:

N/A

Default Value:

N/A

topic

Yes

String

Parameter description:

Topic name.

Constraints:

A topic name must start with a letter and can only contain letters, hyphens (-), underscores (_), and digits.

Value range:

N/A

Default value:

N/A

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

start_time

No

String

Parameter description:

Query start time as a Unix timestamp.

Constraints:

N/A

Value range:

N/A

Default value:

0

end_time

No

String

Parameter description:

Query end time as a Unix timestamp.

Constraints:

N/A

Value range:

N/A

Default value:

Current system time.

limit

No

Integer

Parameter description:

Number of messages returned on a page.

Constraints:

N/A

Value range:

N/A

Default value:

10

offset

No

Integer

Parameter description:

Offset, which is the position where the query starts.

Constraints:

N/A

Value range:

≥ 0

Default value:

N/A

partition

No

String

Parameter description:

Partition ID.

Constraints:

N/A

Value range:

N/A

Default value:

The default value is -1, indicating that all partitions are queried.

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

messages

Array of messages objects

Parameter description:

Message list.

messages_count

Integer

Parameter description:

Total number of messages.

Value range:

N/A

offsets_count

Integer

Parameter description:

Total number of pages.

Value range:

N/A

offset

Integer

Parameter description:

Current page number.

Value range:

N/A

Table 4 messages

Parameter

Type

Description

topic

String

Parameter description:

Topic name.

Value range:

N/A

partition

Integer

Parameter description:

Partition ID.

Value range:

N/A

message_offset

Long

Parameter description:

Message ID.

Value range:

N/A

size

Integer

Parameter description:

Message size, in bytes.

Value range:

N/A

timestamp

Long

Parameter description:

Message production time.

The value is a Unix timestamp. The unit is millisecond.

Value range:

N/A

Example Requests

GET https://{endpoint}/v2/{project_id}/instances/{instance_id}/management/topics/{topic}/messages

Example Responses

Status code: 200

The message with the specified time period is queried successfully.

{
  "messages" : [ {
    "topic" : "mytest",
    "partition" : 0,
    "message_offset" : 7,
    "size" : 6,
    "timestamp" : 1568125036045
  } ],
  "messages_count" : 1,
  "offsets_count" : 1,
  "offset" : 1
}

Status Codes

Status Code

Description

200

The message with the specified time period is queried successfully.

Error Codes

See Error Codes.