All Products
Search
Document Center

CloudFlow:Integrate Simple Message Queue (formerly MNS) topics

Last Updated:Oct 25, 2024

Serverless Workflow can be integrated with Simple Message Queue (formerly MNS) (SMQ) topics in task steps to publish messages to SMQ topics. You can push messages from SMQ topics to queues, HTTP endpoints, and email addresses. To do this, call the PublishMessage operation. This topic describes the modes and parameters that are used to integrate SMQ topics.

Integration modes

This section describes the modes that are used to integrate SMQ topics: request-response mode and wait-for-callback mode. You can use one of the modes to orchestrate SMQ topics.

  • Request-response mode

    In this mode, after a PublishMessage request is sent, Serverless Workflow proceeds with the task steps. The following code defines the flow:

    version: v1
    type: flow
    steps:
     - type: task
     name: mns-topic-task
     resourceArn: acs:mns:::/topics/{topicName}/messages # Call the SMQ topic resource named {topicName}.
     pattern: requestResponse # The request-response mode, which is the default mode. The pattern parameter is optional.
     outputMappings:
     # Response parameters of the PublishMessage operation
     - target: messageID  # The message ID.
     source: $local.MessageId
     - target: requestID  # The request ID.
     source: $local.RequestId
     - target: messageBodyMD5  # The MD5 hash of the message body.
     source: $local.MessageBodyMD5
     serviceParams:
     # Request parameters of the PublishMessage operation
     MessageBody: $.messageBody # The message body.
     MessageTag: $.messageTag # (Optional) The tag of the message. The MessageTag parameter is optional.
     MessageAttributes: $.messageAttributes # The additional attributes of the message. These attributes must be in the JSON format. The MessageAttributes parameter is optional.
  • Wait-for-callback mode

    In this mode, after a PublishMessage request is sent, Serverless Workflow suspends the task steps until a callback notification is received. The following code defines the flow:

    version: v1
    type: flow
    steps:
     - type: task
     name: mns-topic-task
     resourceArn: acs:mns:::/topics/{topicName}/messages # Call the SMQ topic resource named {topicName}.
     pattern: waitForCallback # The wait-for-callback mode.
     inputMappings:
     - target: messageBody
     source: $input.messageBody
          - target: messageTag
     source: $.messageTag
     - target: messageAttributes
     source: $.messageAttributes
     - target: taskToken # The token that is used to call back the task status. This token is automatically generated.
     source: $context.task.token
     serviceParams:
     # Request parameters of the PublishMessage operation
     MessageBody: $ # The message body. The task token (TaskToken) is encapsulated in the message body.
     MessageTag: $.messageTag# The tag of the message. The MessageTag parameter is optional.
     MessageAttributes:$.messageAttributes # The additional attributes of the message. The MessageAttributes parameter is optional.

Parameters

  • context

    • TaskToken

      This parameter specifies the task token of a task step. In wait-for-callback mode, a task step automatically generates the task token that is used to call back the task status. You can call the ReportTaskSucceeded and ReportTaskFailed operations to query the TaskToken value from the $context.task.token response parameter. Then, use the TaskToken value to query the status of the callback task.

  • serviceParams

    • MessageBody: The message body string that you want to send.

    • MessageTag: The tag of the message that you want to send. This parameter is optional.

    • MessageAttributes: The additional attributes of the message. This parameter is optional. You must specify this parameter when you push specific messages. The value of this parameter must be a JSON string.

    • Mail push: The MailAttributes parameter must be specified if you want to push the message by email. Sample code:

      {
       "MailAttributes": {
        "Subject":"{Email subject}",
        "AccountName":"{Sender address (email address)}", 
        "AddressType":0,
        "IsHTML":true,
         "ReplyToAddress":0
      }
      }

    For more information about the preceding parameters, see PublishMessage.