Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Latest commit

 

History

History
127 lines (92 loc) · 3.34 KB

README.md

File metadata and controls

127 lines (92 loc) · 3.34 KB

Cloud Pub/Sub Channel Example

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.

Prerequisites

  1. Install Knative-GCP. Remember to install Eventing as part of the installation procedure.

  2. Create a Service Account for the Data Plane

Deployment

  1. Create the Channel in channel.yaml.

    1. 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.

    2. 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
  2. Create a subscriber from event-display.yaml.

    kubectl apply --filename event-display.yaml
  3. Create a Subscription.

    kubectl apply --filename subscription.yaml

    After a moment, the subscription will become ready.

    kubectl get subscription demo
  4. 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.

Verify

This results in the following:

[hello-world] --> [demo channel] -> [event-display]
  1. 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.

Troubleshooting

You may have issues receiving desired CloudEvent. Please use Authentication Mechanism Troubleshooting to check if it is due to an auth problem.

What's Next

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.

Cleaning Up

  1. Delete the resources:
kubectl delete \
  --filename channel.yaml \
  --filename event-display.yaml \
  --filename subscription.yaml \
  --filename source.yaml