In Serverless Workflow, task steps are integrated with Alibaba Cloud Message Service (MNS) topics. This allows you to publish messages to MNS topics. You can push messages from MNS 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 MNS topics.

Integration modes

The following section describes the modes that are used to integrate MNS topics: request-response mode and wait-for-callback mode. You can use one of the modes to orchestrate MNS 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 MNS topic resource.
        pattern: requestResponse # (Optional) The default mode.
        outputMappings:
          # Response parameters of the PublishMessage operation
          - target: messageID  # The ID of the message.
            source: $local.MessageId
          - target: requestID  # The ID of the request.
            source: $local.RequestId
          - target: messageBodyMD5  # The MD5 value of the message body.
            source: $local.MessageBodyMD5
        serviceParams:
          # Request parameters of the PublishMessage operation
          MessageBody: $.messageBody  # The message body.
          MessageTag: $.messageTag  # (Optional) The message tag.
          MessageAttributes: $.messageAttributes  # (Optional) The additional attributes of the message. These attributes must be in the JSON format. 
  • 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 MNS topic resource.
        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, in which TaskToken is encapsulated.
          MessageTag: $.messageTag # (Optional) The message tag.
          MessageAttributes:$.messageAttributes  # (Optional) The additional attributes of the message.

Description of parameters

  • context
    • TaskToken

      In the wait-for-callback mode, a task step automatically generates TaskToken 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 to be sent.
    • (Optional) MessageTag: The tag of the message to be sent.
    • (Optional) MessageAttributes: 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 as shown in the following 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.