This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.10.2. Event delivery workflows using channels
Events can be sent from a source to a sink by using channels and subscriptions for event delivery.
Channels are custom resources that define a single event-forwarding and persistence layer.
After events have been sent to a channel, these events can be sent to multiple Knative services, or other sinks, by using a subscription.
The default configuration for channel instances is defined in the default-ch-webhook config map. Developers can create their own channels directly by instantiating a supported Channel object.
10.2.1. Supported channel types 复制链接链接已复制到粘贴板!
Currently, OpenShift Serverless only supports InMemoryChannel kind channels for development use, as part of the Knative Eventing Technology Preview.
The following are limitations of InMemoryChannel channels:
- No event persistence is available. If a pod goes down, events on that pod are lost.
-
InMemoryChannelchannels do not implement event ordering, so two events that are received in the channel at the same time can be delivered to a subscriber in any order. -
If a subscriber rejects an event, there are no re-delivery attempts. Instead, the rejected event is sent to a
deadLetterSinkobject if this exists, or is dropped.
When you install Knative Eventing, the following default-ch-webhook config map is created automatically in the knative-eventing namespace:
This config map can specify either a cluster-wide default channel implementation, or a namespace-specific default channel implementation. Configuring a namespace-specific default overrides any cluster-wide settings.
After you create a Channel object, a mutating admission webhook adds a set of spec.channelTemplate properties for the Channel object based on the default channel implementation.
Example Channel object with spec.channelTemplate properties
The channel controller then creates the backing channel instance based on the spec.channelTemplate configuration.
The spec.channelTemplate properties cannot be changed after creation, because they are set by the default channel mechanism rather than by the user.
When this mechanism is used, two objects are created: a generic channel, and an InMemoryChannel channel.
The generic channel acts as a proxy that copies its subscriptions to the InMemoryChannel channel, and sets its status to reflect the status of the backing InMemoryChannel channel.
Because the channel in this example is created in the default namespace, the channel uses the cluster default, which is InMemoryChannel.
10.2.2. Creating a development channel 复制链接链接已复制到粘贴板!
Procedure
You can create a channel using the cluster default configuration by completing the following procedure.
Create a
Channelobject.Create a YAML file and copy the following sample code into it:
apiVersion: messaging.knative.dev/v1 kind: Channel metadata: name: example-channel namespace: default
apiVersion: messaging.knative.dev/v1 kind: Channel metadata: name: example-channel namespace: defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by entering:
oc apply -f <filename>
$ oc apply -f <filename>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.2.3. Creating a subscription 复制链接链接已复制到粘贴板!
You can create a Subscription object to connect a channel to a sink. In the following procedure, the example sink is a Knative service named error-handler.
Procedure
Create a YAML file and copy the following sample code into it:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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. ThedeadLetterSinkvalue 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>
$ oc apply -f <FILENAME>Copy to Clipboard Copied! Toggle word wrap Toggle overflow