Connect a self-managed Apache RocketMQ cluster to Function Compute through EventBridge to process messages with custom function code. When messages arrive in your RocketMQ topic, the trigger automatically invokes your function — passing one or more messages per invocation based on your batching configuration.
How it works
When you create a trigger in Function Compute, Function Compute automatically creates a corresponding event stream in EventBridge based on your configuration. View the trigger details in the Function Compute console and the automatically created resources in the EventBridge console.
Prerequisites
Before you begin, ensure that you have:
EventBridge activated with the required permissions granted
A self-managed Apache RocketMQ cluster deployed and accessible. To quickly deploy a cluster and start sending and receiving messages, see the quick start for your version:
Apache RocketMQ 5.0: Quick startQuick start
Apache RocketMQ 4.x: Quick startQuick start
A topic created in your RocketMQ instance
A consumer group created in your RocketMQ instance
Limitations
The RocketMQ instance must be accessible over the public internet or from an Alibaba Cloud Virtual Private Cloud (VPC).
If the instance is accessed from a VPC, the VPC must be in the same region as your function. Make sure the security group allows inbound traffic on the RocketMQ NameServer port (default: 9876).
The number of RocketMQ triggers is limited by the EventBridge event stream quota. For details, see Limits.
Step 1: Create a trigger
Log on to the Function Compute console. In the left-side navigation pane, click Functions.
In the top navigation bar, select a region. On the Functions page, click the function you want to manage.
On the function details page, click the Trigger tab, then click Create Trigger.
In the Create Trigger panel, configure the parameters described in the following table, then click OK.
| Parameter | Description | Required | Default | Example |
|---|---|---|---|---|
| Trigger type | Select Self-built Apache RocketMQ. | Yes | — | Self-built Apache RocketMQ |
| Name | Enter a name for the trigger. | Yes | — | apache-rocketmq-trigger |
| Version or alias | The function version or alias to associate with the trigger. To use a specific version or alias, switch to it first on the function details page. See Manage versions and Manage aliases. | No | LATEST | LATEST |
| Endpoint | The NameServer address of your RocketMQ cluster. | Yes | — | 192.168.X.X:9876 |
| Topic | The topic in your RocketMQ instance to consume messages from. | Yes | — | testTopic |
| Group ID | The consumer group ID in your RocketMQ instance. | Yes | — | testGroup |
| Filter type | The message filtering method: Tag filters by tag; SQL filters by an SQL expression that matches message properties and values. | Yes | — | Tag |
| Filter | The filter expression corresponding to the selected filter type. | Yes | — | TagA |
| Authentication mode | The authentication mode. Only ACL is supported. | Yes | — | ACL |
| Username | The ACL username. Required when Authentication mode is ACL. | Yes | — | admin |
| Password | The ACL password. Required when Authentication mode is ACL. | Yes | — | ****** |
| Consumer offset | The starting point for message consumption: Latest offset starts from the latest message; Earliest offset starts from the oldest message; Timestamp starts from a specific point in time. | Yes | — | Latest offset |
| Networking | The network type for connecting to your RocketMQ cluster: Internet accesses the cluster over the public internet; VPC accesses the cluster through a VPC (requires selecting the VPC, vSwitch, and security group). | Yes | — | Internet |
| Invocation method | How the trigger invokes your function: Sync invocation waits for the function to complete and returns the result (see Synchronous invocations); Async invocation returns immediately without waiting for the result, suitable for long-running functions (see Asynchronous invocation overview). | No | Sync invocation | Sync invocation |
| Trigger state | Whether to enable the trigger immediately after creation. | No | Enabled | Enabled |
For advanced settings such as push configurations, retry policies, and dead-letter queues, see Advanced features of triggers.
After the trigger is created, it appears on the Triggers tab. To modify or delete it, see Manage triggers.
Step 2: Configure a test event
The trigger passes messages from RocketMQ to your function as an array of event objects. Simulate a trigger invocation by manually configuring a test event.
On the Code tab of the function details page, click the
icon next to Test Function and select Configure Test Parameters.In the Configure Test Parameters panel, select Create new test event or Modify existing test event. Enter an event name, paste the event content below, and click OK.
[
{
"msgId": "7F0000010BDD2A84AEE70DA49B57****",
"topic": "testTopic",
"systemProperties": {
"UNIQ_KEY": "7F0000010BDD2A84AEE70DA49B57****",
"CLUSTER": "DefaultCluster",
"MIN_OFFSET": "0",
"TAGS": "TagA",
"MAX_OFFSET": "128"
},
"userProperties": {},
"body": "Hello RocketMQ"
}
]Each object in the array represents one RocketMQ message. The fields are described below.
| Field | Type | Description | Example |
|---|---|---|---|
msgId | String | The message ID assigned by Apache RocketMQ. | 7F0000010BDD2A84AEE70DA49B57**** |
topic | String | The topic name. | testTopic |
systemProperties | Map | System-level properties set by RocketMQ. | — |
systemProperties.UNIQ_KEY | String | The unique key of the message. | 7F0000010BDD2A84AEE70DA49B57**** |
systemProperties.CLUSTER | String | The name of the RocketMQ cluster. | DefaultCluster |
systemProperties.MIN_OFFSET | Integer | The minimum offset in the topic queue. | 0 |
systemProperties.MAX_OFFSET | Integer | The maximum offset in the topic queue. | 128 |
systemProperties.TAGS | String | The filter tag applied to the message. | TagA |
userProperties | Map | Custom properties set by the message producer. | {} |
body | String | The message body. | Hello RocketMQ |
Step 3: Write and test the function code
After the trigger is created, write your function code to process incoming messages. In production, the trigger automatically invokes the function when RocketMQ receives a new message.
On the Code tab of the function details page, write your code in the editor and click Deploy. The following Node.js example reads the event and returns a result:
'use strict'; /* To enable the initializer feature, implement the initializer function as shown below: exports.initializer = (context, callback) => { console.log('initializing'); callback(null, ''); }; */ exports.handler = (event, context, callback) => { console.log("event: %s", event); // Parse the event and process each message. callback(null, 'return result'); }Click Test Function to run the test event you configured in the previous step.
What's next
In addition to the Function Compute console, configure and manage triggers using:
Serverless Devs: See Common Serverless Devs commands
SDKs: See SDKs
To modify or delete an existing trigger, see Manage triggers.