MT Channel Based Broker

Knative provides a Multi Tenant (MT) Broker implementation that uses channels for event routing.

Before you begin

Before you can use the MT Broker, you will need to have a channel provider installed, for example, InMemoryChannel (for development purposes), Kafka or Nats.

For more information on which channels are available and how to install them, see the list of available channels.

After you have installed the channel provider that will be used by MT Broker, you must create a ConfigMap which specifies how to configure the channels that the Broker creates for routing events.

NOTE: This guide assumes Knative Eventing is installed in the knative-eventing namespace. If you have installed Knative Eventing in a different namespace, replace knative-eventing with the name of that namespace.

Configure Channel ConfigMaps

You can define specifications for how each type of channel will be created, by modifying the ConfigMap for each channel type.

Example InMemoryChannel ConfigMap

When you install the eventing release, the following YAML file is created automatically:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. namespace: knative-eventing
  5. name: config-br-default-channel
  6. data:
  7. channelTemplateSpec: |
  8. apiVersion: messaging.knative.dev/v1
  9. kind: InMemoryChannel

To create a Broker that uses InMemoryChannel, you could create a Broker like this:

  1. kubectl create -f - <<EOF
  2. apiVersion: eventing.knative.dev/v1
  3. kind: Broker
  4. metadata:
  5. annotations:
  6. eventing.knative.dev/broker.class: MTChannelBasedBroker
  7. name: default
  8. namespace: default
  9. spec:
  10. config:
  11. apiVersion: v1
  12. kind: ConfigMap
  13. name: config-br-default-channel
  14. namespace: knative-eventing
  15. EOF

And the broker will use InMemoryChannel for routing events.

Example Kafka Channel ConfigMap

To use Kafka channels, you must create a YAML file that specifies how these channels will be created. NOTE: You must have Kafka Channel installed.

You can copy the following sample code into your Kafka channel ConfigMap:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: kafka-channel
  5. namespace: knative-eventing
  6. data:
  7. channelTemplateSpec: |
  8. apiVersion: messaging.knative.dev/v1alpha1
  9. kind: KafkaChannel
  10. spec:
  11. numPartitions: 3
  12. replicationFactor: 1

NOTE: This example specifies two extra parameters that are specific to Kafka Channels; numPartitions and replicationFactor.

To create a Broker that uses Kafka underneath, you would do it like this:

  1. kubectl create -f - <<EOF
  2. apiVersion: eventing.knative.dev/v1
  3. kind: Broker
  4. metadata:
  5. annotations:
  6. eventing.knative.dev/broker.class: MTChannelBasedBroker
  7. name: kafka-backed-broker
  8. namespace: default
  9. spec:
  10. config:
  11. apiVersion: v1
  12. kind: ConfigMap
  13. name: kafka-channel
  14. namespace: knative-eventing
  15. EOF