PingSource

    A PingSource produces events with a fixed payload on a specified cron schedule.

    The PingSource source type is enabled by default when you install Knative Eventing.

    This example shows how to send an event every second to a Event Display Service.

    In this step, you create one event consumer, event-display to verify that PingSource is properly working.

    To deploy the event-display consumer to your cluster, run the following command:

    1. kubectl -n pingsource-example apply -f - << EOF
    2. apiVersion: apps/v1
    3. kind: Deployment
    4. metadata:
    5. name: event-display
    6. spec:
    7. replicas: 1
    8. selector:
    9. matchLabels: &labels
    10. app: event-display
    11. metadata:
    12. labels: *labels
    13. spec:
    14. containers:
    15. - name: event-display
    16. ---
    17. kind: Service
    18. apiVersion: v1
    19. metadata:
    20. name: event-display
    21. spec:
    22. selector:
    23. app: event-display
    24. ports:
    25. - protocol: TCP
    26. port: 80
    27. EOF

    You can now create the PingSource sending an event containing {"message": "Hello world!"} every second.

    1. kn source ping create test-ping-source \
    2. --namespace pingsource-example
    3. --data '{"message": "Hello world!"}' \
    4. --sink http://event-display.svc.cluster.local

    This returns the Attributes and Data of the events that the PingSource sent to the event-display Service:

    1. ☁️ cloudevents.Event
    2. Validation: valid
    3. Context Attributes,
    4. specversion: 1.0
    5. type: dev.knative.sources.ping
    6. source: /apis/v1/namespaces/default/pingsources/test-ping-source
    7. id: d8e761eb-30c7-49a3-a421-cd5895239f2d
    8. time: 2019-12-04T14:24:00.000702251Z
    9. datacontenttype: application/json
    10. Data,
    11. {
    12. }

    Delete the namespace and all of its resources from your cluster by entering the following command:

    See the PingSource specification.