Knative: Operator’s Handbook

Complex Delivery

In complex delivery, an Event Source fans out messages to multiple Services using Channel and Subscriptions:

Complex Delivery diagram

First, you need to decide the type of Channel to use and define it. For example, an InMemoryChannel:

apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
metadata:
  name: channel

Create the Channel:

$ kubectl apply -f channel.yaml
inmemorychannel.messaging.knative.dev/channel created

Next, point a Source to the Channel:

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: CronJobSource
metadata:
  name: source
spec:
  schedule: "* * * * *"
  data: '{"message": "Hello world from cron!"}'
  sink:
    apiVersion: messaging.knative.dev/v1alpha1
    kind: InMemoryChannel
    name: channel

Then, you can define a Subscription from the Channel to a Service:

apiVersion: messaging.knative.dev/v1alpha1
kind: Subscription
metadata:
  name: subscription1
spec:
  channel:
    apiVersion: messaging.knative.dev/v1alpha1
    kind: InMemoryChannel
    name: channel
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: service1

Create the Subscription:

$ kubectl apply -f subscription1.yaml
subscription.messaging.knative.dev/subscription1 created

You can create multiple Subscriptions from the same Channel as needed.