You can use event rules to filter events and route events to Message Queue for Apache RocketMQ. This topic describes the prerequisites and procedure for routing custom events to Message Queue for Apache RocketMQ. This topic also describes how to verify the result.
Prerequisites
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, 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
Important 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 the 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.
- Perform the following operations in the Create Rule panel:
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 event bus to which you want to publish an event and click Publish Event in the Operations column. Note You can publish events only to custom event buses in the EventBridge console.
- In the Publish Event to Custom Event Bus panel, select a custom event source from the Custom Event Source drop-down list, enter the event content in the Event Body code editor, and then click OK. For more information about the event parameters, see Overview.
Verify the results
You can check whether the event is received in the Message Queue for Apache RocketMQ console.
- Log on to the Message Queue for Apache RocketMQ console.
- In the left-side navigation pane, click Instances.
- In the top navigation bar, select a region. Example: China (Hangzhou).
- On the Instances page, find the instance that you require, and choose in the Actions column.
- On the Message Query page, select Query by Topic from the Query Method drop-down list and the topic whose messages you want to query from the Topic drop-down list, set the Time Range parameter, and then click Search.
The following sample code shows the content of the received event:
{
"id":"94ebc15f-f0db-4bbe-acce-56fb72fb****",
"source":"acs:mq",
"specversion":"1.0",
"type":"mq:Topic:SendMessage",
"datacontenttype":"application/json; charset=utf-8",
"subject":"acs:mq:cn-hangzhou:123456789098****:MQ_INST_123456789098****_BXhFHryi%TopicName",
"time":"2021-04-08T06:01:20.766Z",
"aliyunpublishtime":"2021-04-08T06:01:20.725Z",
"aliyuneventbusname":"BusName",
"data":{
"topic":"TopicName",
"systemProperties":{
"MIN_OFFSET":"0",
"TRACE_ON":"true",
"MAX_OFFSET":"8",
"MSG_REGION":"cn-hangzhou",
"KEYS":"systemProperties.KEYS",
"CONSUME_START_TIME":1628577790396,
"UNIQ_KEY":"AC14C305069E1B28CDFA3181CDA2****",
"TAGS":"systemProperties.TAGS",
"INSTANCE_ID":"MQ_INST_123456789098****_BXhFHryi"
},
"userProperties":{
},
"body":"TEST"
}
}