You can use event rules to filter events and route events to Message Queue for RabbitMQ. This topic describes the prerequisites and procedure for routing custom events to Message Queue for RabbitMQ. This topic also describes how to verify the result.
Prerequisites
-
EventBridge
-
Message Queue for RabbitMQ
Step 1: Create a custom event source
- 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 Sources.
- On the Event Sources page, click Add Event Source.
- In the Add Custom Event Source panel, set 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
Notice The event targets that you want to configure for an event rule 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 target event bus.
- In the left-side navigation pane, click Event Rules.
- On the Event Rules page, click Create Rule.
- Complete the Create Rule wizard.
Step 3: Publish an event
Verify the result
You can check whether the event is received in the Message Queue for RabbitMQ console.
- Log on to the Message Queue for RabbitMQ console.
- In the Resource Distribution section of the Overview page, select the region where your instance is located.
- On the Instances page, find the instance that you require, and choose in the Actions column.
- On the Message Query page, select Query by Queue from the Query Method drop-down list, the vhost whose messages you want to query from the Vhost drop-down list, and the queue whose messages you want to query from the Queue drop-down list, set the time range to query, and then click Query.
The following sample code shows the content of the 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"
}