Use the EventBridge console to create a custom event source, configure an event rule, publish events, and verify event delivery.
Before you begin
-
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) (SMQ)
-
SMQ 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
Event targets must reside 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.
-
In the left-side navigation pane, click Event Rules, and then click Create Rule.
-
In the Create Rule wizard, perform the following steps:
-
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.
-
In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source and select the custom event source that you created in Step 1 from the Event Source drop-down list. In the Pattern Content code editor, specify an event pattern and click Next Step.
-
In the Configure Targets step, configure an event target, and click Create.
NoteEach event rule supports up to five event targets.
-
Service Type: Select SMQ.
-
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 SMQ console.
In the left-side navigation pane, choose Queue Model > Queues.
In the top navigation bar, select a region.
-
On the Queues page, find your queue and click Send Messages in the Actions column.
-
In the Receive Message section, click Receive Message.
Example of received events:
{ "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.
-
On the Event Rules page, find the rule to delete and click Delete in the Operations column.
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.
-
On the Event Bus page, find the custom event bus to delete and click Delete in the Operations column.
Dissociate all event sources from the custom event bus before you delete it. Otherwise, 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.