ApsaraMQ for MQTT
Add ApsaraMQ for MQTT as an event source for an event stream in the console.
Prerequisites
An ApsaraMQ for MQTTApsaraMQ for MQTT instance in the Running state. For more information, see Create resources.
Procedure
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.
In the Create Event Stream panel, enter the Task Name and Description.
In the Source configuration wizard of the Task Creation phase, set Data Provider to ApsaraMQ for MQTT, configure the following parameters, and then click Next.
Parameter Description Example MQTT Instance Select an MQTT instance. test-instance MQTT Topic Select a topic in the MQTT instance. test-topic Batch Push Batch push aggregates multiple events into batches. A batch push is triggered as soon as either the Messages condition or the Interval (Unit: Seconds) condition is met. For example, if you set the number of messages to 100 and the interval to 15 seconds, and 100 messages are collected within 10 seconds, the push is triggered immediately instead of waiting for the remaining 15 seconds. Enabled Messages The maximum number of messages sent in a batch. A batch is sent only after the number of accumulated messages reaches this value. Valid values: 1 to 10,000. 100 Interval (Unit: Seconds) The interval at which the system aggregates messages and pushes them to the event target. Valid values: 0 to 15. Unit: seconds. A value of 0 specifies no wait time, and messages are delivered immediately. 3 In the Filtering, Transformation, and Sink configuration wizards, configure the event filtering rules, event transformation rules, and event target. For more information about event transformation, see Use Function Compute to cleanse message data.
In the Task Properties phase, configure the retry policy and the dead-letter queue of the event stream. For more information, see Retry policies and dead-letter queues.
Click Save.
Return to the Event Streams page, find the event stream that you created, and click Enable in the Actions column on the right.
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.
Sample event
The following example shows a sample event from ApsaraMQ for MQTT:
{
"specversion":"1.0",
"id":"AC1EC0C950650816F27D46F7D7CA****",
"source":"acs:mqtt",
"type":"mqtt:Topic:SendMessage",
"subject":"acs:mq:cn-hangzhou:143998900779****:topic/mqtt-cn-2r42qam****/housekee****",
"datacontenttype":"application/json; charset\u003dutf-8",
"time":"2022-06-22T03:53:47.959Z",
"aliyunaccountid":"143998900779****",
"data":{
"props":{
"firstTopic":"housekee****",
"secondTopic":"/testMq4****",
"clientId":"GID_****"
},
"body":"TEST"
}
}For more information about the parameters defined in the CloudEvents specification, see Event overview.
The following table describes the parameters in the data field.
| Parameter | Type | Example | Description |
| props | Map | {"firstTopic":"housekee****","secondTopic":"/testMq4****","clientId":"GID_****"} | The message properties. |
| props.firstTopic | String | housekee**** | The parent topic used to send and receive messages. |
| props.secondTopic | String | /testMq4**** | The subtopic. |
| props.clientId | String | GID_**** | The client ID. |
| body | String | TEST | The message content. |