All Products
Search
Document Center

Function Compute:Self-managed Apache RocketMQ triggers

Last Updated:Apr 01, 2026

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:

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

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function you want to manage.

  3. On the function details page, click the Trigger tab, then click Create Trigger.

  4. In the Create Trigger panel, configure the parameters described in the following table, then click OK.

ParameterDescriptionRequiredDefaultExample
Trigger typeSelect Self-built Apache RocketMQ.YesSelf-built Apache RocketMQ
NameEnter a name for the trigger.Yesapache-rocketmq-trigger
Version or aliasThe 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.NoLATESTLATEST
EndpointThe NameServer address of your RocketMQ cluster.Yes192.168.X.X:9876
TopicThe topic in your RocketMQ instance to consume messages from.YestestTopic
Group IDThe consumer group ID in your RocketMQ instance.YestestGroup
Filter typeThe message filtering method: Tag filters by tag; SQL filters by an SQL expression that matches message properties and values.YesTag
FilterThe filter expression corresponding to the selected filter type.YesTagA
Authentication modeThe authentication mode. Only ACL is supported.YesACL
UsernameThe ACL username. Required when Authentication mode is ACL.Yesadmin
PasswordThe ACL password. Required when Authentication mode is ACL.Yes******
Consumer offsetThe 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.YesLatest offset
NetworkingThe 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).YesInternet
Invocation methodHow 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).NoSync invocationSync invocation
Trigger stateWhether to enable the trigger immediately after creation.NoEnabledEnabled

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.

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

FieldTypeDescriptionExample
msgIdStringThe message ID assigned by Apache RocketMQ.7F0000010BDD2A84AEE70DA49B57****
topicStringThe topic name.testTopic
systemPropertiesMapSystem-level properties set by RocketMQ.
systemProperties.UNIQ_KEYStringThe unique key of the message.7F0000010BDD2A84AEE70DA49B57****
systemProperties.CLUSTERStringThe name of the RocketMQ cluster.DefaultCluster
systemProperties.MIN_OFFSETIntegerThe minimum offset in the topic queue.0
systemProperties.MAX_OFFSETIntegerThe maximum offset in the topic queue.128
systemProperties.TAGSStringThe filter tag applied to the message.TagA
userPropertiesMapCustom properties set by the message producer.{}
bodyStringThe 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.

  1. 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');
    }
  2. 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:

To modify or delete an existing trigger, see Manage triggers.