All Products
Search
Document Center

ApsaraMQ for Kafka:Message retrieval

Last Updated:Feb 28, 2026

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.

Note

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:

  1. 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}.

  2. 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 AliyunServiceRoleForAlikafkaConnector is also created if it does not already exist. For more information, see Service-linked roles.

  3. A Tablestore table is created for the topic.

  4. Four internal topics and two consumer groups are created on the ApsaraMQ for Kafka instance to manage the connector.

Auto-created resources

Tablestore resources

ResourceNaming format
Instancekfk-{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)

ResourceNaming format
Consumer offset topicconnect-offset-{Connector name}
Configuration topicconnect-config-{Connector name}
Status topicconnect-status-{Connector name}
Dead-letter queue topicconnect-error-{Connector name}
Consumer groupconnect-{Connector name}
Task cluster groupconnect-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.

Important

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

LimitDescription
Topics per instanceUp to 3 topics per instance can have message retrieval enabled at the same time.
Message sizeMessages larger than 2 MB cannot be synchronized or retrieved, because the STRING-type attribute column in Tablestore has a 2 MB size limit.
Data retentionTablestore 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 resultsUp 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.
Note

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

  1. Log on to the ApsaraMQ for Kafka console.

  2. In the Resource Distribution section of the Overview page, select the region where your instance resides.

  3. In the left-side navigation pane, click Instances.

  4. On the Instances page, click the name of your instance.

  5. In the left-side navigation pane, click Message Retrieval, then click Enable Message Retrieval.

    Note

    If 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.

  6. 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 ProducerRecord or 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.

    Parameters for enabling the message retrieval feature

    ParameterDescriptionExample
    Data Source TopicThe topic to enable message retrieval for.test
    Consumer OffsetThe offset from which to start consuming messages. Valid values: Earliest Offset and Latest Offset. Default: Latest Offset.Latest Offset
    Record TimeThe timestamp associated with each retrieved message. Valid values: Native Time and Instant Time. Default: Native Time.Native Time
image

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.

  1. On the Message Retrieval page, find your topic and click Details in the Actions column.

  2. In the upper-right corner of the Task Details page, click Test.

  3. 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

  1. On the Message Retrieval page, find your topic and click Search in the Actions column.

  2. 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 distributed or combine Alibaba Cloud and distributed.

    • Wildcard matching: Use * for any string and ? for any single character. Letters are case-insensitive. For example, search for AliKafkaTe* to match AliKafkaTest001qaz. Strings containing wildcards must not exceed 20 characters. Avoid starting a search keyword with a wildcard character to improve retrieval efficiency.

    Note

    Use the unique business identifier as the message key when producing messages. This enables exact matching during retrieval.

    Search parameters

    Search conditionDescription
    PartitionThe partition to search.
    Offset RangeThe offset range to search within.
    Time RangeThe time range to search within. Select from the last three days or specify a custom range, accurate to the minute.
    KeyA keyword to match against message keys.
    ValueA keyword to match against message values.

    image

  3. On the Topic Search page, view the retrieval results.

    Note

    Up 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.

    Parameters in the retrieval result

    ColumnDescription
    PartitionThe partition from which the message was retrieved.
    OffsetThe message offset within the partition.
    KeyThe message key, displayed as a string.
    ValueThe message value (content), displayed as a string.
    Created AtThe message timestamp. If you specified a value for the timestamp field, that value is displayed. Otherwise, the local system time when the message was sent is displayed. A value in the format 1970/x/x x:x:x indicates the timestamp field was set to 0 or an invalid value.
    ActionsClick Download Key to download the message key, or Download Value to download the full message content.

    image

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.

image

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.

image

Suspend a retrieval task

  1. On the Message Retrieval page, find your topic and choose More > Suspend in the Actions column.

  2. In the confirmation dialog, click OK.

Resume a retrieval task

  1. On the Message Retrieval page, find your topic and choose More > Enable in the Actions column.

  2. 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.

  1. 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.

  2. In the confirmation dialog, click OK.

After deletion, the topic no longer appears on the Message Retrieval page.