All Products
Search
Document Center

Function Compute:Simple Message Queue (formerly MNS) queue triggers

Last Updated:Apr 01, 2026

Simple Message Queue (formerly MNS) queue triggers let you run a Function Compute function automatically whenever a message arrives in a queue. The trigger is backed by EventBridge: when you create the trigger in the Function Compute console, Function Compute creates the required event streams in EventBridge on your behalf. For details on event streams, see Overview.

Once the trigger is active, each message enqueued in the source queue causes the associated function to execute. Messages are delivered individually or in batches, depending on your batch configuration. This pattern suits end-to-end streaming data processing.

Constraints

  • The Simple Message Queue (formerly MNS) queue and the Function Compute function must be in the same region.

  • If your Alibaba Cloud account reaches the EventBridge event-stream limit, you cannot create additional Simple Message Queue (formerly MNS) queue triggers. For current limits, see Limits.

Prerequisites

Before you begin, ensure that you have:

Step 1: Create a trigger

  1. Log on to the Function Compute console and click the function you want to use.

  2. On the function details page, click the Configurations tab, then go to Triggers and click Create Trigger.

  3. Fill in the trigger settings. The key field is Invocation Method: For details, see Synchronous invocation and Asynchronous invocation.

    Invocation methodBehaviorMax payloadWhen to use
    Sync InvocationFunction Compute waits for the function to return before delivering the next event or batch32 MBOrder or sequential processing matters
    Async InvocationFunction Compute delivers the event and immediately moves to the next one; the function runs in the background128 KBHigh-throughput scenarios where you want to consume events quickly
  4. Click OK.

image

For advanced settings such as push settings, 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: (Optional) Configure test parameters

The function receives Simple Message Queue (formerly MNS) events as an event parameter — an array of CloudEvents-formatted objects. To test your function code without sending a real message, simulate the event manually.

  1. On the Code tab, 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 an event name and the event content below, then click OK.

Sample event payload:

[
  {
    "id": "c2g71017-6f65-fhcf-a814-a396fc8d****",
    "source": "MNS-Function-mnstrigger",
    "specversion": "1.0",
    "type": "mns:Queue:SendMessage",
    "datacontenttype": "application/json; charset=utf-8",
    "subject": "acs:mns:cn-hangzhou:164901546557****:queues/zeus",
    "time": "2021-04-08T06:28:17.093Z",
    "aliyunaccountid": "164901546557****",
    "aliyunpublishtime": "2021-10-15T07:06:34.028Z",
    "aliyunoriginalaccountid": "164901546557****",
    "aliyuneventbusname": "MNS-Function-mnstrigger",
    "aliyunregionid": "cn-chengdu",
    "aliyunpublishaddr": "42.120.XX.XX",
    "data": {
      "requestId": "606EA3074344430D4C81****",
      "messageId": "C6DB60D1574661357FA227277445****",
      "messageBody": "TEST"
    }
  },
  {
    "id": "d2g71017-6f65-fhcf-a814-a396fc8d****",
    "source": "MNS-Function-mnstrigger",
    "specversion": "1.0",
    "type": "mns:Queue:SendMessage",
    "datacontenttype": "application/json; charset=utf-8",
    "subject": "acs:mns:cn-hangzhou:164901546557****:queues/zeus",
    "time": "2021-04-08T06:28:17.093Z",
    "aliyunaccountid": "164901546557****",
    "aliyunpublishtime": "2021-10-15T07:06:34.028Z",
    "aliyunoriginalaccountid": "164901546557****",
    "aliyuneventbusname": "MNS-Function-mnstrigger",
    "aliyunregionid": "cn-chengdu",
    "aliyunpublishaddr": "42.120.XX.XX",
    "data": {
      "requestId": "606EA3074344430D4C81****",
      "messageId": "C6DB60D1574661357FA227277445****",
      "messageBody": "TEST"
    }
  }
]

Event field reference

Each element in the array follows the CloudEvents specification.

CloudEvents envelope fields

FieldTypeExampleDescription
idStringc2g71017-6f65-fhcf-a814-a396fc8d****Unique event ID
sourceStringMNS-Function-mnstriggerEvent source identifier (the event bus name)
typeStringmns:Queue:SendMessageEvent type
subjectStringacs:mns:cn-hangzhou:...:queues/zeusARN of the source queue
timeString2021-04-08T06:28:17.093ZTime the message was enqueued (ISO 8601)
specversionString1.0CloudEvents specification version
datacontenttypeStringapplication/json; charset=utf-8Content type of the data field
aliyunregionidStringcn-chengduRegion where the queue resides
aliyunaccountidString164901546557****Alibaba Cloud account ID
aliyunpublishtimeString2021-10-15T07:06:34.028ZTime EventBridge published the event

`data` fields

FieldTypeExampleDescription
requestIdString606EA3074344430D4C81****Unique ID of the send-message request
messageIdStringC6DB60D1574661357FA227277445****Unique ID of the message
messageBodyStringTESTMessage body content

Step 3: Write and test the function

After the trigger is created, write your function code, deploy it, then verify that the trigger works end-to-end.

Write and deploy function code

On the Code tab, write your handler and click Deploy Code.

The following Node.js example shows how to write function code:

'use strict';
/*
To enable the initializer feature
please implement the initializer function as below:
exports.initializer = (context, callback) => {
  console.log('initializing');
  callback(null, '');
};
*/
exports.handler = (event, context, callback) => {
  console.log("event: %s", event);
  // Parse and process event.
  callback(null, 'return result');
}

Test the function

Use either method:

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

  • Real message: Log on to the Simple Message Queue (formerly MNS) console, select the source queue, and click Send Message.

image

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

image

What's next