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:
kubectl -n pingsource-example apply -f - << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: event-display
spec:
replicas: 1
selector:
matchLabels: &labels
app: event-display
metadata:
labels: *labels
spec:
containers:
- name: event-display
---
kind: Service
apiVersion: v1
metadata:
name: event-display
spec:
selector:
app: event-display
ports:
- protocol: TCP
port: 80
EOF
You can now create the PingSource
sending an event containing {"message": "Hello world!"}
every second.
kn source ping create test-ping-source \
--namespace pingsource-example
--data '{"message": "Hello world!"}' \
--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:
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.knative.sources.ping
source: /apis/v1/namespaces/default/pingsources/test-ping-source
id: d8e761eb-30c7-49a3-a421-cd5895239f2d
time: 2019-12-04T14:24:00.000702251Z
datacontenttype: application/json
Data,
{
}
Delete the namespace and all of its resources from your cluster by entering the following command:
See the PingSource specification.