All Products
Search
Document Center

Container Service for Kubernetes:Trigger workflows by using ApsaraMQ for MNS

Last Updated:Mar 26, 2026

ApsaraMQ for MNS lets your workflow cluster react to external events automatically. When a message arrives in an ApsaraMQ for MNS queue or topic — from OSS, EventBridge, or any other source — Argo Events picks it up and triggers the corresponding workflow.

This guide walks through three Argo Events components you'll configure in sequence:

  • Event bus — the communication backbone shared by all event-driven workflows in a namespace

  • Event source — connects to the SMQ queue and forwards incoming messages as events

  • Event sensor — listens for events from the event source and launches a workflow when conditions match

Prerequisites

Before you begin, make sure you have:

Step 1: Create an event bus

An event bus is shared by all event-driven workflows in a namespace. You can create one using NATS or SMQ.

OptionDescriptionWhen to use
NATSRuns as pods inside your clusterLightweight testing or when SMQ integration is not required
SMQUses Alibaba Cloud ApsaraMQ for MNS as the transport layerReliable cross-service messaging and integration with the Alibaba Cloud ecosystem

If you already have an event bus, skip to Step 2: Create an event source.

Create via NATS

  1. Create an event-bus.yaml file:

    apiVersion: argoproj.io/v1alpha1
    kind: EventBus
    metadata:
      name: default
    spec:
      nats:
        native:
          replicas: 3
          auth: token
  2. Apply the file to create the event bus:

    After this command runs, an event bus pod is created in the default namespace. All subsequent steps must be performed in the same namespace.
    kubectl apply -f event-bus.yaml
  3. Verify that the event bus pod has started:

    kubectl get pod

Create via SMQ

  1. Log in to the SMQ console. On the Topic List page, create a topic named argoeventbus. On the Topic Details page, copy the endpoint from the Endpoint section.

  2. Log in to the RAM console as a RAM user with administrative rights. Create a RAM user, grant the AliyunMNSFullAccess permission, and get the AccessKey ID and AccessKey Secret of the new user. For details, see Create a RAM user, Grant permissions to a RAM user, Create an AccessKey pair, and View the AccessKey information of a RAM user.

  3. Create a Kubernetes Secret to store the credentials:

    kubectl create secret generic mns-secret \
      --from-literal=accesskey=<your-access-key-id> \
      --from-literal=secretkey=<your-access-key-secret>
  4. Create an event-bus-mns.yaml file. Replace the topic and endpoint values with what you copied in step 1:

    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                                        # SMQ topic name
        endpoint: http://165***368.mns.<region>.aliyuncs.com      # SMQ endpoint
  5. Apply the file to create the event bus:

    kubectl apply -f event-bus-mns.yaml

Step 2: Create an event source

The event source connects to an SMQ queue and forwards each message as an event that the sensor can act on.

  1. Log in to the SMQ console. On the Queue List page, create a queue named test-event-queue. On the Queue Details page, copy the endpoint from the Endpoint section.

  2. If you already created an event bus via SMQ (and therefore already have an mns-secret), skip steps 3 and 4 and go directly to step 5.

  3. Log in to the RAM console as a RAM user with administrative rights. Create a RAM user, grant the AliyunMNSFullAccess permission, and get the AccessKey ID and AccessKey Secret.

  4. Create a Kubernetes Secret:

    kubectl create secret generic mns-secret \
      --from-literal=accesskey=<your-access-key-id> \
      --from-literal=secretkey=<your-access-key-secret>
  5. Create an event-source.yaml file. Replace queue and endpoint with your actual values:

    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                                    # SMQ queue name
          waitTimeSeconds: 20
          endpoint: http://165***368.mns.<region>.aliyuncs.com      # SMQ endpoint
  6. Apply the file:

    kubectl apply -f event-source.yaml
  7. Verify that the event source pod has started:

    kubectl get pod

Step 3: Create an event sensor

The sensor listens for events from ali-mns and launches a workflow each time one arrives. It maps the event's data.body field directly to the workflow's message parameter — the content you send to the SMQ queue becomes the workflow input.

The parameters block in the sensor YAML controls this mapping:

FieldValueDescription
src.dependencyNametest-depThe dependency to read the event from
src.dataKeybodyThe field within data to extract (the Base64-encoded message content)
destspec.arguments.parameters.0.valueThe workflow parameter to write the extracted value into
  1. Create an event-sensor.yaml file with the following content:

    Expand to view sample code

    apiVersion: argoproj.io/v1alpha1
    kind: Sensor
    metadata:
      name: ali-mns
    spec:
      template:
        serviceAccountName: default
      dependencies:
        - name: test-dep
          eventSourceName: ali-mns    # Must match the EventSource name
          eventName: example          # Must match the event name in the EventSource
      triggers:
        - template:
            name: mns-workflow
            k8s:
              operation: create
              source:
                resource:
                  apiVersion: argoproj.io/v1alpha1
                  kind: Workflow
                  metadata:
                    generateName: ali-mns-workflow-
                  spec:
                    entrypoint: whalesay
                    arguments:
                      parameters:
                        - name: message
                          value: hello world    # Overridden by the event payload below
                    templates:
                      - name: whalesay
                        inputs:
                          parameters:
                            - name: message
                        container:
                          image: docker/whalesay:latest
                          command: [cowsay]
                          args: ["{{inputs.parameters.message}}"]
              parameters:
                - src:
                    dependencyName: test-dep
                    dataKey: body             # Extracts data.body from the CloudEvent
                  dest: spec.arguments.parameters.0.value    # Writes to the workflow's message parameter
  2. Apply the file:

    kubectl apply -f event-sensor.yaml
  3. Verify that the sensor pod has started:

    kubectl get pod
If you created the event bus using ApsaraMQ for MNS, an ApsaraMQ for MNS queue is automatically created when the sensor starts. It follows the naming pattern ackone-argowf-<namespace>-<sensor-name>-<sensor-uid>.

Step 4: Verify that the workflow is triggered

  1. Log in to the SMQ console. On the Queue List page, find test-event-queue and click Send and Receive Messages in the Actions column.

  2. On the Send and Receive Messages Quick Start page, enter test trigger argo workflow as the message content and click Send Message.

  3. Check that a workflow was triggered:

    argo list

    The output shows a running workflow:

    NAME                     STATUS    AGE   DURATION   PRIORITY
    ali-mns-workflow-5prz7   Running   6s    6s         0
  4. Retrieve the workflow logs to see the message content:

    argo logs ali-mns-workflow-5prz7
    Important
    • Replace ali-mns-workflow-5prz7 with the workflow name returned in the previous step.

    • The message content in the logs is Base64-encoded.

Step 5: Delete event-related resources

  1. Delete the event sensor, event source, and event bus:

    kubectl delete sensor ali-mns
    kubectl delete eventsource ali-mns
    kubectl delete eventbus default
  2. Confirm that all pods are removed:

    kubectl get pod