All Products
Search
Document Center

ApsaraMQ for RocketMQ:Consume messages

Last Updated:Mar 10, 2026

Pull messages from an ApsaraMQ for RocketMQ topic over HTTP. The broker returns up to 16 messages per request in XML format. Each message includes the message body, an MD5 digest, a receipt handle for acknowledgment, timestamps, and message attributes.

Request

GET /topics/<TopicName>/messages?ns=<instance-id>&consumer=<group-id>&tag=<tag>&numOfMessages=<count>&waitseconds=<seconds> HTTP/1.1
Important

The total request line length must not exceed 1,024 characters.

Parameters

ParameterRequiredDescription
TopicNameYesTopic name to consume messages from.
nsConditionalInstance ID. Required for instances that have namespaces. Check the Instance Details page in the ApsaraMQ for RocketMQ console to determine whether your instance has a namespace. For more information, see Use instances.
consumerYesConsumer group ID.
tagNoMessage tag for filtering. Omit to pull all messages. Separate multiple tags with double vertical bars (||). Example: TagA||TagB.
numOfMessagesYesMaximum number of messages to return. Valid values: 1 to 16.
waitsecondsNoLong polling timeout in seconds. Valid values: 0 to 30. Set to 0 or omit for short polling. See Long polling vs. short polling.

Request body

None.

Instance types

ApsaraMQ for RocketMQ has two types of instances:

  • Default instance -- No namespace. Resource names must be globally unique.

  • New instance -- Has a namespace. Resource names only need to be unique within the instance.

Long polling vs. short polling

The waitseconds parameter controls how the broker handles requests when no messages are available.

ModeBehavior
Long polling (waitseconds > 0)The broker holds the request open until a message arrives or the timeout elapses.
Short polling (waitseconds = 0 or omitted)The broker responds immediately, even if no messages are available. The client must poll repeatedly.
Important

Short polling generates a high volume of empty responses when no messages are being produced, and each response incurs API call fees. Use long polling with a higher waitseconds value to reduce costs.

Response

Success (HTTP 200)

The broker returns one or more <Message> elements in XML. Each element contains the following fields:

ParameterTypeDescription
MessageIdStringUnique message ID.
MessageBodyMD5StringMD5 hash of the message body.
MessageBodyStringMessage body content.
ReceiptHandleStringHandle for acknowledging the message. Pass this handle to the acknowledge (delete) operation to confirm consumption. Single-use only -- expires at NextConsumeTime. A new handle is issued on each retry.
PublishTimeStringTime when the message was published. UNIX timestamp in milliseconds.
FirstConsumeTimeStringTime when the message was first consumed. UNIX timestamp in milliseconds.
NextConsumeTimeStringTime when the message becomes available for retry. UNIX timestamp in milliseconds.
ConsumedTimesStringNumber of consumption retries.
MessageTagStringMessage tag.
PropertiesStringSerialized message attributes in key-value format. See Message properties format.
Note

Over HTTP, non-ordered messages are retried every 5 minutes, and ordered messages are retried every 1 minute. Each message can be retried up to 288 times.

Message properties format

The Properties field uses the format key1:value1|key2:value2|key3:value3.

KeyTypeDescription
KEYSStringMessage key.
__STARTDELIVERTIMELongScheduled delivery time for a scheduled message. UNIX timestamp in milliseconds.
__TransCheckTLongDelay before the first transaction status check for a transactional message, in seconds. Valid values: 10 to 300.

No messages available (HTTP 404)

If no messages are available, the broker returns HTTP 404 with the error code MessageNotExist. This is expected behavior, not an error.

ParameterTypeDescription
CodeStringError code. MessageNotExist indicates no messages are available.
MessageStringError message.
RequestIdStringRequest ID.
HostIdStringHost that sent the request.

Sample responses

Messages available

<?xml version="1.0" ?>
<Messages xmlns="http://mq.aliyuncs.com/doc/v1">
  <Message>
    <MessageId>1E057D5E6EAD42A579937046FE17****</MessageId>
    <MessageBodyMD5>0CC175B9C0F1B6A831C399E26977****</MessageBodyMD5>
    <MessageBody>a</MessageBody>
    <ReceiptHandle>1E057D5E6EAD42A579937046FE17****-MTI5N****</ReceiptHandle>
    <PublishTime>1571742900759</PublishTime>
    <FirstConsumeTime>1571742902463</FirstConsumeTime>
    <NextConsumeTime>1571742922463</NextConsumeTime>
    <ConsumedTimes>1</ConsumedTimes>
    <MessageTag>Tag</MessageTag>
    <Properties>KEYS:MessageKey|__BORNHOST:30.5.**.**|</Properties>
  </Message>
  <Message>
    <MessageId>1E057D5E6EAD42A579937046FE17****</MessageId>
    <MessageBodyMD5>0CC175B9C0F1B6A831C399E26977****</MessageBodyMD5>
    <MessageBody>a</MessageBody>
    <ReceiptHandle>1E057D5E6EAD42A579937046FE17****-MTI5N****</ReceiptHandle>
    <PublishTime>1571742900759</PublishTime>
    <FirstConsumeTime>1571742902463</FirstConsumeTime>
    <NextConsumeTime>1571742922463</NextConsumeTime>
    <ConsumedTimes>1</ConsumedTimes>
    <MessageTag>Tag</MessageTag>
    <Properties>KEYS:MessageKey|__BORNHOST:30.5.**.**|</Properties>
  </Message>
</Messages>

No messages available

<?xml version="1.0" ?>
<Error xmlns="http://mq.aliyuncs.com/doc/v1">
  <Code>MessageNotExist</Code>
  <Message>Message not exist.</Message>
  <RequestId>5DAEE3FF463541AD6E0322EB</RequestId>
  <HostId>http://123.mqrest.cn-hangzhou.aliyuncs.com</HostId>
</Error>