Brokers can be used in combination with triggers to deliver events from an event source to an event sink.
Events can be sent from an event source to a broker as an HTTP POST request.
After events have entered the broker, they can be filtered by CloudEvent attributes using triggers, and sent as an HTTP POST request to an event sink.
OpenShift Serverless provides a default
Knative broker that can be created by using the Knative CLI.
You can also create the default
broker by adding the eventing.knative.dev/injection=enabled
label to a namespace if you are a cluster administrator, or by adding the eventing.knative.dev/injection: enabled
annotation to a trigger if you are a developer.
Although both developers and cluster administrators can add a broker by injection, only cluster administrators can permanently delete brokers that were created using this method. |
The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Container Platform cluster.
You have installed the kn
CLI.
Create the default
broker:
$ kn broker create default
Use the kn
command to list all existing brokers:
$ kn broker list
NAME URL AGE CONDITIONS READY REASON
default http://broker-ingress.knative-eventing.svc.cluster.local/test/default 45s 5 OK / 5 True
Optional: If you are using the OpenShift Container Platform web console, you can navigate to the Topology view in the Developer perspective, and observe that the broker exists:
You can create a broker by adding the eventing.knative.dev/injection: enabled
annotation to a Trigger
object.
If you create a broker by using the |
The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Container Platform cluster.
Create a Trigger
object as a .yaml
file that has the eventing.knative.dev/injection: enabled
annotation:
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
annotations:
eventing.knative.dev/injection: enabled
name: <trigger-name>
spec:
broker: default
subscriber: (1)
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: <service-name>
1 | Specify details about the event sink, or subscriber, that the trigger sends events to. |
Apply the .yaml
file:
$ oc apply -f <filename>
You can verify that the broker has been created successfully by using the oc
CLI, or by observing it in the Topology view in the web console.
Use the oc
command to get the broker:
$ oc -n <namespace> get broker default
NAME READY REASON URL AGE
default True http://broker-ingress.knative-eventing.svc.cluster.local/test/default 3m56s
Navigate to the Topology view in the web console, and observe that the broker exists:
If you have cluster administrator permissions, you can create the default
broker automatically by labeling a namespace.
Brokers created using this method will not be removed if you remove the label. You must manually delete them. |
The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Container Platform cluster.
You have cluster administrator permissions for OpenShift Container Platform.
Label a namespace with eventing.knative.dev/injection=enabled
:
$ oc label namespace <namespace> eventing.knative.dev/injection=enabled
You can verify that the broker has been created successfully by using the oc
CLI, or by observing it in the Topology view in the web console.
Use the oc
command to get the broker:
$ oc -n <namespace> get broker <broker_name>
$ oc -n default get broker default
NAME READY REASON URL AGE
default True http://broker-ingress.knative-eventing.svc.cluster.local/test/default 3m56s
Navigate to the Topology view in the web console, and observe that the broker exists: