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

Latest commit

 

History

History
126 lines (90 loc) · 2.89 KB

README.md

File metadata and controls

126 lines (90 loc) · 2.89 KB

Cloud Pub/Sub Channel

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.

Prerequisites

  1. Create a Pub/Sub enabled Service Account

  2. Install Knative with GCP.

  3. Install Knative Eventing,

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

Deployment

  1. Create a Channel.

    Note: Update project and secret if you are not using defaults.

    kubectl apply --filename channel.yaml

    After a moment, the demo channel should become ready.

    kubectl get pschan demo
  2. Create a subscriber, event-display.

    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.

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

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