This topic explains how to use the EventBridge event stream feature to route ApsaraMQ for RocketMQ messages.
Prerequisites
-
You have activated EventBridge and granted the required permissions.
-
You have purchased and deployed an ApsaraMQ for RocketMQ instance, and the instance is in the Running state. For more information, see Create an instance.
Background information
An event stream is a lightweight, real-time, end-to-end channel for streaming events. It can filter and transform lightweight streaming data and synchronize data between data warehouses, data processing applications, and data analytics systems. Messages produced by a source ApsaraMQ for RocketMQ instance can be routed through an event stream to a destination ApsaraMQ for RocketMQ instance without defining an event bus. For more information, see Event stream overview.
Step 1: Create an event stream at the destination
You must create the event stream in the destination region. For example, to route ApsaraMQ for RocketMQ messages from the China (Beijing) region to the China (Hangzhou) region, create the event stream in the China (Hangzhou) region.
-
Log on to the EventBridge console.
-
In the top navigation bar, select a region.
-
In the navigation pane on the left, click Event Streams.
-
On the Event Streams page, click Create Event Stream.
-
In the Create Event Stream panel, set Task Name and Description, configure the following parameters, and then click Save.
-
Task Creation
-
In the Source wizard, set Data Provider to Message Queue for Apache RocketMQ, configure the following parameters, and then click Next.
Parameter
Description
Example
Region
Select the region where the source ApsaraMQ for RocketMQ instance is located.
China (Hangzhou)
Version
Select the version of the ApsaraMQ for RocketMQ instance.
RocketMQ 4.x
Instance
Select the source ApsaraMQ for RocketMQ instance.
MQ_INST_115964845466****_ByBehioo
Topic
Select the source topic.
topic
Tag
Specify the tag used to filter messages in the source instance.
test
Group ID
Select the consumer group in the source instance. You must use a dedicated consumer group for the event source. Do not share the consumer group with other business services, as this can disrupt message delivery.
GID_http_1
Consumer Offset
Select the position from which to start consuming messages.
Latest Offset
Data Format
This parameter specifies the content encoding format for data sources that support binary transfer. For a message routing scenario, set this parameter to Binary.
Binary
Batch Push
This feature aggregates multiple events for batch delivery. A batch is delivered when either the Messages or the Interval (Unit: Seconds) is reached, whichever occurs first.
For example, if you set the batch push size to 100 messages and the interval to 15 seconds, a batch is pushed as soon as 100 messages are collected within 10 seconds, without waiting for the full 15 seconds.
Enable
Messages
The maximum number of messages in a batch. A batch is pushed when the number of messages reaches this value. Valid values: 1 to 10,000.
100
Interval (Unit: Seconds)
The maximum time to wait before sending a batch of messages. The system aggregates messages and sends them at the specified interval. Valid values: 0 to 15 seconds. A value of 0 indicates that messages are delivered immediately without waiting.
3
-
In the Filtering wizard, configure event filtering rules, and then click Next.
NoteYou cannot filter messages based on their body content. For message routing, the Transformation step is not required.
-
In the Sink wizard, set Service Type to ApsaraMQ for RocketMQ, configure the following parameters, and then click Save.
Parameter
Description
Example
Version
Select the version of the destination ApsaraMQ for RocketMQ instance.
RocketMQ 4.x
Instance ID
Select the destination ApsaraMQ for RocketMQ instance.
test
Topic
Select the destination topic.
test
Message Body
EventBridge uses binary extraction to retrieve data from the specified event, decodes it from Base64, and then routes it to the event target.
Binary Extraction
$.data.bodyCustom Property
Select Template. You can create a custom template and define the required variables. EventBridge extracts fields from the event and transforms them based on the template definition.
NoteTo transfer all attributes from the source message, use the provided example configuration.
Variables:
{ "userProperties":"$.data.userProperties", "msgId":"$.data.systemProperties.UNIQ_KEY" }Template:
{ "EB_SYS_EMBED_OBJECT":"${userProperties}", "UNIQ_KEY":"${msgId}" }Message Key
EventBridge extracts the message key from the source event by using the specified JSONPath expression.
Partial Event
$.data.systemProperties.KEYSMessage Tag
EventBridge extracts the message tag from the source event by using the specified JSONPath expression.
Partial Event
$.data.systemProperties.TAGS
-
-
Task Properties
Configure the retry policy and dead-letter queue for the event stream. For more information, see Retry policies and dead-letter queues.
-
-
Return to the Event Streams page. Find the event stream that you created and click Enable in the Actions column.
-
In the Show Tooltip dialog box, read the information and click Confirm.
After you enable the event stream, it takes 30 to 60 seconds to start. You can view the startup progress in the Status column on the Event Streams page.
Step 2: Test and verify
-
Log on to the ApsaraMQ for RocketMQ console.
-
In the top menu bar, select the region that contains the source instance specified in Step 1: Create an event stream at the destination.
-
In the navigation pane on the left, click Instances.
-
On the Instances page, find the source instance that you configured in Step 1: Create an event stream at the destination, and in the Actions column, click Details.
-
In the navigation pane on the left, click Topics.
-
In the Topic list, click the Topic name of the source instance that you configured in Step 1: Create an event stream on the destination.
-
On the topic details page, click Send Message in the upper-right corner.
-
In the Send Message panel, select Send by using Console for Go to Console. Then, configure Message Content, Message Key, and Message Tag, and click OK.
After the message is sent, the console displays The message is sent. and the message ID.
-
After the message is produced in the source instance, return to the Instances page.
-
On the Instances page, find the target instance that you configured in Step 1: Create an event stream at the destination, and in its Actions column, click Details.
-
In the navigation pane on the left, click Topics.
-
In the Topic list, click the Topic name of the target instance that you configured in Step 1: Create an event stream on the destination.
-
On the topic details page, click the Message Query tab.
-
Set Query Method: and Specify a query scope, and then click Query.
Set Query By to Topic and Time Range to Last Hour.
-
Verify that the retrieved Message ID, Tag, and Key match the message you sent.