Cloud Native 10 min read

Knative Eventing: Concepts, Hello World Example, and Integration with Cloud Storage & Vision API

This article explains Knative Eventing architecture, demonstrates a Hello World event pipeline using GCP Pub/Sub, and shows how to integrate Cloud Storage events with Google Vision API through Knative services, providing full YAML definitions and command‑line steps.

Architects Research Society
Architects Research Society
Architects Research Society
Knative Eventing: Concepts, Hello World Example, and Integration with Cloud Storage & Vision API

In the previous post we covered Knative Serving for synchronous HTTP triggers; this second part focuses on asynchronous event‑driven workloads using Knative Eventing.

What is Knative Eventing?

Knative Eventing provides the primitives for loosely coupled, event‑driven services. It consists of four core components: Source (reads events from an external system), Channel (stores and forwards events), Subscription (connects a channel to a consumer), and Service (the event‑driven Knative service).

Sources, Channels, and Subscriptions

Sources pull events from systems such as Kubernetes, GitHub, Google Cloud Pub/Sub, AWS SQS, containers, or CronJobs and forward them to a Channel. Channels persist events (in‑memory, Kafka, Pub/Sub, etc.) and deliver them to all subscribed services. Subscriptions define how a Channel delivers events to a Service or another Channel.

Hello World Event

The example creates a GcpPubSubSource, an in‑memory Channel, and a Subscription that links the Channel to a simple C# Knative service that logs received messages.

GcpPubSubSource definition:

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: GcpPubSubSource
metadata:
name: testing-source
spec:
gcpCredsSecret:
name: google-cloud-key
key: key.json
googleCloudProject: knative-atamel
topic: testing
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: pubsub-test

Channel definition:

apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
metadata:
name: pubsub-test
spec:
provisioner:
apiVersion: eventing.knative.dev/v1alpha1
kind: ClusterChannelProvisioner
name: in-memory-channel

Apply the resources:

kubectl apply -f gcp-pubsub-source.yaml
kubectl apply -f channel.yaml

Verify creation:

kubectl get gcppubsubsource
kubectl get channel
kubectl get pods

Subscriber service and subscription (subscriber.yaml):

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: message-dumper-csharp
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
image: docker.io/{username}/message-dumper-csharp:v1
---
apiVersion: eventing.knative.dev/v1alpha1
kind: Subscription
metadata:
name: gcppubsub-source-sample-csharp
spec:
channel:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: pubsub-test
subscriber:
ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: message-dumper-csharp

Publish a test message:

gcloud pubsub topics publish testing --message="Hello World"

The C# service logs the Base64‑encoded payload, confirming the asynchronous flow.

Integration with Cloud Storage and Vision API

When an image is uploaded to a Cloud Storage bucket, a CloudEvent is emitted. The Knative service parses the event, extracts the storage URL, and calls the Vision API to obtain labels.

Event parsing code:

var cloudEvent = JsonConvert.DeserializeObject<CloudEvent>(content);
var eventType = cloudEvent.Attributes["eventType"];
var storageUrl = ConstructStorageUrl(cloudEvent);

Vision API call:

var visionClient = ImageAnnotatorClient.Create();
var labels = await visionClient.DetectLabelsAsync(Image.FromUri(storageUrl), maxResults: 10);

Vision service and subscription definition:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: vision-csharp
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
image: docker.io/{username}/vision-csharp:v1
---
apiVersion: eventing.knative.dev/v1alpha1
kind: Subscription
metadata:
name: gcppubsub-source-vision-csharp
spec:
channel:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: pubsub-test
subscriber:
ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: vision-csharp

After applying the YAML, uploading an image triggers the Vision service, which logs labels such as "Sea, Coast, Water, Sunset, Horizon".

This demonstrates how Knative Eventing can connect unrelated services (Cloud Storage → Vision API) in a serverless, event‑driven manner.

The series will conclude with a discussion of Knative Build in the next article.

cloud-nativeserverlesskubernetesKnativegoogle cloudEventing
Architects Research Society
Written by

Architects Research Society

A daily treasure trove for architects, expanding your view and depth. We share enterprise, business, application, data, technology, and security architecture, discuss frameworks, planning, governance, standards, and implementation, and explore emerging styles such as microservices, event‑driven, micro‑frontend, big data, data warehousing, IoT, and AI architecture.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.