All Products
Search
Document Center

ApsaraMQ for Kafka:UpdateConsumerOffset

Last Updated:Apr 12, 2024

Resets the consumer offsets of the subscribed topics of a consumer group.

Operation description

You can call this operation to reset the consumer offset of a specific consumer group. You can use the timestamp or offset parameter to reset the consumer offset of a consumer group. You can implement the following features by configuring a combination of different parameters:

  • Reset the consumer offsets of one or all subscribed topics of a consumer group to the latest offset. This way, you can consume messages in the topics from the latest offset.
  • Reset the consumer offsets of one or all subscribed topics of a consumer group to a specific point in time. This way, you can consume messages in the topics from the specified point in time.
  • Reset the consumer offset of one subscribed topic of a consumer group to a specific offset in a specific partition. This way, you can consume messages from the specified offset in the specified partition.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
alikafka:UpdateGroupWrite
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The instance ID.

alikafka_post-cn-mp91inkw****
TopicstringYes

The topic name.

  • The name can contain letters, digits, underscores (_), and hyphens (-).
  • The name must be 3 to 64 characters in length. If a name contains more than 64 characters, the name is automatically truncated.
  • The name of a topic cannot be changed after the topic is created.

**If you want to reset the consumer offsets of all topics to which the consumer subscribes, specify an empty string.

topic_name
RegionIdstringYes

The region ID of the instance to which the consumer group belongs.

cn-hangzhou
ConsumerIdstringYes

The name of the consumer group.

  • The name can contain letters, digits, hyphens (-), and underscores (_).
  • The name must be 3 to 64 characters in length. If a name contains more than 64 characters, the name is automatically truncated.
  • The name of a consumer group cannot be changed after the consumer group is created.
kafka-test
ResetTypestringNo

The method that is used to reset the consumer offsets of the subscribed topics of a consumer group. Valid values:

  • timestamp (default)
  • offset
timestamp
TimestringNo

The point in time when message consumption starts. The value of this parameter is a UNIX timestamp in milliseconds. The value of this parameter must be less than 0 or within the retention period of the consumer offset. This parameter takes effect only if you set resetType to timestamp.

  • If you want to reset the consumer offset to the latest offset, set this parameter to -1.
  • If you want to reset the consumer offset to the earliest offset, set this parameter to -2.
-1
Offsetsobject []No

If you set resetType to offset, you can use this parameter to reset the consumer offset of each partition of a specific topic in the consumer group.

PartitionintegerNo

The partition ID.

0
OffsetlongNo

The consumer offset of the partition.

1

a. If you want to reset the consumer offsets of all subscribed topics of a consumer group to the latest offset, set Time to a value that is less than 0. We recommend that you use -1 as the value. Sample code:

{
  "RegionId":"cn-beijing",
  "InstanceId":"alikafka_post-cn-xxxxxx",
  "Topic":"",
  "ConsumerId":"ConsumerGroup1",
  "ResetType": timestamp,
  "Time":-1,
  "Offsets": null
}

b. If you want to reset the consumer offsets of all subscribed topics of a consumer group to a specific point in time, set Time to a UNIX timestamp in milliseconds. Sample code:

{
  "RegionId":"cn-beijing",
  "InstanceId":"alikafka_post-cn-xxxxxx",
  "Topic":"",
  "ConsumerId":"ConsumerGroup1",
  "ResetType": timestamp,
  "Time":1679587200000,
  "Offsets": null
}

c. If you want to reset the consumer offset of a specific subscribed topic of a consumer group to the latest offset, set Time to a value that is less than 0. We recommend that you use -1 as the value. Sample code:

{
  "RegionId":"cn-beijing",
  "InstanceId":"alikafka_post-cn-xxxxxx",
  "Topic":"topic1",
  "ConsumerId":"ConsumerGroup1",
  "ResetType": timestamp,
  "Time":-1,
  "Offsets": null
}

d. If you want to reset the consumer offset of a specific subscribed topic of a consumer group to a point in time that is specified by Time, set Time to a UNIX timestamp in milliseconds. Sample code:

{
  "RegionId":"cn-beijing",
  "InstanceId":"alikafka_post-cn-xxxxxxx",
  "Topic":"topic1",
  "ConsumerId":"ConsumerG1",
  "ResetType": timestamp,
  "Time":1679587200000,
  "Offsets": null
}

e. If you want to reset the consumer offset of a specific subscribed topic of a consumer group to a specific offset in a specific partition, refer to the following sample code:

{
  "RegionId":"cn-beijing",
  "InstanceId":"alikafka_post-cn-xxxxxxx",
  "Topic":"topic1",
  "ConsumerId":"ConsumerG1",
  "Time":-1,
  "ResetType":"offset",
  "Offsets":"[{\"partition\":1,\"offset\":1},{\"partition\":2,\"offset\":2},{\"partition\":3,\"offset\":3}]"
}

Response parameters

ParameterTypeDescriptionExample
object
Successboolean

Indicates whether the call was successful.

true
RequestIdstring

The request ID.

56729737-C428-4E1B-AC68-7A8C2D5****
Codeinteger

The HTTP status code that is returned. The status code 200 indicates that the request is successful.

200
Messagestring

The returned message.

operation success

Examples

Sample success responses

JSONformat

{
  "Success": true,
  "RequestId": "56729737-C428-4E1B-AC68-7A8C2D5****",
  "Code": 200,
  "Message": "operation success"
}

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-03-15The internal configuration of the API is changed, but the call is not affectedsee changesets
Change itemChange content
The internal configuration of the API is changed, but the call is not affected.