Integrate CloudFlow with Simple Message Queue (formerly MNS)

更新时间:
复制 MD 格式

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: true

Notable fields:

Parameters

ParameterRequiredDescriptionExample
resourceArnYesAlibaba Cloud Resource Name (ARN) of the SMQ queue or topic.acs:mns:cn-hangzhou:1231231****:/queues/fnf-mns-queues/messages
messageYesMessage 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
priorityNoMessage priority. Valid values: 1 to 16. A smaller value indicates higher priority. Default: 8.8
delaySecondsNoSeconds to delay the message before it becomes consumable. Valid values: 0 to 604800. Default: 0.0
messageTagNoMessage tag. Applies only to topic-type messages.tag
messageAttributesNoAdditional 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

FieldDescription
SubjectEmail subject line.
AccountNameSender account name.
AddressTypeAddress type identifier.
IsHTMLWhether the email body is in HTML format. Valid values: true, false.
ReplyToAddressReply-to address.

SMSAttributes

FieldDescription
FreeSignNameSMS signature name.
TemplateCodeSMS template code.
TypeSMS type.
ReceiverSMS recipient.
SmsParamsSMS 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-params

Return value

A successful request returns a JSON object with the following fields:

FieldDescription
MessageBodyMD5MD5 hash of the message body.
MessageIDUnique identifier of the sent message.
ReceiptHandleReceipt handle for the message.
RequestIDUnique 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.

ModeBehaviorUse case
RequestCompleteTask completes immediately after the message is sent. The SMQ response becomes the task output.Fire-and-forget messaging where no downstream acknowledgment is needed.
WaitForCustomCallbackTask 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: RequestComplete

WaitForCustomCallback

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: WaitForCustomCallback

Pass 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: true

Callback flow:

  1. CloudFlow sends the message (including the task token) to the SMQ queue.

  2. The external system consumes the message and extracts the task token from the data.key field.

  3. After processing, the external system calls ReportTaskSucceeded or ReportTaskFailed with the task token to resume the workflow.