Connect a custom event source
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
EventBridge
EventBridge is activated, and the required permissions are granted to a Resource Access Management (RAM) user. For more information, see Activate EventBridge and grant permissions.
Simple Message Queue (formerly MNS)
Simple Message Queue (formerly MNS) is activated, and the required permissions are granted to a RAM user. For more information, see Simple Message Queue (formerly MNS): Activation and permissions.
A queue is created. For more information, see Create a queue.
Step 1: Create a custom event source
- Log on to the EventBridge console. In the left navigation pane, click Event Buses.
- In the top navigation bar, select a region. On the Event Buses page, click the target custom event bus.
- In the left navigation pane, click Event Sources, and then click Add Event Source.
-
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
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.
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.
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
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, find the target event bus and click Publish Event in the Operations column.
NoteThe EventBridge console supports publishing events to custom event buses only.
In the Publish Event To Custom Event Bus panel, configure the following settings:
Setting Description Custom Event Source Select an existing custom event source from the drop-down list. Event Body Enter the event content. Click OK.
Step 4: Verify the result
-
Log on to the ApsaraMQ for MNS console.
-
In the left-side navigation pane, choose .
-
In the top navigation bar, select a region.
-
On the Queues page, find the target queue and in the Actions column, choose .
-
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
In the left-side navigation pane, click Event Rules.
Step 6: Delete the custom event bus
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.