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:
The event-driven feature enabled. See Enable the event-driven feature.
ApsaraMQ for MNS activated with the required permissions. This feature incurs ApsaraMQ for MNS charges. See Activate ApsaraMQ for MNS and grant permissions and Billing overview.
A workflow cluster created and kubectl configured. See Create a workflow cluster and Obtain the KubeConfig file of a cluster and use kubectl to connect to the cluster.
The Alibaba Cloud Argo CLI installed. See Install the Alibaba Cloud Argo CLI.
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.
| Option | Description | When to use |
|---|---|---|
| NATS | Runs as pods inside your cluster | Lightweight testing or when SMQ integration is not required |
| SMQ | Uses Alibaba Cloud ApsaraMQ for MNS as the transport layer | Reliable 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
Create an
event-bus.yamlfile:apiVersion: argoproj.io/v1alpha1 kind: EventBus metadata: name: default spec: nats: native: replicas: 3 auth: tokenApply 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.yamlVerify that the event bus pod has started:
kubectl get pod
Create via SMQ
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.Log in to the RAM console as a RAM user with administrative rights. Create a RAM user, grant the
AliyunMNSFullAccesspermission, 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.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>Create an
event-bus-mns.yamlfile. Replace thetopicandendpointvalues 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 endpointApply 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.
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.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.Log in to the RAM console as a RAM user with administrative rights. Create a RAM user, grant the
AliyunMNSFullAccesspermission, and get the AccessKey ID and AccessKey Secret.Create a Kubernetes Secret:
kubectl create secret generic mns-secret \ --from-literal=accesskey=<your-access-key-id> \ --from-literal=secretkey=<your-access-key-secret>Create an
event-source.yamlfile. Replacequeueandendpointwith 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 endpointApply the file:
kubectl apply -f event-source.yamlVerify 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:
| Field | Value | Description |
|---|---|---|
src.dependencyName | test-dep | The dependency to read the event from |
src.dataKey | body | The field within data to extract (the Base64-encoded message content) |
dest | spec.arguments.parameters.0.value | The workflow parameter to write the extracted value into |
Create an
event-sensor.yamlfile with the following content:Apply the file:
kubectl apply -f event-sensor.yamlVerify 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
Log in to the SMQ console. On the Queue List page, find
test-event-queueand click Send and Receive Messages in the Actions column.On the Send and Receive Messages Quick Start page, enter
test trigger argo workflowas the message content and click Send Message.Check that a workflow was triggered:
argo listThe output shows a running workflow:
NAME STATUS AGE DURATION PRIORITY ali-mns-workflow-5prz7 Running 6s 6s 0Retrieve the workflow logs to see the message content:
argo logs ali-mns-workflow-5prz7ImportantReplace
ali-mns-workflow-5prz7with the workflow name returned in the previous step.The message content in the logs is Base64-encoded.
Step 5: Delete event-related resources
Delete the event sensor, event source, and event bus:
kubectl delete sensor ali-mns kubectl delete eventsource ali-mns kubectl delete eventbus defaultConfirm that all pods are removed:
kubectl get pod