CloudFlow integrates with Simple Message Queue (formerly MNS) (SMQ) to send messages to queues and topics directly from a workflow. Use the MNS:SendMessage action in your flow definition to deliver messages with optional priority, delay, and email or SMS attributes.
Sample flow definition
The following flow definition sends a message to an SMQ queue with custom priority, a 10-second delay, and email and SMS attributes:
Type: StateMachine
Name: MyWorkflow
SpecVersion: v1
StartAt: SendMessage
States:
- Type: Task
Name: SendMessage
Action: MNS:SendMessage
TaskMode: RequestComplete
Description: Send a message to an SMQ queue
Parameters:
resourceArn: acs:mns:cn-hangzhou:1231231****:/queues/fnf-mns-queues/messages
message:
body: ok
priority: 1
delaySeconds: 10
messageTag: aaa
messageAttributes:
MailAttributes:
Subject: subject
AccountName: account
AddressType: 123
IsHTML: true
ReplyToAddress: 456
SMSAttributes:
FreeSignName: test-free-sign-name
TemplateCode: test-template-code
Type: test-type
Receiver: test-receiver
SmsParams: test-sms-params
End: trueNotable fields:
Action: Set to
MNS:SendMessage.TaskMode: Set to RequestComplete or WaitForCustomCallback. For details, see Execution modes.
Name and Description: Values that describe the task in your workflow.
Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
| resourceArn | Yes | Alibaba Cloud Resource Name (ARN) of the SMQ queue or topic. | acs:mns:cn-hangzhou:1231231****:/queues/fnf-mns-queues/messages |
| message | Yes | Message body. Accepts plain text, a structured object, or an array. Structured objects and arrays are automatically converted to JSON before sending. | This is a test message |
| priority | No | Message priority. Valid values: 1 to 16. A smaller value indicates higher priority. Default: 8. | 8 |
| delaySeconds | No | Seconds to delay the message before it becomes consumable. Valid values: 0 to 604800. Default: 0. | 0 |
| messageTag | No | Message tag. Applies only to topic-type messages. | tag |
| messageAttributes | No | Additional message attributes for email or SMS delivery. See messageAttributes fields. | - |
messageAttributes fields
The messageAttributes parameter supports email delivery through MailAttributes and SMS delivery through SMSAttributes.
MailAttributes
| Field | Description |
|---|---|
| Subject | Email subject line. |
| AccountName | Sender account name. |
| AddressType | Address type identifier. |
| IsHTML | Whether the email body is in HTML format. Valid values: true, false. |
| ReplyToAddress | Reply-to address. |
SMSAttributes
| Field | Description |
|---|---|
| FreeSignName | SMS signature name. |
| TemplateCode | SMS template code. |
| Type | SMS type. |
| Receiver | SMS recipient. |
| SmsParams | SMS template parameters. |
Example:
messageAttributes:
MailAttributes:
Subject: subject
AccountName: account
AddressType: 123
IsHTML: true
ReplyToAddress: 456
SMSAttributes:
FreeSignName: test-free-sign-name
TemplateCode: test-template-code
Type: test-type
Receiver: test-receiver
SmsParams: test-sms-paramsReturn value
A successful request returns a JSON object with the following fields:
| Field | Description |
|---|---|
| MessageBodyMD5 | MD5 hash of the message body. |
| MessageID | Unique identifier of the sent message. |
| ReceiptHandle | Receipt handle for the message. |
| RequestID | Unique identifier of the API request. |
Example:
{
"MessageBodyMD5": "74B87337454200D4D33F8**********",
"MessageID": "02CCC72A80767FCE7FE97DDC**********",
"ReceiptHandle": "",
"RequestID": "65387E5A44383182**********"
}Execution modes
The SMQ integration supports two execution modes that control when the task is considered complete. In both modes, after CloudFlow sends a message to SMQ, the task completes when the current HTTP request is complete, and the HTTP response is used as the task output.
| Mode | Behavior | Use case |
|---|---|---|
| RequestComplete | Task completes immediately after the message is sent. The SMQ response becomes the task output. | Fire-and-forget messaging where no downstream acknowledgment is needed. |
| WaitForCustomCallback | Task pauses after the message is sent and waits for an external callback to resume. | Workflows that require external processing or human approval before continuing. |
RequestComplete
After CloudFlow sends the message to SMQ, the task completes immediately. The SMQ response becomes the task output.
Set TaskMode to RequestComplete in the flow definition:
TaskMode: RequestCompleteWaitForCustomCallback
After CloudFlow sends the message to SMQ, the workflow pauses and waits for an external system to report the result. The workflow resumes only after the ReportTaskSucceeded or ReportTaskFailed API operation is called.
Set TaskMode to WaitForCustomCallback in the flow definition:
TaskMode: WaitForCustomCallbackPass the task token to the external system
For the external system to call back into CloudFlow, it needs the task token. Include the token in the message by referencing $Context.Current.TaskToken in the data field:
- Type: Task
Name: SendMessageWithCallback
Action: MNS:SendMessage
TaskMode: WaitForCustomCallback
Parameters:
resourceArn: acs:mns:cn-hangzhou:1231231****:/queues/fnf-mns-queues/messages
message:
body: ok
data:
key: $Context.Current.TaskToken
End: trueCallback flow:
CloudFlow sends the message (including the task token) to the SMQ queue.
The external system consumes the message and extracts the task token from the
data.keyfield.After processing, the external system calls ReportTaskSucceeded or ReportTaskFailed with the task token to resume the workflow.