We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.
PingSource example
This example shows how to configure PingSource as an event source for functions.
Before you begin
- Set up Knative Serving.
- Set up Knative Eventing.
Create a Knative Service
To verify that PingSource
is working, create a simple Knative
Service that dumps incoming messages to its log.
Use following command to create the service from STDIN:
cat <<EOF | kubectl create -f -
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
EOF
Use following command to create the service from the service.yaml
file:
kubectl apply --filename service.yaml
Create a PingSource
For each set of ping events that you want to request, create an Event Source in the same namespace as the destination.
Use following command to create the event source from STDIN:
cat <<EOF | kubectl create -f -
apiVersion: sources.knative.dev/v1alpha1
kind: PingSource
metadata:
name: test-ping-source
spec:
schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}'
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
EOF
Use following command to create the event source from the ping-source.yaml
file:
kubectl apply --filename ping-source.yaml
Verify
Verify that the message was sent to the Knative eventing system by looking at message dumper logs.
Use following command to view the logs of the event-display service:
kubectl logs -l serving.knative.dev/service=event-display -c user-container --since=10m
You can also use kail
instead of kubectl logs
to tail the logs of the subscriber.
kail -l serving.knative.dev/service=event-display -c user-container --since=10m
You should see log lines showing the request headers and body from the source:
☁️ 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,
{
"message": "Hello world!"
}
Cleanup
You can delete the PingSource instance by entering the following command:
kubectl delete pingsources.sources.knative.dev test-ping-source
kubectl delete --filename ping-source.yaml
Similarly, you can delete the Service instance via:
kubectl delete service.serving.knative.dev event-display
kubectl delete --filename service.yaml
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.