This sample shows how to configure a Channel backed by Cloud Pub/Sub. This is an implementation of a Knative Channel intended to provide a durable messaging solution.
-
Install Knative Eventing,
- To install Knative Eventing, first install the CRDs by running the kubectl apply command once with the -l knative.dev/crd-install=true flag. This prevents race conditions during the install, which cause intermittent errors:
kubectl apply --selector knative.dev/crd-install=true \ --filename https://github.com/knative/eventing/releases/download/v0.8.0/release.yaml
kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.8.0/release.yaml
-
Create a
Channel
.Note: Update
project
andsecret
if you are not using defaults.kubectl apply --filename channel.yaml
After a moment, the demo channel should become ready.
kubectl get pschan demo
-
Create a subscriber,
event-display
.kubectl apply --filename event-display.yaml
-
Create a
Subscription
.kubectl apply --filename subscription.yaml
After a moment, the subscription will become ready.
kubectl get Subscription demo
-
Create an event source.
kubectl apply --filename source.yaml
This will send an event through the
demo
channel every minute on the minute.
This results in the following:
[hello-world] --> [demo channel] -> [event-display]
-
Inspect the logs of the
event-display
pod:kubectl logs --selector app=event-display -c user-container
You should see log lines similar to:
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 0.3
type: dev.knative.cronjob.event
source: /apis/v1/namespaces/default/cronjobsources/hello-world
id: 37a8a186-acc0-4c63-b1ad-a8dac9caf288
time: 2019-08-26T20:48:00.000475893Z
datacontenttype: application/json
Data,
{
"hello": "world"
}
These events are generated from the hello-world
CronJobSource, sent through
the demo
Channel and delivered to the event-display
via the demo
Subscription.
The Channel
implements what Knative Eventing considers to be a channelable
.
This component can work alone, but it also works well when
Knative Serving and Eventing are installed in
the cluster.
- Delete the resources:
kubectl delete \
--filename channel.yaml \
--filename event-display.yaml \
--filename subscription.yaml \
--filename source.yaml