All Products
Search
Document Center

Function Compute:RocketMQ triggers

Last Updated:Apr 01, 2026

Use an ApsaraMQ for RocketMQ trigger to invoke a Function Compute function each time a message arrives in a topic. Function Compute integrates with ApsaraMQ for RocketMQ through EventBridge, which handles event routing and delivery. This topic walks you through creating a trigger, understanding the event payload, writing function code, and testing the setup.

How it works

When you create an ApsaraMQ for RocketMQ trigger in the Function Compute console, Function Compute automatically creates event streams in EventBridge based on your trigger configuration. After the trigger is active, messages arriving in the source topic are delivered to your function — individually or in batches, depending on your batch configuration.

ApsaraMQ for RocketMQ triggers are designed for end-to-end streaming data processing scenarios.

Limits

  • The ApsaraMQ for RocketMQ instance must reside in the same region as the Function Compute function.

  • If the number of event streams in your account reaches the upper limit, you cannot create additional ApsaraMQ for RocketMQ triggers. For quota information, see Limits.

Prerequisites

Before you begin, ensure that you have:

Step 1: Create a trigger

  1. Log on to the Function Compute console and go to the function details page.

  2. Click the Configurations tab, then click Create Trigger on the Triggers page.

  3. Configure the trigger parameters described in the following table, then click OK.

image
ParameterDescriptionExample
Consumer offsetThe offset from which ApsaraMQ for RocketMQ starts pulling messages. Valid values: Latest Offset (start from the most recent message), Earliest Offset (start from the oldest available message), Timestamp (start from a specific point in time).Latest Offset
Invocation methodHow the function is invoked when an event arrives. Sync Invocation: Function Compute runs the function and waits for a response before processing the next event or batch. Maximum payload: 32 MB. See Synchronous invocation. Async Invocation: Function Compute immediately moves on to the next event without waiting for the function to finish. Maximum payload: 128 KB. See Asynchronous invocation.Sync Invocation

For advanced settings such as push configuration, retry policies, and dead-letter queues, see Advanced features of triggers.

Step 2: (Optional) Configure test parameters

ApsaraMQ for RocketMQ delivers messages to your function as an event array. Before sending real messages, simulate trigger events to verify your function code.

  1. On the Code tab of the function details page, click the image.png icon next to Test Function and select Configure Test Parameters.

  2. In the Configure Test Parameters panel, click Create New Test Event or Modify Existing Test Event, enter a name and the event content, then click OK.

The following is a sample event payload containing two messages:

[
    {
        "id": "94ebc15f-f0db-4bbe-acce-56fb72fb****",
        "source": "RocketMQ-Function-rocketmq-trigger",
        "specversion": "1.0",
        "type": "mq:Topic:SendMessage",
        "datacontenttype": "application/json; charset=utf-8",
        "subject": "acs:mq:cn-hangzhou:164901546557****:MQ_INST_164901546557****_BXhFHryi%TopicName",
        "time": "2021-04-08T06:01:20.766Z",
        "aliyunaccountid": "164901546557****",
        "aliyunpublishtime": "2021-10-15T02:05:16.791Z",
        "aliyunoriginalaccountid": "164901546557****",
        "aliyuneventbusname": "RocketMQ-Function-rocketmq-trigger",
        "aliyunregionid": "cn-chengdu",
        "aliyunpublishaddr": "42.120.XX.XX",
        "data": {
            "topic": "TopicName",
            "systemProperties": {
                "MIN_OFFSET": "0",
                "TRACE_ON": "true",
                "MAX_OFFSET": "8",
                "MSG_REGION": "cn-hangzhou",
                "KEYS": "systemProperties.KEYS",
                "CONSUME_START_TIME": 1628577790396,
                "TAGS": "systemProperties.TAGS",
                "INSTANCE_ID": "MQ_INST_164901546557****_BXhFHryi"
            },
            "userProperties": {},
            "body": "TEST"
        }
    },
    {
        "id": "94ebc15f-f0db-4bbe-acce-56fb72fb****",
        "source": "RocketMQ-Function-rocketmq-trigger",
        "specversion": "1.0",
        "type": "mq:Topic:SendMessage",
        "datacontenttype": "application/json; charset=utf-8",
        "subject": "acs:mq:cn-hangzhou:164901546557****:MQ_INST_164901546557****_BXhFHryi%TopicName",
        "time": "2021-04-08T06:01:20.766Z",
        "aliyunaccountid": "164901546557****",
        "aliyunpublishtime": "2021-10-15T02:05:16.791Z",
        "aliyunoriginalaccountid": "164901546557****",
        "aliyuneventbusname": "RocketMQ-Function-rocketmq-trigger",
        "aliyunregionid": "cn-chengdu",
        "aliyunpublishaddr": "42.120.XX.XX",
        "data": {
            "topic": "TopicName",
            "systemProperties": {
                "MIN_OFFSET": "0",
                "TRACE_ON": "true",
                "MAX_OFFSET": "8",
                "MSG_REGION": "cn-hangzhou",
                "KEYS": "systemProperties.KEYS",
                "CONSUME_START_TIME": 1628577790396,
                "TAGS": "systemProperties.TAGS",
                "INSTANCE_ID": "MQ_INST_164901546557****_BXhFHryi"
            },
            "userProperties": {},
            "body": "TEST"
        }
    }
]

Each element in the array is a CloudEvents-formatted message. The top-level fields (id, source, specversion, and so on) follow the CloudEvents specification. For details, see Overview. The data object contains the RocketMQ message content:

FieldTypeExampleDescription
topicStringTopicNameThe topic name.
systemPropertiesMapRocketMQ system-level message properties.
systemProperties.MIN_OFFSETInt0The earliest offset in the queue.
systemProperties.TRACE_ONBooleantrueWhether a message trace exists.
systemProperties.MAX_OFFSETInt8The latest offset in the queue.
systemProperties.MSG_REGIONStringcn-hangzhouThe region where the message was sent.
systemProperties.KEYSStringsystemProperties.KEYSKeys used to filter the message.
systemProperties.CONSUME_START_TIMELong1628577790396Message consumption start time, in milliseconds.
systemProperties.UNIQ_KEYStringAC14C305069E1B28CDFA3181CDA2****The unique key of the message.
systemProperties.TAGSStringsystemProperties.TAGSTags used to filter the message.
systemProperties.INSTANCE_IDStringMQ_INST_123456789098****_BXhFHryiThe ApsaraMQ for RocketMQ instance ID.
userPropertiesMapThe user properties.
bodyStringTESTThe message body.

Step 3: Write and test your function

After the trigger is created, write your function code and test it.

Write function code

On the Code tab of the function details page, write your handler code and click Deploy Code.

The following Node.js example shows how to handle the event:

'use strict';

exports.handler = (event, context, callback) => {
  console.log("event: %s", event);
  // Parse the event parameters and process the event.
  callback(null, 'return result');
}

Test the function

Two methods are available:

Method 1: Simulate with test parameters

If you configured a test event in Step 2, click Test Function on the Code tab.

Method 2: Send a real message

Log on to the ApsaraMQ for RocketMQ console, select the topic you created, and click Send Message.

image

After the function runs, view the output in Real-time Logs.

image

What's next

  • To modify or delete this trigger, see Manage triggers.

  • To view the event streams created by this trigger, log on to the EventBridge console. See Overview.