ApsaraMQ for Kafka provides the message query feature for you to query messages by offset or point in time in the ApsaraMQ for Kafka console. If this feature cannot meet your message query requirements, you can use the message retrieval feature provided by ApsaraMQ for Kafka. The message retrieval feature allows you to retrieve messages by partition, offset range, time range, and keyword of message keys and values. This topic describes how to enable the message retrieval feature and specify search conditions for a message retrieval task. This topic also describes how to suspend, resume, and delete a message retrieval task.
Prerequisites
A topic is created as the data source on your ApsaraMQ for Kafka instance. For more information, see Step 1: Create a topic.
NoteServerless ApsaraMQ for Kafka instances do not support the message retrieval feature.
The message retrieval feature is available in the region where the ApsaraMQ for Kafka instance resides. For information about the regions where the message retrieval feature is available, see Supported regions.
Background information
The message retrieval feature of ApsaraMQ for Kafka is based on the connector feature of ApsaraMQ for Kafka and the index feature of Tablestore. To be more specific, messages in the source topic are dumped to a connector and forwarded to a Tablestore table. Then, you can use the index feature provided by Tablestore to retrieve messages.
By enabling the message retrieval feature, you actually create a connector that is used to synchronize data from ApsaraMQ for Kafka to Tablestore. The connector name is in the ots-ms-{Topic name}-{Six random characters} format. For information about how to view the details of a message retrieval task, see View the details of a message retrieval task.
The first time you enable the message retrieval feature, ApsaraMQ for Kafka automatically activates Tablestore for you and creates a Tablestore instance and tables in the same region. One Tablestore table is created for each topic that has the message retrieval feature enabled. The names of the automatically created Tablestore instance and tables are in the following formats:
Instance name: kfk-{Last 12 characters of the name of the ApsaraMQ for Kafka instance}
Table name: {Topic name}:kafka_topic_{Topic name}_{Six random characters}
For each topic that has the message retrieval feature enabled, ApsaraMQ for Kafka automatically creates four topics and two groups on the corresponding instance. The topics and groups are used to record the configurations and status of the connector. The names of the created topics and groups are in the following formats:
The topic that is used to record the consumer offsets of the connector: connect-offset-{Connector name}
The topic that is used to record the configurations of the connector: connect-config-{Connector name}
The topic that is used to record the status of the connector: connect-status-{Connector name}
The topic that is used to record the data of the dead-letter queue and exceptions: connect-error-{Connector name}
Consumer group for the connector: connect-{Connector name}
Group for the task cluster: connect-cluster-{Task name}
Billing
The message retrieval feature of ApsaraMQ for Kafka is in public preview. ApsaraMQ for Kafka does not charge you for the message retrieval feature during the public preview.
During the public preview of the message retrieval feature, you are not charged for instances and tables that are automatically created in Tablestore.
Alibaba Cloud does not provide a service level agreement (SLA) for the message retrieval feature. For information about the SLAs and billing of other services that are required to use the message retrieval feature, see the documentation of the related services.
Usage notes
By default, you can enable the message retrieval feature for up to three topics on an ApsaraMQ for Kafka instance at the same time.
The value in an attribute column of the STRING type in Tablestore cannot exceed 2 MB. A message whose size exceeds 2 MB cannot be synchronized or retrieved.
Tablestore retains messages that are synchronized from an ApsaraMQ for Kafka instance for the same period of time as ApsaraMQ for Kafka retains messages. After the retention period expires, Tablestore automatically clears the messages and removes the related indexes. For information about the configuration and description of the message retention period in ApsaraMQ for Kafka, see Modify configurations for messages.
The data expiration policy of Tablestore is different from that of ApsaraMQ for Kafka. Therefore, the messages retrieved by each message retrieval task may be different from the messages that meet the specified search conditions. In this case, the final retrieval result shall prevail.
Procedure for message retrieval
Step 1: Enable the message retrieval feature
After you enable the message retrieval feature for a topic on an ApsaraMQ for Kafka instance, you can retrieve messages in the topic based on your business requirements.
The first time you enable the message retrieval feature for a topic on an ApsaraMQ for Kafka instance, ApsaraMQ for Kafka automatically creates a Tablestore instance that resides in the same region as the ApsaraMQ for Kafka instance.
The first time you enable the message retrieval feature for a topic on an ApsaraMQ for Kafka instance, ApsaraMQ for Kafka automatically creates the service-linked role AliyunServiceRoleForAlikafkaConnector to allow you to use the connector feature. If the service-linked role is created, ApsaraMQ for Kafka does not create the role again. For more information, see Service-linked roles.
Log on to the ApsaraMQ for Kafka console.
In the Resource Distribution section of the Overview page, select the region where the ApsaraMQ for Kafka instance that you want to manage resides.
In the left-side navigation pane, click Instances.
On the Instances page, click the name of the instance that you want to manage.
In the left-side navigation pane, click Message Retrieval. On the page that appears, click Enable Message Retrieval.
In the Enable Message Retrieval panel, configure the parameters and click OK.
NoteThe first time you enable the message retrieval feature for a topic on an ApsaraMQ for Kafka instance, a message indicating that you have not enabled the connector feature for the instance appears after you click Enable Message Retrieval. In this case, click OK in the message and then configure the parameters in the Enable Message Retrieval panel.
On the Message Retrieval page, you can view the topic for which you enabled the message retrieval feature.
Step 2: Send a test message
After you enable the message retrieval feature for a topic on an ApsaraMQ for Kafka instance, you can send messages to the topic to test whether the message retrieval task is created.
On the Message Retrieval page, find the topic that you want to manage and click Details in the Actions column.
In the upper-right corner of the Task Details page, click Test.
In the Send Message panel, configure the parameters and click OK.
In the Message Key field, enter the message key. Example: demo.
In the Message Content field, enter the message content. Example: {"key": "test"}.
Configure the Send to Specified Partition parameter to specify whether to send the test message to a specific partition.
If you want to send the test message to a specific partition, click Yes and enter the partition ID in the Partition ID field. Example: 0. For information about how to query partition IDs, see View partition status.
If you do not want to send the test message to a specific partition, click No.
Step 3: Retrieve messages
On the Message Retrieval page, find the topic that you want to manage and click Search in the Actions column.
In the Search panel, perform the following operations to specify a search condition: Select an item from the search condition drop-down list, click Add Search Condition, specify the search condition in the Value column, and then click OK.
NoteWhen you specify the search condition, you can select one or more values, including Partition, Offset Range, Time Range, Key, and Value.
We recommend that you use the unique business identifier as the key value when you send a message. This way, the message can be exactly matched during the search.
On the Topic Search page, view the retrieved messages.
NoteUp to 10 messages can be displayed in the retrieval result. We recommend that you specify accurate search conditions for exact match.
Up to 1 KB of content for each retrieved message can be displayed in the ApsaraMQ for Kafka console. If a retrieved message exceeds 1 KB in size, the system automatically truncates the content. If you want to view the complete message content, download the message.
Related operations
View the details of a message retrieval task
After you enable the message retrieval feature for a topic, a message retrieval task is automatically created. You can view the details of the task, such as the topics and groups that are automatically created on the ApsaraMQ for Kafka instance, and the names of the instance and tables that are automatically created in Tablestore. You can also navigate to the details page of the Tablestore table from the Task Details page.
On the Message Retrieval page, find the topic that you want to manage and click Details in the Actions column.
View consumption details
After you enable the message retrieval feature for a topic, you can view the consumption progress of the active groups in each partition of the topic. This helps you obtain information about message consumption and accumulation.
On the Message Retrieval page, find the topic that you want to manage and click Consumption Progress in the Actions column.
On the Consumer Details page, you can view the consumption status of the groups that subscribe to the topic in each partition of the topic.
Suspend a message retrieval task
On the Message Retrieval page, find the topic that you want to manage and choose in the Actions column.
In the message that appears, click OK.
Resume a message retrieval task
You can resume a suspended message retrieval task based on your business requirements.
On the Message Retrieval page, find the topic that you want to manage and choose in the Actions column.
In the message that appears, click OK.
Delete a message retrieval task
After you delete a message retrieval task for a topic, the relevant Tablestore table and search index are also deleted. The topic no longer provides the message retrieval feature. If you want to use the message retrieval feature for the topic again, re-create a message retrieval task and wait for data synchronization to complete.
On the Message Retrieval page, find the topic that you want to manage and perform one of the following operations based on the status of the message retrieval task:
If the task is not in the Running or Suspended state, click Delete in the Actions column.
If the task is in the Running or Suspended state, choose
in the Actions column.
In the message that appears, click OK.
On the Message Retrieval page, you can no longer view the topic for which the message retrieval task is deleted.