Message retrieval lets you search for messages across topics by partition, offset range, time range, and keywords in message keys or values. Unlike the basic message query feature, which only supports lookup by offset or point in time, message retrieval provides full-text search powered by Tablestore indexing.
Prerequisites
Before you begin, make sure that:
A topic exists on your ApsaraMQ for Kafka instance as the data source. For more information, see Create a topic.
Message retrieval is available in the region where your instance resides. For more information, see Supported regions.
Serverless ApsaraMQ for Kafka instances do not support message retrieval.
How it works
Message retrieval uses the ApsaraMQ for Kafka connector feature to synchronize messages from a source topic to a Tablestore table, where they are indexed for full-text search.
When you enable message retrieval for a topic:
A connector is created to synchronize data from ApsaraMQ for Kafka to Tablestore. The connector name follows the format
ots-ms-{Topic name}-{Six random characters}.If this is the first time you enable message retrieval on the instance, Tablestore is automatically activated and a Tablestore instance is created in the same region. The service-linked role
AliyunServiceRoleForAlikafkaConnectoris also created if it does not already exist. For more information, see Service-linked roles.A Tablestore table is created for the topic.
Four internal topics and two consumer groups are created on the ApsaraMQ for Kafka instance to manage the connector.
Auto-created resources
Tablestore resources
| Resource | Naming format |
|---|---|
| Instance | kfk-{Last 12 characters of the ApsaraMQ for Kafka instance name} |
| Table | {Topic name}:kafka_topic_{Topic name}_{Six random characters} |
Internal Kafka resources (per topic)
| Resource | Naming format |
|---|---|
| Consumer offset topic | connect-offset-{Connector name} |
| Configuration topic | connect-config-{Connector name} |
| Status topic | connect-status-{Connector name} |
| Dead-letter queue topic | connect-error-{Connector name} |
| Consumer group | connect-{Connector name} |
| Task cluster group | connect-cluster-{Task name} |
Billing
Message retrieval is in public preview. During the preview period:
ApsaraMQ for Kafka does not charge for the message retrieval feature.
Auto-created Tablestore instances and tables are also free of charge.
No service level agreement (SLA) is provided for message retrieval during public preview. For SLA and billing details of other services involved, refer to the corresponding service documentation.
Limits
| Limit | Description |
|---|---|
| Topics per instance | Up to 3 topics per instance can have message retrieval enabled at the same time. |
| Message size | Messages larger than 2 MB cannot be synchronized or retrieved, because the STRING-type attribute column in Tablestore has a 2 MB size limit. |
| Data retention | Tablestore retains synchronized messages for the same duration as the message retention period configured on your ApsaraMQ for Kafka instance. After the retention period expires, Tablestore clears the messages and removes the related indexes. For more information, see Modify configurations for messages. |
| Search results | Up to 10 messages are displayed per search. Each message displays up to 1 KB of content in the console. Download the message to view the full content. |
The data expiration policies of Tablestore and ApsaraMQ for Kafka differ. As a result, retrieval results may not exactly match the specified search conditions. The actual retrieval results are authoritative.
Step 1: Enable message retrieval
Log on to the ApsaraMQ for Kafka console.
In the Resource Distribution section of the Overview page, select the region where your instance resides.
In the left-side navigation pane, click Instances.
On the Instances page, click the name of your instance.
In the left-side navigation pane, click Message Retrieval, then click Enable Message Retrieval.
NoteIf the connector feature has not been enabled on this instance, a prompt appears. Click OK to enable the connector feature, then configure the parameters in the Enable Message Retrieval panel.
In the Enable Message Retrieval panel, configure the following parameters and click OK. Record Time options:
Native Time: The message creation timestamp recorded by the producer -- either the timestamp from
ProducerRecordor the time when the producer sent the message.Instant Time: The time when the message was synchronized to Tablestore. This may differ from the actual production time.

After you enable message retrieval, the topic appears on the Message Retrieval page.
Step 2: Send a test message
To verify that the message retrieval task is running, send a test message.
On the Message Retrieval page, find your topic 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 following parameters and click OK:
Message Key: Enter a message key. Example:
demo.Message Content: Enter the message body. Example:
{"key": "test"}.Send to Specified Partition:
To send to a specific partition, select Yes and enter the partition ID. Example:
0. For more information about partition IDs, see View partition status.To let ApsaraMQ for Kafka assign a partition automatically, select No.
Step 3: Retrieve messages
On the Message Retrieval page, find your topic and click Search in the Actions column.
In the Search panel, select a search condition from the dropdown, click Add Search Condition, enter the value, and click OK. You can combine one or more of the following search conditions: Keyword search rules for Key and Value: For more information about search patterns, see Tokenization, Match phrase query, and Wildcard query.
Phrase matching (default): Enter a phrase to match. For example, if the message key is "ApsaraMQ for Kafka is a distributed, high-throughput, and scalable message queue service", search for
distributedor combineAlibaba Cloudanddistributed.Wildcard matching: Use
*for any string and?for any single character. Letters are case-insensitive. For example, search forAliKafkaTe*to matchAliKafkaTest001qaz. Strings containing wildcards must not exceed 20 characters. Avoid starting a search keyword with a wildcard character to improve retrieval efficiency.
NoteUse the unique business identifier as the message key when producing messages. This enables exact matching during retrieval.

On the Topic Search page, view the retrieval results.
NoteUp to 10 messages are displayed per search. Specify precise search conditions for accurate results. Each message displays up to 1 KB of content in the console. Download the message to view the full content.

Manage retrieval tasks
View task details
After you enable message retrieval for a topic, a retrieval task is created automatically. The Task Details page shows the auto-created topics, consumer groups, and Tablestore instance and table names. From this page, navigate directly to the Tablestore table details page.
On the Message Retrieval page, find your topic and click Details in the Actions column.

View consumption progress
Monitor the consumption progress of active groups across partitions to identify message consumption and accumulation.
On the Message Retrieval page, find your topic and click Consumption Progress in the Actions column. The Consumer Details page displays the consumption status per partition.

Suspend a retrieval task
On the Message Retrieval page, find your topic and choose More > Suspend in the Actions column.
In the confirmation dialog, click OK.
Resume a retrieval task
On the Message Retrieval page, find your topic and choose More > Enable in the Actions column.
In the confirmation dialog, click OK.
Delete a retrieval task
Deleting a retrieval task also deletes the associated Tablestore table and search index. The topic no longer supports message retrieval. To use message retrieval for this topic again, create a new retrieval task and wait for data synchronization to complete.
On the Message Retrieval page, find your topic and perform one of the following actions based on the task status:
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 More > Delete in the Actions column.
In the confirmation dialog, click OK.
After deletion, the topic no longer appears on the Message Retrieval page.