You can use event rules to filter events and route events to Message Queue for Apache RocketMQ. This topic describes the prerequisites and procedure for routing custom events to Message Queue for Apache RocketMQ. This topic also describes how to verify the result.

Step 1: Add a custom event source

  1. Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the custom event bus that you want to manage.
  3. In the left-side navigation pane, click Event Sources, and then click Add Event Source.
  4. In the Add Custom Event Source panel, set the Name and Description parameters, select Custom Application from the Event Provider drop-down list, and then click OK.

Step 2: Create an event rule

Important The event targets that you want to configure for an event rule must reside in the same region as the event rule.
  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, click Event Buses.
  3. In the top navigation bar, select the 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.
  6. On the Event Rules page, click Create Rule.
  7. Perform the following operations in the Create Rule panel:
    1. In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field, and click Next Step.
    2. In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source, select the custom event source that is created in Step 1 from the Event Source drop-down list, specify an event pattern in the Pattern Content code editor, and then click Next Step.

      For more information, see Event patterns.

    3. In the Configure Targets step, configure an event target. Then, click Create.
      Note You can configure up to five event targets for an event rule.

      The following table describes the parameters that you can set if you select Message Queue for Apache RocketMQ as the event target.

      Parameter Description
      Service Type Click Message queue RocketMQ version.
      Instance ID Select the ID of the created Message queue RocketMQ version instance.
      Topic Select the created topic.
      Message Body EventBridge extracts data from an event by using JSONPath and routes the specified content of the event to an event target. Example:

      Partial Event

      $.data.body
      Custom Property EventBridge extracts data from an event by using JSONPath and routes the specified property of the event to an event target. Example:

      Template

      Parameters:
      {
        "userProperties":"$.data.userProperties",
        "msgId":"$.data.systemProperties.UNIQ_KEY"
      }
      Template:
      {
        "EB_SYS_EMBED_OBJECT":"${userProperties}",
        "UNIQ_KEY":"${msgId}"
      }
      Message Index EventBridge extracts data from an event by using JSONPath and routes the specified content of the event to an event target.

      Partial Event

      $.data.systemProperties.KEYS
      Message Tag EventBridge extracts data from an event by using JSONPath and routes the specified content of the event to an event target.

      Partial Event

      $.data.systemProperties.TAGS

      EventBridge provides various event transformation methods. For more information, see Event transformation. The following part provides an example of each event transformation method:

      • Example of Partial Event
        $.data.body
      • Example of Fixed Value
        Pay attention to the alert. 
      • Examples of Parameters and Template

        Sample Parameters:

        {
          "type":"$.type"
        }

        Sample Template

        The event type is ${type}.

Step 3: Publish an event

  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 event bus to which you want to publish an event and click Publish Event in the Operations column.
    Note You can publish events only to custom event buses in the EventBridge console.
  5. In the Publish Event to Custom Event Bus panel, select a custom event source from the Custom Event Source drop-down list, enter the event content in the Event Body code editor, and then click OK.
    For more information about the event parameters, see Overview.

Verify the results

You can check whether the event is received in the Message Queue for Apache RocketMQ console.

  1. Log on to the Message Queue for Apache RocketMQ console.
  2. In the left-side navigation pane, click Instances.
  3. In the top navigation bar, select a region such as China (Hangzhou).
  4. On the Instances page, find the instance that you require, and choose More > Message Query in the Actions column.
  5. On the Message Query page, select Query by Topic from the Query Method drop-down list and the topic whose messages you want to query from the Topic drop-down list, set the Time Range parameter, and then click Search.

The following sample code shows the content of the received event:

{
    "id":"94ebc15f-f0db-4bbe-acce-56fb72fb****",
    "source":"acs:mq",
    "specversion":"1.0",
    "type":"mq:Topic:SendMessage",
    "datacontenttype":"application/json; charset=utf-8",
    "subject":"acs:mq:cn-hangzhou:123456789098****:MQ_INST_123456789098****_BXhFHryi%TopicName",
    "time":"2021-04-08T06:01:20.766Z",
    "aliyunpublishtime":"2021-04-08T06:01:20.725Z",
    "aliyuneventbusname":"BusName",
    "data":{
        "topic":"TopicName",
        "systemProperties":{
            "MIN_OFFSET":"0",
            "TRACE_ON":"true",
            "MAX_OFFSET":"8",
            "MSG_REGION":"cn-hangzhou",
            "KEYS":"systemProperties.KEYS",
            "CONSUME_START_TIME":1628577790396,
            "UNIQ_KEY":"AC14C305069E1B28CDFA3181CDA2****",
            "TAGS":"systemProperties.TAGS",
            "INSTANCE_ID":"MQ_INST_123456789098****_BXhFHryi"
        },
        "userProperties":{
        },
        "body":"TEST"
    }
}