×

Events can be sent from a source to a sink by using channels and subscriptions for event delivery.

Channel workflow overview

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.

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.

  • InMemoryChannel channels 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 deadLetterSink object if this exists, or is dropped.

Using the default development channel configuration

When you install Knative Eventing, the following default-ch-webhook config map is created automatically in the knative-eventing namespace:

apiVersion: v1
kind: ConfigMap
metadata:
  name: default-ch-webhook
  namespace: knative-eventing
data:
  default-ch-config: |
    clusterDefault:
      apiVersion: messaging.knative.dev/v1
      kind: InMemoryChannel
    namespaceDefaults:
      some-namespace:
        apiVersion: messaging.knative.dev/v1
        kind: InMemoryChannel

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
apiVersion: messaging.knative.dev/v1
kind: Channel
metadata:
  name: example-channel
  namespace: default
spec:
  channelTemplate:
    apiVersion: messaging.knative.dev/v1
    kind: InMemoryChannel

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.

Creating a development channel

Procedure

You can create a channel using the cluster default configuration by completing the following procedure.

  1. Create a Channel object.

    1. 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
    2. Apply the YAML file by entering:

      $ oc apply -f <filename>

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
  1. 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.
  2. Apply the YAML file:

    $ oc apply -f <FILENAME>