Route events to ApsaraMQ for RabbitMQ

更新时间:
复制 MD 格式

You can filter events by using event rules and route them to ApsaraMQ for RabbitMQ. This topic uses a custom event as an example to describe the prerequisites, procedure, and result verification for routing events to ApsaraMQ for RabbitMQ.

Prerequisites

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, configure 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 target and the event rule must be in the same region.

  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.

  6. On the Event Rules page, click Create Rule.

  7. On the Create Rule page, perform the following steps.

    1. In the Configure Basic Info step, enter a name and description for the rule in the Name and Description text boxes, and then click Next Step.

    2. In the Configure Event Pattern step, set Event Source Type to Custom Event Source. For Event Source, select the custom event source that you added in Step 1. In the Pattern Content code editor, enter an event pattern, and then click Next Step.

      For more information, see event patterns.

    3. In the Configure Targets step, configure the event target, and then click Create.

      Note

      You can add up to five event targets for an event rule.

      The following table describes the parameters for configuring an ApsaraMQ for RabbitMQ event target.

      Parameter

      Description

      Service Type

      Select ApsaraMQ for RabbitMQ.

      Instance ID

      Select the ID of the ApsaraMQ for RabbitMQ instance that you created.

      vhost

      Select the vhost that you created.

      Destination Type

      Select Exchange or Queue.

      Exchange

      Select the exchange that you created. This parameter is required only if you set Destination Type to Exchange.

      Message Routing Key

      Select Partial Event or Fixed Value. This parameter is required only if you set Destination Type to Exchange.

      queue

      Select the queue that you created. This parameter is required only if you set Destination Type to Queue.

      Message Body

      Select Complete Event, Partial Event, Fixed Value, or Template.

      MessageId

      Select Partial Event, Fixed Value, or Template.

      Custom Property

      Select Partial Event or Template.

      Note

      The value of this parameter must be a map.

      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, 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.

    Note

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

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

    SettingDescription
    Custom Event SourceSelect an existing custom event source from the drop-down list.
    Event BodyEnter the event content.
  6. Click OK.

Verify the result

Verify that the event was received in the ApsaraMQ for RabbitMQ console.

  1. Log on to the ApsaraMQ for RabbitMQ console. In the left-side navigation pane, click Instances.

  2. In the top navigation bar of the Instances page, select the region where the instance that you want to manage resides. Then, in the instance list, click the name of the instance that you want to manage.

  3. On the Instances page, find the target instance, and in the Actions column, choose More > Message Query.

  4. On the Message Query page, set Query Method: to Query by Queue, select the desired Queue and Time Range, and then click Query.

The example below shows the content of a received message:

{
    "datacontenttype":"application/json;charset=utf-8",
    "aliyunaccountid":"143998900779****",
    "data":{
        "envelope":{
            "deliveryTag":98,
            "exchange":"",
            "redeliver":false,
            "routingKey":"housekeeping"
        },
        "body":{
            "Hello":"EventBridge"
        },
        "props":{
            "contentEncoding":"UTF-8",
            "messageId":"f7622d51-e198-41de-a072-77c1ead7****"
        }
    },
    "subject":"acs:amqp:cn-hangzhou:143998900779****:/instances/amqp-cn-zvp2av0m****/vhosts/eb-connect/queues/housekeeping",
    "aliyunoriginalaccountid":"143998900779****",
    "source":"housekeeping.rabbitmq",
    "type":"amqp:Queue:SendMessage",
    "aliyunpublishtime":"2021-08-12T06:56:50.783Z",
    "specversion":"1.0",
    "aliyuneventbusname":"Housekeeping-Connect",
    "id":"8b09e19b-8cbd-4c46-ab77-9cc39c44****",
    "time":"2021-08-12T06:56:40.709Z",
    "aliyunregionid":"cn-hangzhou"
}