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<br/>kind: GcpPubSubSource<br/>metadata:<br/>  name: testing-source<br/>spec:<br/>  gcpCredsSecret:<br/>    name: google-cloud-key<br/>    key: key.json<br/>  googleCloudProject: knative-atamel<br/>  topic: testing<br/>  sink:<br/>    apiVersion: eventing.knative.dev/v1alpha1<br/>    kind: Channel<br/>    name: pubsub-test

Channel definition:

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

Apply the resources:

kubectl apply -f gcp-pubsub-source.yaml<br/>kubectl apply -f channel.yaml

Verify creation:

kubectl get gcppubsubsource<br/>kubectl get channel<br/>kubectl get pods

Subscriber service and subscription (subscriber.yaml):

apiVersion: serving.knative.dev/v1alpha1<br/>kind: Service<br/>metadata:<br/>  name: message-dumper-csharp<br/>spec:<br/>  runLatest:<br/>    configuration:<br/>      revisionTemplate:<br/>        spec:<br/>          container:<br/>            image: docker.io/{username}/message-dumper-csharp:v1<br/>---<br/>apiVersion: eventing.knative.dev/v1alpha1<br/>kind: Subscription<br/>metadata:<br/>  name: gcppubsub-source-sample-csharp<br/>spec:<br/>  channel:<br/>    apiVersion: eventing.knative.dev/v1alpha1<br/>    kind: Channel<br/>    name: pubsub-test<br/>  subscriber:<br/>    ref:<br/>      apiVersion: serving.knative.dev/v1alpha1<br/>      kind: Service<br/>      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);<br/>var eventType = cloudEvent.Attributes["eventType"];<br/>var storageUrl = ConstructStorageUrl(cloudEvent);

Vision API call:

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

Vision service and subscription definition:

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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeKubernetesKnativeGoogle 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

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.