Connect a custom event source

Updated at:

Connect a custom event source in the console to route events from your applications to event targets. This topic describes how to add a custom event source, create an event rule, publish events, verify the result, and delete the event rule and the custom event bus.

Prerequisites

Step 1: Create a custom event source

  1. Log on to the EventBridge console. In the left navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the target custom event bus.
  3. In the left navigation pane, click Event Sources, and then click Add Event Source.
  4. In the Add Custom Event Source panel, enter a Name and Description. For Event Provider, select Event Provider, and then click OK.

Step 2: Create an event rule

Note

Each event target must be in the same region as the event rule.

  • Log on to the EventBridge console.

  • In the left-side navigation pane, click Event Buses.

  • In the top navigation bar, select a region.

  • On the Event Buses page, click the name of the event bus that you want to manage.

  • In the left-side navigation pane, click Event Rules.

  • 1. On the Event Rules page, click Create Rule.

    1. On the Create Rule page, perform the following steps:

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

    b. In the Configure Event Pattern wizard step, set the Event Source Type parameter to Custom Event Source. Select the custom event source that you 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.

    c. In the Configure Targets wizard step, configure the target service with the following parameters, and click Create.

    Note

    Each event rule supports up to five event targets.

    • Service Type: Select Simple Message Queue (formerly MNS)Simple Message Queue (formerly MNS).

    • Queue: Select the queue that you created.

    • Message Body: Select Complete Event.

    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.

    Step 4: Verify the result

    1. Log on to the ApsaraMQ for MNS console.

    2. In the left-side navigation pane, choose Queue Model > Queues.

    3. In the top navigation bar, select a region.

    4. On the Queues page, find the target queue and in the Actions column, choose .

    5. In the Receive Message section, click Receive Message.

      The following code block shows a sample received message.

      {
          "id": "45ef4dewdwe1-7c35-447a-bd93-fab****",
          "source": "acs.ecs",
          "specversion": "1.0",
          "subject": "acs.ecs:cn-hangzhou:123456789098****:215672",
          "time": "2020-11-19T21:04:41Z",
          "type": "ecs:Snapshot:CreateSnapshotCompleted",
          "aliyunaccountid": "123456789098****",
          "aliyunpublishtime": "2020-11-19T21:04:42Z",
          "aliyuneventbusname": "default",
          "aliyunregionid": "cn-hangzhou",
          "aliyunpublishaddr": "172.25.XX.XX",
          "data": {
              "result": "accomplished",
              "snapshotId": "s-bp151qed0khxxxxxxxxx",
              "snapshotType": "user",
              "snapshotName": "cust51119970_xxxxxxxx_20211117114015",
              "diskId": "d-bp18dnj7u1xxxxxxxxx",
              "startTime": "2020-11-19T21:02:16Z",
              "endTime": "2020-11-19T21:04:17Z"
          }
      }

    Step 5: Delete the event rule

  • Log on to the EventBridge console.
  • In the left-side navigation pane, click Event Buses.
  • In the top navigation bar, select a region.
  • On the Event Buses page, click the name of the target event bus.
  • In the left-side navigation pane, click Event Rules.

  • 1. On the Event Rules page, find the event rule that you want to delete and click Delete in the Operations column. Complete the deletion as prompted.

    Step 6: Delete the custom event bus

  • Log on to the EventBridge console.
  • In the left-side navigation pane, click Event Buses.
  • In the top navigation bar, select a region.
  • 1. On the Event Bus page, find the custom event bus that you want to delete and click Delete in the Operations column. Complete the deletion as prompted.

    Note

    Make sure that no event source is bound to the custom event bus that you want to delete. Otherwise, the deletion fails with the following error: An event source has been bound to the event bus. Delete the event source bound to the event bus or specify another event bus.