You need to enable JavaScript to run this app.
文档中心
消息队列 Kafka版

消息队列 Kafka版

复制全文
下载 pdf
消息查询
QueryMessageByTimestamp - 根据时间查询消息
复制全文
下载 pdf
QueryMessageByTimestamp - 根据时间查询消息
根据时间查询查询实例 Topic 中的消息​
使用说明​
此接口用于查询分区中指定时间范围内的消息元数据。​
调试​
API Explorer
您可以通过 API Explorer 在线发起调用,无需关注签名生成过程,快速获取调用结果。
​
请求参数​
下方仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。​
Action string 必选 示例值:QueryMessageByTimestamp​
要执行的操作,取值:QueryMessageByTimestamp。​
​
Version string 必选 示例值:2022-05-01​
API的版本,取值:2022-05-01。​
​
TopicName string 必选 示例值:query_topic​
Topic 名称。​
​
PartitionId integer 必选 示例值:0​
分区编号。设置为-1时表示查询全部分区。​
​
Refresh boolean 可选 示例值:false​
是否强制刷新,默认为false。​
  • false:不强制刷新消息缓存。​
  • true:强制刷新消息缓存。​
说明​
当时间范围内有新消息写入时,可能需要刷新缓存才能正常查询到。​
​
PageNumber integer 必选 示例值:1​
列表的页码,最小值为 1。​
​
PageSize integer 必选 示例值:10​
列表中每一页的条目数量,取值范围为 1~16。​
​
SortOrder string 可选 示例值:Asc​
查询结果的排序方式,默认为Asc。​
  • Asc:按分区和消息位点进行升序排列。​
  • Desc:按分区和消息位点进行降序排列。​
​
QueryStartTimestamp long 必选 示例值:1661320625000​
需要查询的起始时间。Unix 时间戳格式,单位为毫秒。​
​
QueryEndTimestamp long 必选 示例值:1661320682000​
需要查询的结束时间。Unix 时间戳格式,单位为毫秒。​
​
InstanceId string 必选 示例值:kafka-cnngbnntswg1****​
实例 ID。​
​
​
​
返回参数​
下方仅列出本接口特有的返回参数。更多信息请参见返回结构。​
MessageList object[] 示例值:--​
符合查询条件的消息列表。​
TopicName string 示例值:test-topic​
Topic 名称。​
​
PartitionId integer 示例值:0​
消息所在分区。​
​
MessageOffset integer 示例值:0​
消息 Offset。​
​
MessageSize integer 示例值:1024​
消息大小,单位为(Byte)。​
​
CreateTime integer 示例值:1717415105339​
消息写入时间。​
​
Key string 示例值:tesst-key​
消息 Key 字段。​
​
Message string 示例值:test-value​
消息 Body 字段。​
​
​
HasMoreMessage boolean 示例值:true​
是否还有更多页的消息。​
  • true:还有更多页的消息。​
  • false:没有更多页的消息。​
  • 如果指定时间段内消息数量超出指定的 PageSize,消息队列 Kafka 版会分页返回数据。此参数用于展示当前返回的消息是否为全部符合条件的消息合集。​
​
​
​
请求示例​
​
POST /?Action=QueryMessageByTimestamp&Version=2022-05-01 HTTP/1.1​
Content-Type: application/json​
Host: kafka.volcengineapi.com​
X-Date: 20210328T100802Z​
Authorization: HMAC-SHA256 Credential=AK********/20210328/cn-beijing/kafka/request, SignedHeaders=x-date, Signature=********​
​
{​
"InstanceId": "kafka-cnaxxxxx",​
"TopicName": "test-topic",​
"PartitionId": 0,​
"QueryStartTimestamp": 1717415062840,​
"QueryEndTimestamp": 1717415962840,​
"PageNumber": 1,​
"PageSize": 16,​
"Refresh": false​
}​
​
返回示例​
​
{​
"ResponseMetadata": {​
"RequestId": "2024060511024265745BEBEC5C4***",​
"Action": "QueryMessageByTimestamp",​
"Version": "2022-05-01",​
"Service": "kafka",​
"Region": "cn-beijing"​
},​
"Result": {​
"HasMoreMessage": false,​
"MessageList": [​
{​
"CreateTime": 1717556541777,​
"Key": "doc-key",​
"Message": "test-message1",​
"MessageOffset": 0,​
"MessageSize": 13,​
"PartitionId": 0,​
"TopicName": "test-topic"​
},​
{​
"CreateTime": 1717556557043,​
"Key": "doc-key",​
"Message": "test-message2",​
"MessageOffset": 1,​
"MessageSize": 13,​
"PartitionId": 0,​
"TopicName": "test-topic"​
}​
]​
}​
}​
​
错误码​
下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。​
​
状态码​
错误码​
错误信息​
说明​
400​
MissingParameter​
The request body is missing a required parameter %s.​
缺少%s参数。​
400​
InvalidParameter.Unsupported​
The specified parameter %s is not supported.​
不支持%s参数。​
400​
Forbidden.Authentication​
This operation is forbidden by Realname Authentication system.​
账户未实名认证。​
400​
InvalidParameter.Malformed​
The specified parameter %s is Malformed.​
%s参数不符合规范。​
400​
OperationDenied.InstanceClosed​
The operation is not permitted due to the instance has overdue or expired.​
当前实例已关停,无法执行该操作。​
404​
InvalidInstance.NotFound​
The specified instance does not exist.​
该实例不存在。​
404​
InvalidTopicName.NotFound​
The specified topic does not exist.​
Topic 不存在。​
404​
InvalidInstanceId.NotFound​
The specified Instance ID does not exist.​
实例不存在。​
500​
InternalError​
The request failed due to some unknown error, exception or failure.​
内部错误,请稍后重试。​
​
​
最近更新时间:2025.08.08 17:47:28
这个页面对您有帮助吗?
有用
有用
无用
无用