All Products
Search
Document Center

EventBridge:Route events to ApsaraMQ for RabbitMQ

Last Updated:Dec 01, 2023

You can use event rules to filter events and then route events to ApsaraMQ for RabbitMQ. This topic describes the prerequisites and procedure for routing custom events to ApsaraMQ for RabbitMQ. This topic also describes how to verify the result.

Prerequisites

Step 1: Create 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 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 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. In the left-side navigation pane, click Event Rules. On the page that appears, click Create Rule.

  7. In the Create Rule panel, perform the following steps:

    1. In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field. Then, click Next Step.

    2. In the Configure Event Pattern step, set Event Source Type to Custom Event Source and select the custom event source that you configured in Step 1 from the Event Source drop-down list. Then, In the Pattern Content code editor, enter an event pattern and click Next Step.

      For more information, see Event patterns.

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

      Note

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

      The following table describes the parameters that you must configure if you specify ApsaraMQ for RabbitMQ as the event target.

      Parameter

      Description

      Service Type

      Select Message Queue for RabbitMQ from the drop-down list.

      Instance ID

      Select the ID of the Message Queue for RabbitMQ instance that you created.

      vhost

      Select the vhost that you created.

      Destination Type

      Select Exchange or Queue based on your business requirements.

      Exchange

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

      Message Routing Key

      Select Partial Event or Fixed Value based on your business requirements. This parameter is required only if you set the Destination Type parameter to Exchange.

      Queue

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

      Message Body

      Select Complete Event, Partial Event, Fixed Value, or Template based on your business requirements.

      MessageId

      Select Partial Event, Fixed Value, or Template based on your business requirements.

      Custom Property

      Select Partial Event or Template based on your business requirements.

      Note

      The value of this parameter is of the Map type.

      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. In the left-side navigation pane, click Event Buses.

  2. In the top navigation bar, select a region.
  3. 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.
  4. 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 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 instance that you want to manage and choose More > Message Query in the Actions column.

  4. In the upper-left corner of the Message Query page, configure the vhost parameter and click the Query by Queue tab. In the tab that appears, select the queue that you want to manage from the Queue drop-down list, specify a time range, and then click Query.

The following sample code provides an example of a received event:

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