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

     1  # AMQP
     2  
     3  AMQP event-source listens to messages on the MQ 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                 "contentType": "ContentType is the MIME content type",
    21                 "contentEncoding": "ContentEncoding is the MIME content encoding",
    22                 "deliveryMode": "Delivery mode can be either - non-persistent (1) or persistent (2)",
    23                 "priority": "Priority refers to the use - 0 to 9",
    24                 "correlationId": "CorrelationId is the correlation identifier",
    25                 "replyTo": "ReplyTo is the address to reply to (ex: RPC)",
    26                 "expiration": "Expiration refers to message expiration spec",
    27                 "messageId": "MessageId is message identifier",
    28                 "timestamp": "Timestamp refers to the message timestamp",
    29                 "type": "Type refers to the message type name",
    30                 "appId": "AppId refers to the application id",
    31                 "exchange": "Exchange is basic.publish exchange",
    32                 "routingKey": "RoutingKey is basic.publish routing key",
    33                 "body": "Body represents the message body",
    34              }
    35          }
    36  
    37  <br/>
    38  
    39  ## Setup
    40  
    41  1. Lets set up RabbitMQ locally.
    42  
    43          apiVersion: v1
    44          kind: Service
    45          metadata:
    46            labels:
    47              component: rabbitmq
    48            name: rabbitmq-service
    49          spec:
    50            ports:
    51              - port: 5672
    52            selector:
    53              app: taskQueue
    54              component: rabbitmq
    55          ---
    56          apiVersion: v1
    57          kind: ReplicationController
    58          metadata:
    59            labels:
    60              component: rabbitmq
    61            name: rabbitmq-controller
    62          spec:
    63            replicas: 1
    64            template:
    65              metadata:
    66                labels:
    67                  app: taskQueue
    68                  component: rabbitmq
    69              spec:
    70                containers:
    71                  - image: rabbitmq
    72                    name: rabbitmq
    73                    ports:
    74                      - containerPort: 5672
    75                    resources:
    76                      limits:
    77                        cpu: 100m
    78  
    79  2. Make sure the RabbitMQ controller pod is up and running before proceeding further.
    80  
    81  3. Expose the RabbitMQ server to local publisher using `port-forward`.
    82  
    83          kubectl -n argo-events port-forward <rabbitmq-pod-name> 5672:5672
    84  
    85  4. Create the event source by running the following command.
    86  
    87          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/amqp.yaml
    88  
    89  6. Inspect the event-source pod logs to make sure it was able to subscribe to the exchange specified in the event source to consume messages.
    90  
    91  7. 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/amqp.yaml
    94  
    95  8. Lets set up a RabbitMQ publisher. If you don't have `pika` installed, run.
    96  
    97          python -m pip install pika --upgrade
    98  
    99  9. Open a python REPL and run following code to publish a message on `exchange` called `test`.
   100  
   101          import pika
   102          connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
   103          channel = connection.channel()
   104          channel.basic_publish(exchange='test',
   105                                routing_key='hello',
   106                                body='{"message": "hello"}')
   107  
   108  10. As soon as you publish a message, sensor will trigger an Argo workflow. Run `argo list` to find the workflow.
   109  
   110  ## Troubleshoot
   111  
   112  Please read the [FAQ](https://argoproj.github.io/argo-events/FAQ/).