Skip to content

Latest commit

 

History

History
120 lines (87 loc) · 3.05 KB

README.md

File metadata and controls

120 lines (87 loc) · 3.05 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 Pub/Sub enabled Service Account

Deployment

  1. Create the Channel in channel.yaml.

    1. If you are in GKE and using Workload Identity, update serviceAccount with the Pub/Sub enabled service account you created in Create a Pub/Sub enabled 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 CronJobSource 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.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