PingSource example

    1. Set up Knative Serving.
    2. Set up .

    To verify that is working, create a simple Knative Service that dumps incoming messages to its log.

    {{< tabs name=”create-service” default=”By YAML” >}} {{% tab name=”By YAML” %}} Use following command to create the service from STDIN:

    {{< /tab >}}

    {{% tab name=”By filename” %}} Use following command to create the service from the service.yaml file:

    1. kubectl apply --filename service.yaml

    {{< /tab >}} {{< /tabs >}}

    For each set of ping events that you want to request, create an Event Source in the same namespace as the destination.

    {{< tabs name=”create-source” default=”By YAML” >}} {{% tab name=”By YAML” %}} Use following command to create the event source from STDIN:

    1. apiVersion: sources.knative.dev/v1beta1
    2. kind: PingSource
    3. metadata:
    4. name: test-ping-source
    5. schedule: "*/2 * * * *"
    6. jsonData: '{"message": "Hello world!"}'
    7. sink:
    8. apiVersion: serving.knative.dev/v1
    9. kind: Service
    10. name: event-display

    {{< /tab >}}

    {{< /tab >}} {{< /tabs >}}

    Verify that the message was sent to the Knative eventing system by looking at message dumper logs.

    {{< tabs name=”view-event” default=”kubectl” >}} {{% tab name=”kubectl” %}}

    Use following command to view the logs of the event-display service:

    1. kubectl logs -l serving.knative.dev/service=event-display -c user-container --since=10m

    {{< /tab >}} {{% tab name=”kail” %}}

    You can also use kail instead of kubectl logs to tail the logs of the subscriber.

    1. kail -l serving.knative.dev/service=event-display -c user-container --since=10m

    {{< /tab >}} {{< /tabs >}}

    You should see log lines showing the request headers and body from the source:

    {{< tabs name=”delete-source” default=”By name” >}} {{% tab name=”By name” %}}

    1. kubectl delete pingsources.sources.knative.dev test-ping-source

    {{< /tab >}}

    {{% tab name=”By filename” %}}

    1. kubectl delete --filename ping-source.yaml

    {{< /tab >}} {{< /tabs >}}

    Similarly, you can delete the Service instance via:

    {{< tabs name=”delete-service” default=”By name” >}} {{% tab name=”By name” %}}

    {{< /tab >}} {{% tab name=”By filename” %}}

      {{< /tab >}}