Use Multiple Sources in One EventSource

This document describes how to use multiple sources in one EventSource.

Prerequisites

  • You need to create a function as the target function to be triggered. Please refer to Create a function for more details.
  • You need to create a Kafka cluster. Please refer to Create a Kafka cluster for more details.

Use Multiple Sources in One EventSource

  1. Use the following content to create an EventSource configuration file (for example, eventsource-multi.yaml).

    Note

    • The following example defines an event source named my-eventsource and mark the events generated by the specified Kafka server as sample-three.
    • spec.sink references the target function (Knative service).
    • The configuration of spec.cron is to trigger the function defined in spec.sink every 5 seconds.
    1. apiVersion: events.openfunction.io/v1alpha1
    2. kind: EventSource
    3. metadata:
    4. name: my-eventsource
    5. spec:
    6. logLevel: "2"
    7. kafka:
    8. sample-three:
    9. brokers: "kafka-server-kafka-brokers.default.svc.cluster.local:9092"
    10. topic: "events-sample"
    11. authRequired: false
    12. cron:
    13. sample-three:
    14. schedule: "@every 5s"
    15. sink:
    16. uri: "http://openfunction.io.svc.cluster.local/default/sink"
  2. Run the following command to apply the configuration file.

    1. kubectl apply -f eventsource-multi.yaml
  3. Run the following commands to observe changes.

    1. $ kubectl get eventsources.events.openfunction.io
    2. NAME EVENTBUS SINK STATUS
    3. my-eventsource Ready
    4. $ kubectl get components
    5. NAME AGE
    6. serving-vqfk5-component-esc-cron-sample-three-dzcpv 35s
    7. serving-vqfk5-component-esc-kafka-sample-one-nr9pq 35s
    8. serving-vqfk5-component-ts-my-eventsource-default-q6g6m 35s
    9. $ kubectl get deployments.apps
    10. NAME READY UP-TO-DATE AVAILABLE AGE
    11. serving-4x5wh-ksvc-wxbf2-v100-deployment 1/1 1 1 3h14m
    12. serving-vqfk5-deployment-v100-vdmvj 1/1 1 1 48s