You can filter events by using event rules and route them to ApsaraMQ for RabbitMQ. This topic uses a custom event as an example to describe the prerequisites, procedure, and result verification for routing events to ApsaraMQ for RabbitMQ.
Prerequisites
-
EventBridge
-
ApsaraMQ for RabbitMQ
Step 1: Add 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 custom event bus that you want to manage.
In the left-side navigation pane, click Event Sources, and then click Add Event Source.
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
The event target and the event rule must be in the same region.
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 Event Rules page, click Create Rule.
-
On the Create Rule page, perform the following steps.
-
In the Configure Basic Info step, enter a name and description for the rule in the Name and Description text boxes, and then click Next Step.
-
In the Configure Event Pattern step, set Event Source Type to Custom Event Source. For Event Source, select the custom event source that you added in Step 1. In the Pattern Content code editor, enter an event pattern, and then click Next Step.
For more information, see event patterns.
-
In the Configure Targets step, configure the event target, and then click Create.
NoteYou can add up to five event targets for an event rule.
The following table describes the parameters for configuring an ApsaraMQ for RabbitMQ event target.
Parameter
Description
Service Type
Select ApsaraMQ for RabbitMQ.
Instance ID
Select the ID of the ApsaraMQ for RabbitMQ instance that you created.
vhost
Select the vhost that you created.
Destination Type
Select Exchange or Queue.
Exchange
Select the exchange that you created. This parameter is required only if you set Destination Type to Exchange.
Message Routing Key
Select Partial Event or Fixed Value. This parameter is required only if you set Destination Type to Exchange.
queue
Select the queue that you created. This parameter is required only if you set Destination Type to Queue.
Message Body
Select Complete Event, Partial Event, Fixed Value, or Template.
MessageId
Select Partial Event, Fixed Value, or Template.
Custom Property
Select Partial Event or Template.
NoteThe value of this parameter must be a map.
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}.
- Example of partial 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.
Verify the result
Verify that the event was received in the ApsaraMQ for RabbitMQ console.
Log on to the ApsaraMQ for RabbitMQ console. In the left-side navigation pane, click Instances.
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.
-
On the Instances page, find the target instance, and in the Actions column, choose .
-
On the Message Query page, set Query Method: to Query by Queue, select the desired Queue and Time Range, and then click Query.
The example below shows the content of a received message:
{
"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"
}