When messages arrive in a Simple Message Queue (formerly MNS) (SMQ) queue, you may need to route them to downstream services such as Function Compute for processing. EventBridge event streams connect an SMQ queue to a target service so that messages are delivered automatically without polling or custom integrations.
Prerequisites
Before you begin, make sure that you have:
An activated EventBridge instance with the required permissions granted to a Resource Access Management (RAM) user. For more information, see Activate EventBridge and grant permissions to a RAM user
An SMQ queue. For more information, see Activate SMQ and authorize RAM users to access SMQ
Create an event stream with an SMQ source
Log on to the EventBridge console. In the left-side navigation pane, click Event Streams.
In the top navigation bar, select a region and click Create Event Stream.
On the Create Event Stream page, specify the Task Name and Description parameters.
Configure the event source, filtering, transformation, sink, and task properties as described in the following sections. Then click Save.
Source
In the Source step, set Data Provider to SMQ and configure the following parameters. Then click Next Step.
| Parameter | Description | Valid values | Example |
|---|---|---|---|
| Queue Name | The SMQ queue to use as the event source. | N/A | test-queue |
| Base64 Decoding | Whether to decode message data from Base64 before delivery to the sink. Enable this if your SMQ messages are Base64-encoded. | N/A | test |
| Messages | The maximum number of messages that can be sent in each function invocation. Requests are sent only when the number of messages in the backlog reaches the specified value. | 1 to 10,000 | 100 |
| Interval (Unit: Seconds) | The time interval at which you want to invoke the function. The system sends the aggregated messages to Function Compute when the specified interval is reached. Set to 0 to send messages immediately after aggregation. | 0 to 15 | 3 |
Filtering, transformation, and sink
In the Filtering, Transformation, and Sink steps, configure the event filtering method, event transformation rule, and event target.
For more information about event transformation, see Use Function Compute to perform message cleansing.
Retry policy and dead-letter queue
Under Task Property, specify the retry policy and dead-letter queue for the event stream.
For more information, see Retry policies and dead-letter queues.
Enable the event stream
Go back to the Event Streams page and find the event stream that you created.
In the Actions column, click Enable.
The event stream takes 30 to 60 seconds to start. Track the progress in the Status column on the Event Streams page.
Sample event
Each message from the SMQ queue is delivered as a CloudEvents 1.0-compliant event. The following example shows the structure of a typical event:
{
"specversion": "1.0",
"id": "bffb9722-9c48-407b-9895-b038f78f****",
"source": "acs:mns",
"type": "mns:Queue:SendMessage",
"subject": "acs:mns:cn-hangzhou:123456789098****:queues/zeus",
"datacontenttype": "application/json; charset=utf-8",
"time": "2021-04-08T06:28:17.093Z",
"aliyunpublishtime": "2021-04-08T06:30:31.367Z",
"aliyuneventbusname": "mybus",
"data": {
"requestId": "606EA3074344430D4C81****",
"messageId": "C6DB60D1574661357FA227277445****",
"messageBody": "TEST"
}
}For more information about the CloudEvents envelope fields (specversion, id, source, type, subject, time, and others), see Overview.
Data fields
The data object contains the original SMQ message payload:
| Field | Type | Description |
|---|---|---|
requestId | String | A unique identifier for the request that sent the message to the queue. |
messageId | String | A unique identifier for the message in the queue. |
messageBody | String | The message body content. |