All Products
Search
Document Center

Container Service for Kubernetes:Trigger a workflow using Simple Message Queue (formerly MNS)

Last Updated:Nov 24, 2025

A workflow cluster can be integrated with Alibaba Cloud Simple Message Queue (formerly MNS). You can use Simple Message Queue (formerly MNS) as an intermediary to connect to various event sources and trigger workflows. When a new event, such as an OSS or EventBridge event, occurs, Simple Message Queue (formerly MNS) receives a corresponding message. Argo then automatically triggers a workflow based on the specified event trigger conditions. This process automates workflow execution.

Prerequisites

Step 1: Create an Event Bus

An Event Bus can be shared by event-driven workflows within a namespace. You can create an Event Bus using NATS or Simple Message Queue (formerly MNS). If you have already created an Event Bus, you can skip to Step 2: Create an Event Source.

Create via NATS

  1. Create an event-bus.yaml file. The following code is an example:

    apiVersion: argoproj.io/v1alpha1
    kind: EventBus
    metadata:
      name: default
    spec:
      nats:
        native:
          replicas: 3
          auth: token
  2. Run the following command to create the EventBus.

    kubectl apply -f event-bus.yaml
    Note

    After the command runs successfully, an Event Bus pod is created in the default namespace. You must perform all subsequent operations in the same namespace.

  3. Run the following command to verify that the Event Bus pod has started.

    kubectl get pod

Create using Simple Message Queue (formerly MNS)

  1. Log on to the SMQ console.

  2. On the Topics page, create a topic named argoeventbus. On the Topic Details page, obtain the endpoint from the Endpoint section.

  3. Log on to the RAM console as a RAM user who has administrative rights.

  4. Create a RAM user, grant the AliyunMNSFullAccess permission to the RAM user, and then obtain the AccessKey ID and AccessKey secret of the RAM user.

    For more information, see Create a RAM user, Grant permissions to a RAM user, Create an AccessKey pair, and View the AccessKey information of a RAM user.

  5. Run the following command to create a Secret to store the AccessKey ID and AccessKey secret.

    kubectl create secret generic mns-secret\
      --from-literal=accesskey=*** \
      --from-literal=secretkey=***
  6. Create an event-bus-mns.yaml file and replace the parameter values in the example with your actual values.

    • topic: Replace this value with the name of the Simple Message Queue (formerly MNS) topic that you created in Step 2.

    • endpoint: Replace this value with the endpoint that you obtained in Step 2.

    apiVersion: argoproj.io/v1alpha1
    kind: EventBus
    metadata:
      name: default
    spec:
      alimns:
        accessKey:
          key: accesskey
          name: mns-secret
        secretKey:
          key: secretkey
          name: mns-secret
        topic: argoeventbus  # The name of the Simple Message Queue (formerly MNS) topic.
        endpoint: http://165***368.mns.<region>.aliyuncs.com  # The endpoint of Simple Message Queue (formerly MNS).
  7. Run the following command to apply the event-bus-mns.yaml file and create the Event Bus resource.

    kubectl apply -f event-bus-mns.yaml

Step 2: Create an Event Source

  1. Log on to the SMQ console.

  2. On the Queues page, create a queue named test-event-queue. On the Queue Details page, obtain the endpoint from the Endpoint section.

    Note

    If you created the Event Bus using Simple Message Queue (formerly MNS), you can skip Step 3 to Step 5 and proceed directly to Step 6.

  3. Log on to the RAM console as a RAM user who has administrative rights.

  4. Create a RAM user, grant the AliyunMNSFullAccess permission to the RAM user, and then obtain the AccessKey ID and AccessKey secret of the RAM user.

    For more information, see Create a RAM user, Grant permissions to a RAM user, Create an AccessKey pair, and View the AccessKey information of a RAM user.

  5. Run the following command to create a Secret to store the AccessKey ID and AccessKey secret.

    kubectl create secret generic mns-secret\
      --from-literal=accesskey=*** \
      --from-literal=secretkey=***
  6. Create an event-source.yaml file and replace the parameter values in the example with your actual values.

    • topic: Set this parameter to the name of the topic in Simple Message Queue (formerly MNS) that you created in Step 2.

    • endpoint: Replace this value with the endpoint that you obtained in Step 2.

    apiVersion: argoproj.io/v1alpha1
    kind: EventSource
    metadata:
      name: ali-mns
    spec:
      mns:
        example:
          jsonBody: true
          accessKey:
            key: accesskey
            name: mns-secret
          secretKey:
            key: secretkey
            name: mns-secret
          queue: test-event-queue # The name of the Simple Message Queue (formerly MNS) queue.
          waitTimeSeconds: 20
          endpoint: http://165***368.mns.<region>.aliyuncs.com # The endpoint of Simple Message Queue (formerly MNS).
  7. Run the following command to apply the event-source.yaml file and create the Event Source.

    kubectl apply -f event-source.yaml
  8. Run the following command to check whether the Event Source pod starts as expected.

    kubectl get pod

Step 3: Create an Event Sensor

  1. Create an event-sensor.yaml file and embed the workflow definition to be run in the Event Sensor. The following code provides an example of an Event Sensor:

    Click to view the sample code

    apiVersion: argoproj.io/v1alpha1
    kind: Sensor
    metadata:
      name: ali-mns
    spec:
      template:
        serviceAccountName: default
      dependencies:
        - name: test-dep
          eventSourceName: ali-mns    # Match the event source name.
          eventName: example          # Match the event name definition in the event source.
      triggers:
        - template:
            name: mns-workflow
            k8s:
              operation: create
              source:
                resource:
                  apiVersion: argoproj.io/v1alpha1    # Embed the workflow definition.
                  kind: Workflow
                  metadata:
                    generateName: ali-mns-workflow-
                  spec:
                    entrypoint: whalesay
                    arguments:
                      parameters:        # Pass the event content as a parameter.
                        - name: message
                          # this is the value that should be overridden
                          value: hello world
                    templates:
                      - name: whalesay
                        inputs:
                          parameters:
                            - name: message
                        container:
                          image: docker/whalesay:latest
                          command: [cowsay]
                          args: ["{{inputs.parameters.message}}"]
              parameters:
                - src:        # Parse the event content and pass it to the workflow.
                    dependencyName: test-dep
                    dataKey: body
                  dest: spec.arguments.parameters.0.value
  2. Run the following command to apply the event-sensor.yaml file and create the Event Sensor.

    kubectl apply -f event-sensor.yaml
  3. Run the following command to check whether the Event Sensor pod starts as expected.

    kubectl get pod
Note

When you create an Event Bus using Simple Message Queue (formerly MNS), a corresponding Simple Message Queue (formerly MNS) queue is automatically created after you create the Event Sensor. The queue is named in the following format: ackone-argowf-<namespace>-<sensor-name>-<sensor-uid>.

Step 4: Verify that sending a message to Simple Message Queue (formerly MNS) triggers a workflow

  1. Log on to the SMQ console.

  2. On the Queues page, find the test-event-queue queue and click Send Messages in the Actions column.

  3. On the Quick Experience page, enter test trigger argo workflow as the message content and then click Send Message.

  4. Run the following command to check the status of the workflow in the workflow cluster.

    argo list

    The following output is returned:

    NAME                     STATUS    AGE   DURATION   PRIORITY
    ali-mns-workflow-5prz7   Running   6s    6s         0
  5. Run the following command to obtain the workflow logs and view the message content.

    argo logs ali-mns-workflow-5prz7
    Important
    • The workflow name in this command must be the same as the workflow name that is returned in the previous step. ali-mns-workflow-5prz7 is an example. You must replace it with the actual return value in your environment.

    • The message content is Base64-encoded.

    The following output is returned: image.png

Step 5: Delete event-related resources

  1. Delete the related resources.

    • Delete the Event Sensor

      kubectl delete sensor ali-mns
    • Delete the Event Source

      kubectl delete eventsource ali-mns
    • Delete the Event Bus

      kubectl delete eventbus default
  2. Run the following command to check the pod status and confirm that all resources are deleted.

    kubectl get pod