All Products
Search
Document Center

Function Compute:RabbitMQ triggers

Last Updated:Apr 01, 2026

ApsaraMQ for RabbitMQ triggers let you run a Function Compute function every time a message enters a RabbitMQ queue. The integration routes messages through EventBridge, so you can process them individually or in batches without managing any polling infrastructure.

How it works

When you create an ApsaraMQ for RabbitMQ trigger in the Function Compute console, Function Compute automatically creates an event stream in EventBridge. When a message is enqueued in the source RabbitMQ instance, EventBridge delivers it to your function as a CloudEvents-formatted event. Messages are pushed to your function one at a time or in batches, depending on your batch configuration.

You can view the trigger in the Function Compute console and the corresponding event stream resources in the EventBridge console.

ApsaraMQ for RabbitMQ triggers are suited for end-to-end streaming data processing scenarios.

Limitations

  • The ApsaraMQ for RabbitMQ instance and the Function Compute function must be in the same region.

  • If the number of event streams in your account reaches the quota, you cannot create additional triggers. For quota details, 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. The following figure shows the configuration panel.

    image

  4. Click OK.

Invocation method

Choose how Function Compute invokes your function when messages arrive:

MethodMax payloadBehaviorWhen to use
Sync Invocation32 MBProcesses one event or batch at a time; waits for the function to return before processing the nextSequential processing where order matters
Async Invocation128 KBReturns immediately and continues to the next event or batch; function runs in the backgroundHigh-throughput scenarios where speed of consumption matters more than sequential processing

For details, see Synchronous invocation and Asynchronous invocation.

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

After creation, the trigger appears on the Triggers tab. To modify or delete it, see Trigger management.

Step 2: (Optional) Configure test parameters

ApsaraMQ for RabbitMQ passes messages to your function as an event array. To test your function code without sending real messages, 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.

The following is a sample event payload containing two messages:

[
  {
    "id": "bj694332-4cj1-389e-9d8c-b137h30b****",
    "source": "RabbitMQ-Function-rabbitmq-trigger",
    "specversion": "1.0",
    "type": "amqp:Queue:SendMessage",
    "datacontenttype": "application/json;charset=utf-8",
    "subject": "acs:amqp:cn-hangzhou:164901546557****:/instances/amqp-cn-tl32e756****/vhosts/eb-connect/queues/housekeeping",
    "time": "2021-08-12T06:56:40.709Z",
    "aliyunaccountid": "164901546557****",
    "aliyunpublishtime": "2021-10-15T08:58:55.140Z",
    "aliyunoriginalaccountid": "164901546557****",
    "aliyuneventbusname": "RabbitMQ-Function-rabbitmq-trigger",
    "aliyunregionid": "cn-chengdu",
    "aliyunpublishaddr": "42.120.XX.XX",
    "data": {
      "envelope": {
        "deliveryTag": 98,
        "exchange": "",
        "redeliver": false,
        "routingKey": "housekeeping"
      },
      "body": {
        "Hello": "RabbitMQ"
      },
      "props": {
        "contentEncoding": "UTF-8",
        "messageId": "f7622d51-e198-41de-a072-77c1ead7****"
      }
    }
  },
  {
    "id": "bj694332-4cj1-389e-9d8c-b137h30b****",
    "source": "RabbitMQ-Function-rabbitmq-trigger",
    "specversion": "1.0",
    "type": "amqp:Queue:SendMessage",
    "datacontenttype": "application/json;charset=utf-8",
    "subject": "acs:amqp:cn-hangzhou:164901546557****:/instances/amqp-cn-tl32e756****/vhosts/eb-connect/queues/housekeeping",
    "time": "2021-08-12T06:56:40.709Z",
    "aliyunaccountid": "164901546557****",
    "aliyunpublishtime": "2021-10-15T08:58:55.140Z",
    "aliyunoriginalaccountid": "164901546557****",
    "aliyuneventbusname": "RabbitMQ-Function-rabbitmq-trigger",
    "aliyunregionid": "cn-chengdu",
    "aliyunpublishaddr": "42.120.XX.XX",
    "data": {
      "envelope": {
        "deliveryTag": 98,
        "exchange": "",
        "redeliver": false,
        "routingKey": "housekeeping"
      },
      "body": {
        "Hello": "RabbitMQ"
      },
      "props": {
        "contentEncoding": "UTF-8",
        "messageId": "f7622d51-e198-41de-a072-77c1ead7****"
      }
    }
  }
]

The outer array contains one object per message in the batch. The top-level fields follow the CloudEvents specification. The data field carries the RabbitMQ-specific content:

`data` field parameters

ParameterTypeExampleDescription
bodyMapMessage body containing user-defined content
HelloStringEventBridgeUser data within the message body
propsMapMessage attributes
contentEncodingStringutf-8Encoding of the message body
messageIdStringf7622d51-e198-41de-a072-77c1ead7****Unique message ID
envelopeMapAMQP envelope metadata
deliveryTagInt98Delivery tag assigned by the broker
exchangeString The name of the exchange that sends the message
redeliverBooleanfalseSpecifies whether the message can be resent. Valid values: true or false
routingKeyStringhousekeepingRouting key used to deliver the message to the queue

Step 3: Write and test function code

Write code in the editor to parse and process the event array your function receives. Deploy it, then test it using one of the two methods below.

  1. On the Code tab, write your function code and click Deploy Code. The following Node.js example logs the raw event and returns a result:

    '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 the event parameters and process the event.
      callback(null, 'return result');
    }
  2. Test the function using one of these methods:

    • Simulated event: Click Test Function to run with the test parameters you configured in Step 2.

    • Real message: Log on to the ApsaraMQ for RabbitMQ console, select your queue, and click Send Message to publish a message. The trigger fires automatically.

      image

  3. After execution, check the result in Real-time Logs.

    image

What's next