title | linkTitle | weight | type |
---|---|---|---|
PingSource |
PingSource |
31 |
docs |
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.
Create a new namespace called pingsource-example
by entering the following
command:
kubectl create namespace pingsource-example
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
template:
metadata:
labels: *labels
spec:
containers:
- name: event-display
image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
---
kind: Service
apiVersion: v1
metadata:
name: event-display
spec:
selector:
app: event-display
ports:
- protocol: TCP
port: 80
targetPort: 8080
EOF
You can now create the PingSource
sending an event containing
{"message": "Hello world!"}
every second.
{{< tabs name="create-source" default="YAML" >}} {{% tab name="YAML" %}}
kubectl create -n pingsource-example -f - <<EOF
apiVersion: sources.knative.dev/v1beta1
kind: PingSource
metadata:
name: test-ping-source
spec:
schedule: "*/1 * * * *"
jsonData: '{"message": "Hello world!"}'
sink:
ref:
apiVersion: v1
kind: Service
name: event-display
EOF
{{< /tab >}}
{{% tab name="kn" %}}
kn source ping create test-ping-source \
--namespace pingsource-example
--schedule "*/1 * * * *" \
--data '{"message": "Hello world!"}' \
--sink http://event-display.svc.cluster.local
{{< /tab >}} {{< /tabs >}}
View the logs for the event-display
event consumer by
entering the following command:
kubectl -n pingsource-example logs -l app=event-display --tail=100
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,
{
"message": "Hello world!"
}
Delete the pingsource-example
namespace and all of its resources from your
cluster by entering the following command:
kubectl delete namespace pingsource-example
See the PingSource specification.
For any inquiries about this source, please reach out on to the Knative users group.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )