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

     1  # Azure Service Bus
     2  
     3  Service Bus event-source allows you to consume messages from queus and topics in Azure Service Bus and helps sensor trigger workflows.
     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                "id": "unique_event_id",
    12                "source": "name_of_the_event_source",
    13                "specversion": "cloud_events_version",
    14                "type": "type_of_event_source",
    15                "datacontenttype": "type_of_data",
    16                "subject": "name_of_the_configuration_within_event_source"
    17                "time": "event_time",
    18              },
    19              "data": {
    20                  "applicationProperties": "ApplicationProperties can be used to store custom metadata for a message",
    21                  "body": "Body represents the message body",
    22                  "contentType": "ContentType is the MIME content type",
    23                  "correlationID": "CorrelationID is the correlation identifier",
    24                  "enqueuedTime": "EnqueuedTime is the time when the message was enqueued",
    25                  "messageID": "ID of the message",
    26                  "replyTo": "ReplyTo is an application-defined value specify a reply path to the receiver of the message",
    27                  "sequenceNumber": "SequenceNumber is a unique number assigned to a message by Service Bus",
    28                  "subject": "Subject enables an application to indicate the purpose of the message, similar to an email subject line",
    29              }
    30          }
    31  
    32  ## Setup
    33  
    34  1. Create a queue called `test` either using Azure CLI or Azure Service Bus management console.
    35  
    36  1. Fetch your connection string for Azure Service Bus and base64 encode it.
    37  
    38  1. Create a secret called `azure-secret` as follows.
    39  
    40          apiVersion: v1
    41          kind: Secret
    42          metadata:
    43            name: azure-secret
    44          type: Opaque
    45          data:
    46            connectionstring: <base64-connection-string>
    47  
    48  1. Deploy the secret.
    49  
    50          kubectl -n argo-events apply -f azure-secret.yaml
    51  
    52  1. Create the event source by running the following command.
    53  
    54          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/azure-service-bus.yaml
    55  
    56  1. Inspect the event-source pod logs to make sure it was able to listen to the queue specified in the event source to consume messages.
    57  
    58  1. Create a sensor by running the following command.
    59  
    60          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/azure-service-bus.yaml
    61  
    62  1. Lets set up a Service Bus client. If you don't have `azure-servicebus`installed, run.
    63  
    64          python -m pip install azure-servicebus --upgrade
    65  
    66  1. Open a python REPL and run the following code to send a message on the queue called `test`.
    67  
    68      Before running the code, make sure you have the `SERVICE_BUS_CONNECTION_STRING` environment variable set.
    69      This is the connection string for your Azure Service Bus.
    70  
    71          import os, json
    72          from azure.servicebus import ServiceBusClient, ServiceBusMessage
    73          servicebus_client = ServiceBusClient.from_connection_string(conn_str=os.environ['SERVICE_BUS_CONNECTION_STRING'])
    74          with servicebus_client:
    75              sender = servicebus_client.get_queue_sender(queue_name="test")
    76              with sender:
    77                  message = ServiceBusMessage('{"hello": "world"}')
    78                  sender.send_messages(message)
    79  
    80  2. As soon as you publish a message, sensor will trigger an Argo workflow. Run argo list to find the workflow.