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, choose Event-driven Operations > Event Sources.
  3. In the top navigation bar, select a region.
  4. On the Event Sources page, click the Custom Event Sources tab. On the Custom Event Sources tab, click Add Event Source.
  5. In the Add Custom Event Source panel, enter a name and a description, select an event provider and an existing custom event bus, and then click OK.
    You can also click Create Custom Event Bus to associate the custom event source with a new custom event bus.

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, choose Event-driven Operations > Event Rules.
  3. In the top navigation bar, select a region.
  4. On the Event Rules page, select the custom event bus with which the custom event source created in Step 1 is associated, and then click Create Rule.
  5. 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 Event 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 and 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 for Apache RocketMQ.
      Instance ID Select the ID of the created Message Queue for Apache RocketMQ 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.

      The following part provides examples of event transformation methods of EventBridge. For more information, see Event transformation.

      • 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, choose Event-driven Operations > Event Buses.
  3. In the top navigation bar, select a region.
  4. In the Custom Event Buses section, 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"
    }
}