Connect events¶
Deliver events to a function either through a Knative Eventing Broker and Trigger, or directly from an Apache Kafka topic using a runtime sidecar.
Broker subscription¶
Requirements (Broker path):
- An initialized function project using the
cloudeventstemplate (func create -l <language> -t cloudevents <name>), with a handler that logs or otherwise makes received events observable. - A Kubernetes cluster with Knative Serving and Knative Eventing installed, and
a ready Broker in your target namespace (for example
default, orexample-brokerif reusing a Quickstart cluster). - Registry push and cluster pull access as described in Deploy a function.
func subscribe records event subscription filters in func.yaml — it does
not modify the cluster until you deploy.
Pass --source with your Broker's name (if omitted, func defaults to a
Broker named default) and one or more --filter key/value pairs (all filters
must match):
func subscribe \
--source example-broker \
--filter type=dev.knative.example
kn func subscribe \
--source example-broker \
--filter type=dev.knative.example
Repeat --filter key=value to require additional CloudEvent attributes or
extensions. To change or remove subscriptions later, edit deploy.subscriptions
in func.yaml and redeploy.
Deploy and verify delivery¶
Use the same target namespace (<namespace>) for deployment, Trigger checks,
and logs (pass -n <namespace> consistently if you are not using the current
context's namespace).
-
Deploy from inside the project directory.
func deploycreates or updates the Knative Service and creates the matching Knative Triggers on the cluster:func deploy --registry <registry> -n <namespace> -
Confirm the generated Trigger is ready (
READY=True):kn trigger list -n <namespace> -
Send a matching CloudEvent (
type: dev.knative.example) toexample-broker— for example using the CloudEvents Player from Try Eventing or another event source connected to that Broker. -
Verify your function received the event by checking its pod logs (or other observable effect from your handler):
kubectl logs -n <namespace> \ -l serving.knative.dev/service=<function-name> -c user-containerConfirm your handler logged the event's ID and payload. Direct
func invokecalls the function directly and does not verify Broker routing or Trigger filters.
Consume Kafka records¶
A function can also consume records directly from an Apache Kafka topic without
a Knative Eventing Broker. When func.yaml declares a run.kafka
configuration, func deploys a language-agnostic sidecar that consumes the
topic and delivers each record to your function as a CloudEvent over HTTP, so
your function needs no Kafka client code.
Requirements (Kafka path):
- An initialized
cloudeventsfunction project and container registry push/pull access. - An accessible Apache Kafka cluster and topic.
- The KEDA or raw deployer — direct Kafka consumption (
run.kafka) is not supported with the default Knative Serving deployer (KEDA requires KEDA installed on the cluster).
For the full walkthrough — including concepts, delivery and retries, scaling, idempotency, local development, and troubleshooting — see the upstream guides: