In Serverless workflow, task steps have integrated Alibaba Cloud Message Service (MNS) topics. You can publish messages to MNS topics by defining task steps in a flow. By setting PublishMessage parameters, you can push messages that are from MNS topics to queues, HTTP endpoints, and email addresses.
Integration modes
The following section describes two integration modes of MNS topics: request/response mode and wait-for-callback mode. You can use one of them to orchestrate MNS topics.
- Request/response mode
In this mode, after a PublishMessage request is sent, the flow proceeds with the task steps. The following piece of code defines the flow:
version: v1 type: flow steps: - type: task name: mns-topic-task resourceArn: acs:mns:::/topics/{topicName}/messages # mns topic resource arn pattern: requestResponse # Optional. The default mode. outputMappings: # Response parameters of PublishMessage - 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 PublishMessage MessageBody: $.messageBody # The message body. MessageTag: $.messageTag # Optional. The message tag. MessageAttributes: $.messageAttributes # The additional message attributes, which must be in JSON format.
- Wait-for-callback mode
In this mode, after a PublishMessage request is sent, the flow holds on the task steps until a callback notification is received. The following piece of code defines the flow:
version: v1 type: flow steps: - type: task name: mns-topic-task resourceArn: acs:mns:::/topics/{topicName}/messages # mns topic resource arn 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 automatically generated for task status callbacks source: $context.task.token serviceParams: # Request parameters of PublishMessage MessageBody: $ # The message body, in which TaskToken is encapsulated. MessageTag: $.messageTag # Optional. The message tag. MessageAttributes: $.messageAttributes # Optional. The additional message attributes.
Description of parameters
- context
- TaskToken
In the wait-for-callback mode, a task step automatically generates
TaskToken
for task status callbacks. You can use$context.task.token
to query the value. You can run task status callbacks by passing theTaskToken
parameter to call the ReportTaskSucceeded and ReportTaskFailed operations.
- TaskToken
- Fields in serviceParams
- MessageBody: This is the message body string to be sent.
- MessageTag: Optional. This is the tag of the message to be sent.
- MessageAttributes: Optional. You must specify this parameter to push messages in specific ways. The value must be a JSON string.
- Mail push: The parameters must include MailAttributes, 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.