github.com/argoproj/argo-events@v1.9.1/docs/sensors/triggers/nats-trigger.md (about)

     1  # NATS Trigger
     2  
     3  NATS trigger allows sensor to publish events on NATS subjects. This trigger helps source the events from outside world into your messaging queues.
     4  
     5  ## Specification
     6  
     7  The NATS trigger specification is available [here](https://github.com/argoproj/argo-events/blob/master/api/sensor.md#natstrigger).
     8  
     9  ## Walkthrough
    10  
    11  1. Consider a scenario where you are expecting a file drop onto a Minio bucket and want to place that event
    12     on a NATS subject.
    13  
    14  1. Set up the Minio Event Source [here](https://argoproj.github.io/argo-events/eventsources/setup/minio/).
    15     Do not create the Minio sensor, we are going to create it in next step.
    16  
    17  1. Lets create the sensor.
    18  
    19          apiVersion: argoproj.io/v1alpha1
    20          kind: Sensor
    21          metadata:
    22            name: minio-sensor
    23          spec:
    24            dependencies:
    25              - name: test-dep
    26                eventSourceName: minio
    27                eventName: example
    28            triggers:
    29              - template:
    30                  name: nats-trigger
    31                  nats:
    32                    # NATS Server URL
    33                    url: nats.argo-events.svc:4222
    34                    # Name of the subject
    35                    subject: minio-events
    36                    payload:
    37                      - src:
    38                          dependencyName: test-dep
    39                          dataKey: notification.0.s3.object.key
    40                        dest: fileName
    41                      - src:
    42                          dependencyName: test-dep
    43                          dataKey: notification.0.s3.bucket.name
    44                        dest: bucket
    45  
    46  1. The NATS message needs a body. In order to construct message based on the event data, sensor offers
    47     `payload` field as a part of the NATS trigger.
    48  
    49     The `payload` contains the list of `src` which refers to the source event and `dest` which refers to destination key within result request payload.
    50  
    51     The `payload` declared above will generate a message body like below,
    52  
    53          {
    54              "fileName": "hello.txt" // name/key of the object
    55              "bucket": "input" // name of the bucket
    56          }
    57  
    58  1. If you are running NATS on local K8s cluster, make sure to `port-forward` to pod.
    59  
    60          kubectl -n argo-events port-forward <nats-pod-name> 4222:4222
    61  
    62  1. Subscribe to the subject called `minio-events`. Refer the nats example to publish a message to the subject <https://github.com/nats-io/go-nats-examples/tree/master/patterns/publish-subscribe>.
    63  
    64             go run main.go -s localhost minio-events'
    65  
    66  1. Drop a file called `hello.txt` onto the bucket `input` and you will receive the message on NATS subscriber as follows.
    67  
    68          [#1] Received on [minio-events]: '{"bucket":"input","fileName":"hello.txt"}'