This sample shows how to configure a Channel backed by Cloud Pub/Sub. This is an implementation of a Knative Eventing Channel intended to provide a durable messaging solution.
-
Install Knative-GCP. Remember to install Eventing as part of the installation procedure.
-
Create the
Channel
in channel.yaml.-
If you are in GKE and using Workload Identity, update
serviceAccountName
with the Kubernetes service account you created in Create a Service Account for the Data Plane, which is bound to the Pub/Sub enabled Google service account. -
If you are using standard Kubernetes secrets, but want to use a non-default one, update
secret
with your own secret.
kubectl apply --filename channel.yaml
After a moment, the demo channel should become ready.
kubectl get channels.messaging.cloud.google.com demo
-
-
Create a subscriber from event-display.yaml.
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, in this case, a
PingSource
from source.yaml.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: 1.0
type: dev.knative.sources.ping
source: /apis/v1/namespaces/default/pingsources/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
PingSource
, sent through the
demo
Channel
and delivered to the event-display
via the demo
Subscription
.
You may have issues receiving desired CloudEvent. Please use Authentication Mechanism Troubleshooting to check if it is due to an auth problem.
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