Knative: Operator’s Handbook

Filtering events

Event filtering is done via the Trigger.

For example, in the following Trigger, only events with dev.knative.samples.helloworld type will reach the service:

apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
...
spec:
  filter:
    attributes:
      type: dev.knative.samples.helloworld

This event will pass the filter:

$ curl -v "http://default-broker.default.svc.cluster.local" \
  -X POST \
  -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
  -H "Ce-Specversion: 0.3" \
  -H "Ce-Type: dev.knative.samples.helloworld" \
  -H "Ce-Source: dev.knative.samples/helloworldsource" \
  -H "Content-Type: application/json" \
  -d '{"msg":"Hello Knative!"}'

You can filter with multiple attributes. In this case, type and source:

apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
...
spec:
  filter:
    attributes:
      type: dev.knative.samples.helloworld
      source: dev.knative.samples/helloworldsource
  ...

You can also filter with extensions:

apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
...
spec:
  filter:
    attributes:
      type: dev.knative.samples.helloworld
      source: dev.knative.samples/helloworldsource
      myextension: my-extension-value
  ...

This event will pass the filter:

$ curl -v "http://default-broker.default.svc.cluster.local" \
  -X POST \
  -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
  -H "Ce-Specversion: 0.3" \
  -H "Ce-Type: dev.knative.samples.helloworld" \
  -H "Ce-Source: dev.knative.samples/helloworldsource" \
  -H "Ce-myextension: my-extension-value" \
  -H "Content-Type: application/json" \
  -d '{"msg":"Hello Knative!"}'