Skip to content

NATS Trigger

NATS trigger allows sensor to publish events on NATS subjects. This trigger helps source the events from outside world into your messaging queues.


The NATS trigger specification is available here.


  1. Consider a scenario where you are expecting a file drop onto a Minio bucket and want to place that event on a NATS subject.

  2. Set up the Minio Event Source here. Do not create the Minio sensor, we are going to create it in next step.

  3. Lets create the sensor.

    kind: Sensor
      name: minio-sensor
        - name: test-dep
          eventSourceName: minio
          eventName: example
        - template:
            name: nats-trigger
              # NATS Server URL
              url: nats.argo-events.svc:4222
              # Name of the subject
              subject: minio-events
                - src:
                    dependencyName: test-dep
                    dataKey: notification.0.s3.object.key
                  dest: fileName
                - src:
                    dependencyName: test-dep
                  dest: bucket
  4. The NATS message needs a body. In order to construct message based on the event data, sensor offers payload field as a part of the NATS trigger.

The payload contains the list of src which refers to the source event and dest which refers to destination key within result request payload.

The payload declared above will generate a message body like below,

        "fileName": "hello.txt" // name/key of the object
        "bucket": "input" // name of the bucket
  1. If you are running NATS on local K8s cluster, make sure to port-forward to pod.

    kubectl -n argo-events port-forward <nats-pod-name> 4222:4222
  2. Subscribe to the subject called minio-events. Refer the nats example to publish a message to the subject

       go run main.go -s localhost minio-events'
  3. Drop a file called hello.txt onto the bucket input and you will receive the message on NATS subscriber as follows.

    [#1] Received on [minio-events]: '{"bucket":"input","fileName":"hello.txt"}'
Back to top