TLS supports consuming data via consumer groups and provides a range of SDKs to manage consumer groups. This topic describes how to consume data using consumer groups in TLS.
Background information
TLS provides the ConsumeLogs OpenAPI interface for log consumption, supporting real-time access to log data collected on the server. When using the ConsumeLogs interface, you must consume log data based on the shard dimension. Plus, you need to specify the log topic ID, Shard ID, and starting and ending cursors during consumption. Therefore, the progress of log consumption depends on the read-write capability of each Shard. You also need to manually maintain the consumption progress. In scenarios where shards are auto split, the consumption logic and workflow become complex.
TLS offers the ConsumerGroup feature through the SDK. You can consume log data using consumer groups. When consuming logs via a consumer group, TLS automatically balances consumer capacity and progress and allocates shards. You do not need to manage the internal scheduling details, load balancing, or failover between consumers. You can just focus on your business logic.
Basic concepts
Limits
- Each project supports up to 150 consumer groups.
- A consumer group can consume multiple topics within the same project, but cross-project consumption is not supported.
Prerequisites
- AccessKey for Volcanoengine has been created and obtained.
- The access key (AccessKey) of the Volcanoengine account has full permissions for all APIs. We recommend using an IAM user for API operations and routine O&M. Before using an IAM user, the primary account should grant the IAM user the relevant consumer group permissions. For authorization examples, see Examples of custom permission policy.
Consume data with consumer group
TLS provides the Consumer asynchronous log consumption library, which supports consuming multiple log topics under the same project. Features include asynchronous consumption, high performance, retry on failure, and graceful shutdown. You can use TLS Go SDK overview, Java SDK overview or Python SDK overview to manage consumer groups and consume log data. Code examples
The following code uses the Go SDK to demonstrate how to create consumer groups and consumers, and how to consume logs using the SDK.
Configuration instructions
The TLS SDK allows you to configure various consumer group consumption settings, such as enabling sequential consumption and setting the consumer heartbeat interval. You can use these configurations to manage different consumption logics of consumer groups.
For example, in the Go SDK code example above, the log_consumer.GetDefaultConsumerConfig() function returns the consumer group’s default configuration consumerCfg, and shows how to configure basic information like Endpoint, Region, AccessKeyID, AccessKeySecret, as well as project ID and log topic IDs, consumer group name, and consumer name. In addition, you can use other fields in consumerCfg for further custom settings. Supported fields for consumerCfg are as follows.
LoggerConfig configuration description:
Troubleshooting
TLS SDK consumer group provides automatic retry for failed requests and automatic reporting of consumption progress checkpoints. Therefore, you only need to focus on implementing the business logic for handling each consumed LogGroupList.
View or reset consumption progress
You can check the current consumption progress at any time while consuming log data via the consumer. In offline data processing scenarios, if you need to consume log data from a past period or from a specific position, you can reset the consumption checkpoint for the consumer group to start consuming data from the specified position.
TLS console supports viewing consumption progress, resetting all consumption checkpoints for the consumer group on a subscribed topic, and resetting checkpoints for specific shards via API.
Tip
Before resetting the consumption checkpoint, stop the relevant consumer processes. If you reset all checkpoints for the consumer group, stop all consumers; otherwise, the reset will fail.
The relevant steps in the console are as follows:
- In the left navigation pane, select data processing > log consumption.
- On the SDK tab, find and expand the project containing the target consumer group, and then click the specified consumer group.
- View consumption checkpoint.
- Click the consumer group name in the left consumer group list to view the most recent consumption time for each consumer in each shard.
-
- Reset consumption checkpoint.
- Click the consumer group name in the left consumer group list.
- In the upper-right corner, click Reset checkpoint.
Related API