Events that have been sent to a channel from an event source or producer can be forwarded to one or more sinks by using subscriptions.
You can create subscriptions by configuring a Subscription
object, which specifies the channel and the sink (also known as a subscriber) that consumes the events sent to that channel.
After you have created a channel and an event sink, you can create a subscription to enable event delivery. Using the OpenShift Container Platform web console provides a streamlined and intuitive user interface to create a subscription.
The OpenShift Serverless Operator, Knative Serving, and Knative Eventing are installed on your OpenShift Container Platform cluster.
You have logged in to the web console.
You have created an event sink, such as a Knative service, and a channel.
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Container Platform.
In the Developer perspective, navigate to the Topology page.
Create a subscription using one of the following methods:
Hover over the channel that you want to create a subscription for, and drag the arrow. The Add Subscription option is displayed.
Select your sink in the Subscriber list.
Click Add.
If the service is available in the Topology view under the same namespace or project as the channel, click on the channel that you want to create a subscription for, and drag the arrow directly to a service to immediately create a subscription from the channel to that service.
After the subscription has been created, you can see it represented as a line that connects the channel to the service in the Topology view:
After you have created a channel and an event sink, you can create a subscription to enable event delivery. Creating Knative resources by using YAML files uses a declarative API, which enables you to describe subscriptions declaratively and in a reproducible manner. To create a subscription by using YAML, you must create a YAML file that defines a Subscription
object, then apply it by using the oc apply
command.
The OpenShift Serverless Operator and Knative Eventing are installed on the cluster.
Install the OpenShift CLI (oc
).
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Container Platform.
Create a Subscription
object:
Create a YAML file and copy the following sample code into it:
apiVersion: messaging.knative.dev/v1beta1
kind: Subscription
metadata:
name: my-subscription (1)
namespace: default
spec:
channel: (2)
apiVersion: messaging.knative.dev/v1beta1
kind: Channel
name: example-channel
delivery: (3)
deadLetterSink:
ref:
apiVersion: serving.knative.dev/v1
kind: service
name: error-handler
subscriber: (4)
ref:
apiVersion: serving.knative.dev/v1
kind: service
name: event-display
1 | Name of the subscription. |
2 | Configuration settings for the channel that the subscription connects to. |
3 | Configuration settings for event delivery. This tells the subscription what happens to events that cannot be delivered to the subscriber. When this is configured, events that failed to be consumed are sent to the deadLetterSink . The event is dropped, no re-delivery of the event is attempted, and an error is logged in the system. The deadLetterSink value must be a Destination. |
4 | Configuration settings for the subscriber. This is the event sink that events are delivered to from the channel. |
Apply the YAML file:
$ oc apply -f <filename>
After you have created a channel and an event sink, you can create a subscription to enable event delivery. Using the Knative (kn
) CLI to create subscriptions provides a more streamlined and intuitive user interface than modifying YAML files directly. You can use the kn subscription create
command with the appropriate flags to create a subscription.
The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Container Platform cluster.
You have installed the Knative (kn
) CLI.
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Container Platform.
Create a subscription to connect a sink to a channel:
$ kn subscription create <subscription_name> \
--channel <group:version:kind>:<channel_name> \ (1)
--sink <sink_prefix>:<sink_name> \ (2)
--sink-dead-letter <sink_prefix>:<sink_name> (3)
1 | --channel specifies the source for cloud events that should be processed. You must provide the channel name. If you are not using the default InMemoryChannel channel that is backed by the Channel custom resource, you must prefix the channel name with the <group:version:kind> for the specified channel type. For example, this will be messaging.knative.dev:v1beta1:KafkaChannel for an Apache Kafka backed channel. |
2 | --sink specifies the target destination to which the event should be delivered. By default, the <sink_name> is interpreted as a Knative service of this name, in the same namespace as the subscription. You can specify the type of the sink by using one of the following prefixes:
|
3 | Optional: --sink-dead-letter is an optional flag that can be used to specify a sink which events should be sent to in cases where events fail to be delivered. For more information, see the OpenShift Serverless Event delivery documentation.
Example command
Example output
|
To confirm that the channel is connected to the event sink, or subscriber, by a subscription, list the existing subscriptions and inspect the output:
$ kn subscription list
NAME CHANNEL SUBSCRIBER REPLY DEAD LETTER SINK READY REASON
mysubscription Channel:mychannel ksvc:event-display True
Delete a subscription:
$ kn subscription delete <subscription_name>
After you have created a channel and an event sink, also known as a subscriber, you can create a subscription to enable event delivery. Subscriptions are created by configuring a Subscription
object, which specifies the channel and the subscriber to deliver events to. You can also specify some subscriber-specific options, such as how to handle failures.
The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Container Platform cluster.
You have logged in to the web console and are in the Administrator perspective.
You have cluster administrator permissions on OpenShift Container Platform, or you have cluster or dedicated administrator permissions on Red Hat OpenShift service on AWS or OpenShift Dedicated.
You have created a Knative channel.
You have created a Knative service to use as a subscriber.
In the Administrator perspective of the OpenShift Container Platform web console, navigate to Serverless → Eventing.
In the Channel tab, select the Options menu for the channel that you want to add a subscription to.
Click Add Subscription in the list.
In the Add Subscription dialogue box, select a Subscriber for the subscription. The subscriber is the Knative service that receives events from the channel.
Click Add.
Configure event delivery parameters that are applied in cases where an event fails to be delivered to an event sink.