github.com/argoproj/argo-events@v1.9.1/docs/eventsources/setup/nats.md (about) 1 # NATS 2 3 NATS event-source listens to NATS subject notifications and helps sensor trigger the workloads. 4 5 ## Event Structure 6 7 The structure of an event dispatched by the event-source over the eventbus looks like following, 8 9 { 10 "context": { 11 "type": "type_of_event_source", 12 "specversion": "cloud_events_version", 13 "source": "name_of_the_event_source", 14 "id": "unique_event_id", 15 "time": "event_time", 16 "datacontenttype": "type_of_data", 17 "subject": "name_of_the_configuration_within_event_source" 18 }, 19 "data": { 20 "subject": "name_of_the_nats_subject", 21 "headers": "headers_of_the_nats_message", 22 "body": "message_payload" 23 } 24 } 25 26 ## Specification 27 28 NATS event-source specification is available [here](https://github.com/argoproj/argo-events/blob/master/api/event-source.md#natseventssource). 29 30 ## Setup 31 32 1. Make sure to have NATS cluster deployed in the Kubernetes. If you don't have one already installed, please refer <https://github.com/nats-io/nats-operator> for details. 33 34 NATS cluster setup for test purposes, 35 36 apiVersion: v1 37 kind: Service 38 metadata: 39 name: nats 40 namespace: argo-events 41 labels: 42 component: nats 43 spec: 44 selector: 45 component: nats 46 type: ClusterIP 47 ports: 48 - name: client 49 port: 4222 50 - name: cluster 51 port: 6222 52 - name: monitor 53 port: 8222 54 --- 55 apiVersion: apps/v1beta1 56 kind: StatefulSet 57 metadata: 58 name: nats 59 namespace: argo-events 60 labels: 61 component: nats 62 spec: 63 serviceName: nats 64 replicas: 1 65 template: 66 metadata: 67 labels: 68 component: nats 69 spec: 70 containers: 71 - name: nats 72 image: nats:latest 73 ports: 74 - containerPort: 4222 75 name: client 76 - containerPort: 6222 77 name: cluster 78 - containerPort: 8222 79 name: monitor 80 livenessProbe: 81 httpGet: 82 path: / 83 port: 8222 84 initialDelaySeconds: 10 85 timeoutSeconds: 5 86 87 1. Create the event source by running the following command. 88 89 kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/nats.yaml 90 91 1. Create the sensor by running the following command. 92 93 kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/nats.yaml 94 95 1. If you are running NATS on local K8s cluster, make sure to `port-forward` to pod, 96 97 kubectl -n argo-events port-forward <nats-pod-name> 4222:4222 98 99 1. Publish a message for the subject specified in the event source. Refer the nats example to publish a message to the subject <https://github.com/nats-io/go-nats-examples/tree/master/patterns/publish-subscribe>. 100 101 go run main.go -s localhost foo '{"message": "hello"}' 102 103 1. Once a message is published, an argo workflow will be triggered. Run `argo list` to find the workflow. 104 105 ## Troubleshoot 106 107 Please read the [FAQ](https://argoproj.github.io/argo-events/FAQ/).