github.com/argoproj/argo-events@v1.9.1/docs/eventsources/setup/nsq.md (about)

     1  # NSQ
     2  
     3  NSQ event-source subscribes to nsq pub/sub 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                     "body": "Body is the message data",
    21                     "timestamp": "timestamp of the message",
    22                     "nsqdAddress": "NSQDAddress is the address of the nsq host"
    23                  }
    24              }
    25  
    26  ## Specification
    27  
    28  NSQ event-source is available [here](https://github.com/argoproj/argo-events/blob/master/api/event-source.md#nsqeventsource).
    29  
    30  ## Setup
    31  
    32  1. Deploy NSQ on local K8s cluster.
    33  
    34          apiVersion: v1
    35          kind: Service
    36          metadata:
    37            name: nsqlookupd
    38            labels:
    39              app: nsq
    40          spec:
    41            ports:
    42              - port: 4160
    43                targetPort: 4160
    44                name: tcp
    45              - port: 4161
    46                targetPort: 4161
    47                name: http
    48            clusterIP: None
    49            selector:
    50              app: nsq
    51              component: nsqlookupd
    52          ---
    53          apiVersion: v1
    54          kind: Service
    55          metadata:
    56            name: nsqd
    57            labels:
    58              app: nsq
    59          spec:
    60            ports:
    61              - port: 4150
    62                targetPort: 4150
    63                name: tcp
    64              - port: 4151
    65                targetPort: 4151
    66                name: http
    67            clusterIP: None
    68            selector:
    69              app: nsq
    70              component: nsqd
    71          ---
    72          apiVersion: v1
    73          kind: Service
    74          metadata:
    75            name: nsqadmin
    76            labels:
    77              app: nsq
    78          spec:
    79            ports:
    80              - port: 4170
    81                targetPort: 4170
    82                name: tcp
    83              - port: 4171
    84                targetPort: 4171
    85                name: http
    86            selector:
    87              app: nsq
    88              component: nsqadmin
    89          ---
    90          apiVersion: apps/v1beta1
    91          kind: StatefulSet
    92          metadata:
    93            name: nsqlookupd
    94          spec:
    95            serviceName: "nsqlookupd"
    96            replicas: 1
    97            updateStrategy:
    98              type: RollingUpdate
    99            template:
   100              metadata:
   101                labels:
   102                  app: nsq
   103                  component: nsqlookupd
   104              spec:
   105                containers:
   106                  - name: nsqlookupd
   107                    image: nsqio/nsq:v1.1.0
   108                    imagePullPolicy: Always
   109                    resources:
   110                      requests:
   111                        cpu: 30m
   112                        memory: 64Mi
   113                    ports:
   114                      - containerPort: 4160
   115                        name: tcp
   116                      - containerPort: 4161
   117                        name: http
   118                    livenessProbe:
   119                      httpGet:
   120                        path: /ping
   121                        port: http
   122                      initialDelaySeconds: 5
   123                    readinessProbe:
   124                      httpGet:
   125                        path: /ping
   126                        port: http
   127                      initialDelaySeconds: 2
   128                    command:
   129                      - /nsqlookupd
   130                terminationGracePeriodSeconds: 5
   131          ---
   132          apiVersion: apps/v1beta1
   133          kind: Deployment
   134          metadata:
   135            name: nsqd
   136          spec:
   137            replicas: 1
   138            selector:
   139              matchLabels:
   140                app: nsq
   141                component: nsqd
   142            template:
   143              metadata:
   144                labels:
   145                  app: nsq
   146                  component: nsqd
   147              spec:
   148                containers:
   149                  - name: nsqd
   150                    image: nsqio/nsq:v1.1.0
   151                    imagePullPolicy: Always
   152                    resources:
   153                      requests:
   154                        cpu: 30m
   155                        memory: 64Mi
   156                    ports:
   157                      - containerPort: 4150
   158                        name: tcp
   159                      - containerPort: 4151
   160                        name: http
   161                    livenessProbe:
   162                      httpGet:
   163                        path: /ping
   164                        port: http
   165                      initialDelaySeconds: 5
   166                    readinessProbe:
   167                      httpGet:
   168                        path: /ping
   169                        port: http
   170                      initialDelaySeconds: 2
   171                    volumeMounts:
   172                      - name: datadir
   173                        mountPath: /data
   174                    command:
   175                      - /nsqd
   176                      - -data-path
   177                      - /data
   178                      - -lookupd-tcp-address
   179                      - nsqlookupd.argo-events.svc:4160
   180                      - -broadcast-address
   181                      - nsqd.argo-events.svc
   182                    env:
   183                      - name: HOSTNAME
   184                        valueFrom:
   185                          fieldRef:
   186                            fieldPath: metadata.name
   187                terminationGracePeriodSeconds: 5
   188                volumes:
   189                  - name: datadir
   190                    emptyDir: {}
   191          ---
   192          apiVersion: extensions/v1beta1
   193          kind: Deployment
   194          metadata:
   195            name: nsqadmin
   196          spec:
   197            replicas: 1
   198            template:
   199              metadata:
   200                labels:
   201                  app: nsq
   202                  component: nsqadmin
   203              spec:
   204                containers:
   205                  - name: nsqadmin
   206                    image: nsqio/nsq:v1.1.0
   207                    imagePullPolicy: Always
   208                    resources:
   209                      requests:
   210                        cpu: 30m
   211                        memory: 64Mi
   212                    ports:
   213                      - containerPort: 4170
   214                        name: tcp
   215                      - containerPort: 4171
   216                        name: http
   217                    livenessProbe:
   218                      httpGet:
   219                        path: /ping
   220                        port: http
   221                      initialDelaySeconds: 10
   222                    readinessProbe:
   223                      httpGet:
   224                        path: /ping
   225                        port: http
   226                      initialDelaySeconds: 5
   227                    command:
   228                      - /nsqadmin
   229                      - -lookupd-http-address
   230                      - nsqlookupd.argo-events.svc:4161
   231                terminationGracePeriodSeconds: 5
   232  
   233  1. Expose NSQD by kubectl `port-forward`.
   234  
   235           kubectl -n argo-events port-forward service/nsqd 4151:4151
   236  
   237  1. Create topic `hello` and channel `my-channel`.
   238  
   239          curl -X POST 'http://localhost:4151/topic/create?topic=hello'
   240  
   241          curl -X POST 'http://localhost:4151/channel/create?topic=hello&channel=my-channel'
   242  
   243  1. Create the event source by running the following command.
   244  
   245          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/nsq.yaml
   246  
   247  1. Create the sensor by running the following command.
   248  
   249          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/nsq.yaml
   250  
   251  1. Publish a message on topic `hello` and channel `my-channel`.
   252  
   253          curl -d '{"message": "hello"}' 'http://localhost:4151/pub?topic=hello&channel=my-channel'
   254  
   255  9. Once a message is published, an argo workflow will be triggered. Run `argo list` to find the workflow.
   256  
   257  ## Troubleshoot
   258  
   259  Please read the [FAQ](https://argoproj.github.io/argo-events/FAQ/).