Skip to content

Latest commit

 

History

History
105 lines (77 loc) · 4.37 KB

README.md

File metadata and controls

105 lines (77 loc) · 4.37 KB

Event Bus Service Subscription

Overview

This example demonstrates how to publish and consume Events using the Event Bus with the Event publishing API and push-to-webhook support available in Kyma.

Details

Kyma comes with the NATS Streaming messaging cluster. Instead of interacting with the NATS Streaming cluster directly, use the publish HTTP API and the push subscription support that Kyma offers, to enable basic Event publishing and Event delivery through push notifications to an HTTP endpoint.

Access the Event publishing API from the cluster through the 8080 port on the following hostnames:

  • event-bus-publish.kyma-system
  • event-bus-publish.kyma-system.svc.cluster.local

Prerequisites

  • A Docker installation if modification of the image is necessary.
  • A kubectl installation.
  • Kyma as the target deployment environment.
  • A Namespace to which to deploy the example with the env: "true" label. For more information, read the related documentation.

Installation

  1. Export your Namespace as a variable by replacing the {namespace} placeholder in the following command and running it:

    export KYMA_EXAMPLE_NS="{namespace}"
  2. Deploy the example subscriber:

    kubectl apply -f example-subscriber.yaml -n $KYMA_EXAMPLE_NS
  3. Enable the Event activation:

    kubectl apply -f example-event-activation.yaml -n $KYMA_EXAMPLE_NS
  4. Set your Namespace on the subscription endpoint:

    #Linux
    sed -i "s/<namespace>/$KYMA_EXAMPLE_NS/g" example-subscription.yaml
    #OSX
    sed -i '' "s/<namespace>/$KYMA_EXAMPLE_NS/g" example-subscription.yaml

    To manually edit example-subscription.yaml, replace the {namespace} placeholder in the endpoint with your Namespace.

  5. Deploy the example subscription:

    kubectl apply -f example-subscription.yaml -n $KYMA_EXAMPLE_NS
  6. Deploy the example publisher:

    kubectl apply -f example-publisher.yaml -n $KYMA_EXAMPLE_NS
  7. Verify that the example subscriber and publisher Pods are running:

    kubectl get pods -n $KYMA_EXAMPLE_NS

    The system eventually applies EgressRule, which allows the example publisher container to download cURL. Istio grants access and the example publisher Pod starts.

  8. Once the example subscriber and publisher Pods are running, access the example publisher container through SSH:

    kubectl exec -n $KYMA_EXAMPLE_NS $(kubectl get pods -n $KYMA_EXAMPLE_NS -l app=example-publisher --output=jsonpath={.items..metadata.name}) -c example-publisher -i -t -- sh
  9. Publish a message:

    curl -i \
        -H "Content-Type: application/json" \
        -X POST http://event-bus-publish.kyma-system:8080/v1/events \
        -d '{"source-id": "external-application", "event-type": "test-event-bus", "event-type-version": "v1", "event-time": "2018-11-02T22:08:41+00:00", "data": {"event":{"customer":{"customerID": "1234", "uid": "rick.sanchez@mail.com"}}}}'
    
    # or use the fully-qualified Event publishing API service name
    curl -i \
        -H "Content-Type: application/json" \
        -X POST http://event-bus-publish.kyma-system.svc.cluster.local:8080/v1/events \
        -d '{"source-id": "external-application", "event-type": "test-event-bus", "event-type-version": "v1", "event-time": "2018-11-02T22:08:41+00:00", "data": {"event":{"customer":{"customerID": "1234", "uid": "rick.sanchez@mail.com"}}}}'

    NOTE: To send multiple Events, change the orderCode to have a unique value for each POST request.

Tracing

To view the traces:

  1. Access the tracing UI.
  2. Select event-publish-knative-service.
  3. Click Find Traces.

Cleanup

Exit the example publisher container and perform a cleanup using this command:

exit
kubectl delete all,subscription,eventactivation -l example=event-bus -n $KYMA_EXAMPLE_NS

Troubleshooting

NATS Streaming does not support topic and subject deletion. Thus, data such as topics and messages from previous runs accumulates if you repeat the installation steps multiple times.