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: 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 the 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.
  6. On the Event Sources page, click Add Event Source.
  7. 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

Notice 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. Complete the Create Rule wizard.
    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 a maximum of 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.
      Body Click Complete Event, Partial Event, Constant, or Template.
      Properties Click Partial Event or Template.
      Keys Click Partial Event, Constant, or Template.
      Tags Click Partial Event, Constant, or Template.

      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 constant
        Pay attention to the alert. 
      • Examples of variable and template

        Sample variable:

        {
          "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 result

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"
    }
}