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.
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
- A Docker installation if modification of the image is necessary.
- A kubectl installation.
- Kyma as the target deployment environment.
-
Export your Namespace as a variable by replacing the {namespace} placeholder in the following command and running it:
export KYMA_EXAMPLE_NS="{namespace}"
-
Deploy the example subscriber:
kubectl apply -f example-subscriber.yaml -n $KYMA_EXAMPLE_NS
-
Enable the Event activation:
kubectl apply -f example-event-activation.yaml -n $KYMA_EXAMPLE_NS
-
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.
-
Deploy the example subscription:
kubectl apply -f example-subscription.yaml -n $KYMA_EXAMPLE_NS
-
Deploy the example publisher:
kubectl apply -f example-publisher.yaml -n $KYMA_EXAMPLE_NS
-
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.
-
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
-
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.
To view the traces:
- Access the tracing UI.
- Select event-publish-knative-service.
- Click Find Traces.
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
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.