All Products
Search
Document Center

EventBridge:Route events to Simple Message Queue (formerly MNS)

Last Updated:Mar 11, 2026

This tutorial walks you through creating a custom event source, defining an event rule with a filter pattern, and routing matched events to a Simple Message Queue (formerly MNS) (SMQ) queue. You then publish a test event and verify it arrives in the queue.

Prerequisites

Before you begin, make sure that you have:

Important

Event targets must reside in the same region as the event rule. Create your SMQ queue in the same region where you plan to create the event rule.

Step 1: Create a custom event source

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Buses.

  3. In the top navigation bar, select a region.

  4. On the Event Buses page, click the name of the custom event bus that you want to manage.

  5. In the left-side navigation pane, click Event Sources, and then click Add Event Source.

  6. In the Add Custom Event Source panel, configure the following settings and click OK:

    • Name: Enter a name for the event source.

    • Description: Enter a description.

    • Event Provider: Select Custom Application.

Step 2: Create an event rule

An event rule defines which events to match (the event pattern) and where to send them (the event target). In this step, you create a rule that filters events from the custom event source and routes them to an SMQ queue.

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Buses.

  3. In the top navigation bar, select a region.

  4. On the Event Buses page, click the name of the event bus that you want to manage.

  5. In the left-side navigation pane, click Event Rules, and then click Create Rule.

  6. In the Create Rule wizard, complete the following steps:

    1. a. Configure basic info

      Enter a rule name in the Name field and a description in the Description field. Click Next Step.

    2. b. Configure event pattern

      • Set Event Source Type to Custom Event Source.

      • From the Event Source drop-down list, select the custom event source you created in Step 1.

      • In the Pattern Content code editor, specify an event pattern.

        The event pattern defines which events match this rule. For example, the following pattern matches all events where source is my.custom.app:

        {
          "source": ["my.custom.app"]
        }

        For the full pattern syntax, see Event patterns.

      Click Next Step.

    3. c. Configure targets

      Note

      Each event rule supports up to five event targets.

      Important

      When you receive events through SMQ SDK for Java, the message body is not Base64-encoded, which causes garbled characters. Use the getMessageBodyAsRawBytes or getMessageBodyAsRawString method to retrieve the event body correctly.

      Configure the following settings:

      • Service Type: Select SMQ.

      • Queue: Select the SMQ queue you created.

      • Message Body: Select Template.

        Define variables and a template to transform the event before delivery. The variables extract values from the event JSON using JSONPath expressions, and the template assembles them into the final message body.

        Sample variables:

        {
          "source": "$.source"
        }

        Sample template:

        The event comes from ${source} is abnormal.

        The following table shows additional transformation examples:

        ScenarioVariablesTemplateOutputSimple string{"source": "$.source"}The event from ${source} is abnormal.The event from my.custom.app is abnormal.JSON output{"source": "$.source", "type": "$.type"}{"src": "${source}", "eventType": "${type}"}{"src": "my.custom.app", "eventType": "custom:MyEvent"}

        For the full transformation syntax, see Event transformation.

      Click Create.

Step 3: Publish a test event

Note

The EventBridge console only supports publishing events to custom event buses.

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Buses.

  3. In the top navigation bar, select a region.

  4. On the Event Buses page, find the target event bus and click Publish Event in the Operations column.

  5. In the Publish Event to Custom Event Bus panel, configure the following settings:

    • Custom Event Source: Select the event source you created in Step 1.

    • Event Body: Enter an event in JSON format. For example:

      {
        "id": "demo-event-001",
        "source": "my.custom.app",
        "specversion": "1.0",
        "type": "custom:MyEvent",
        "datacontenttype": "application/json",
        "data": {
          "name": "EventBridge",
          "action": "test"
        }
      }

      For details on event attributes, see Overview.

  6. Click OK.

Step 4: Verify the result

After publishing the event, confirm that it arrived in the SMQ queue.

  1. Log on to the SMQ console.

  2. In the left-side navigation pane, choose Queue Model > Queues.

  3. In the top navigation bar, select the same region as your event rule.

  4. On the Queues page, find the target queue and choose More > Send Messages in the Actions column.

  5. In the Receive Message section of the Quick Experience page, click Receive Message.

A successfully received event looks similar to the following:

{
    "id": "22h0iaji-8cf5-2iea-j4a6-i99a5j1a****",
    "source": "acs.oss",
    "specversion": "1.0",
    "type": "oss:ObjectCreated:PostObject",
    "datacontenttype": "application/json;charset=utf-8",
    "dataschema": "http://example.com/item.json",
    "subject": "acs:oss:cn-hangzhou:<yourAccountId>:xls-papk/game_apk/123.jpg",
    "aliyunaccountid": "165228866041****",
    "aliyunpublishtime": "2020-10-14T17:00:03.628Asia/Shanghai",
    "aliyuneventbusname": "MyEventBus",
    "aliyunpublishaddr": "10.0.XX.XX",
    "data": {
        "name": "Eventbridge",
        "number": 100
    }
}