@@ -15,27 +15,63 @@ a Broker, all metadata other than the CloudEvent is stripped away (e.g. unless
1515set as a CloudEvent attribute, there is no concept of how this event entered the
1616Broker).
1717
18+ There can be different classes of Brokers providing different kinds
19+ of semantics around durability of events, performance, etc. The Broker that is
20+ part of the Knative Eventing repo is used for these examples, it uses Knative
21+ [ Channels] ( ./channels/ ) for delivering events. You can read more details about
22+ [ Channel Based Broker] ( ./channel-based-broker.md ) . Simple example showing a ` Broker `
23+ where the configuration is specified in a ` ConfigMap ` config-br-default-channel,
24+ which uses ` InMemoryChannel ` :
25+
1826Example:
1927
2028``` yaml
21- apiVersion : eventing.knative.dev/v1alpha1
29+ apiVersion : eventing.knative.dev/v1beta1
30+ kind : Broker
31+ metadata :
32+ name : default
33+ spec :
34+ # Configuration specific to this broker.
35+ config :
36+ apiVersion : v1
37+ kind : ConfigMap
38+ name : config-br-default-channel
39+ namespace : knative-eventing
40+ ` ` `
41+
42+ More complex example, showing the same ` Broker` as above
43+ but with failed events being delivered to Knative Service called `dlq-service`
44+
45+ ` ` ` yaml
46+ apiVersion: eventing.knative.dev/v1beta1
2247kind: Broker
2348metadata:
2449 name: default
2550spec:
26- channelTemplateSpec :
27- apiVersion : messaging.knative.dev/v1alpha1
28- kind : InMemoryChannel
51+ # Configuration specific to this broker.
52+ config:
53+ apiVersion: v1
54+ kind: ConfigMap
55+ name: config-br-default-channel
56+ namespace: knative-eventing
57+ # Where to deliver Events that failed to be processed.
58+ delivery:
59+ deadLetterSink:
60+ ref:
61+ apiVersion: serving.knative.dev/v1
62+ kind: Service
63+ name: dlq-service
2964` ` `
3065
3166# # Trigger
3267
3368A Trigger represents a desire to subscribe to events from a specific Broker.
3469
35- Example:
70+ Simple example which will receive all the events from the given (`default`) broker and
71+ deliver them to Knative Serving service `my-service` :
3672
3773` ` ` yaml
38- apiVersion : eventing.knative.dev/v1alpha1
74+ apiVersion: eventing.knative.dev/v1beta1
3975kind: Trigger
4076metadata:
4177 name: my-service-trigger
@@ -57,7 +93,7 @@ Note that we only support exact matching on string values.
5793Example :
5894
5995` ` ` yaml
60- apiVersion : eventing.knative.dev/v1alpha1
96+ apiVersion: eventing.knative.dev/v1beta1
6197kind: Trigger
6298metadata:
6399 name: my-service-trigger
@@ -77,146 +113,17 @@ spec:
77113The example above filters events from the `default` Broker that are of type `dev.knative.foo.bar` AND
78114have the extension `myextension` with the value `my-extension-value`.
79115
80- # # Usage
81-
82- # ## Channel
83-
84- ` Broker` s use their `spec.channelTemplateSpec` to create their internal
85- [Channels](./channels/), which dictate the durability guarantees of events sent
86- to that `Broker`. If `spec.channelTemplateSpec` is not specified, then the
87- [default channel](./channels/default-channels.md) for their namespace is used.
88-
89- # ### Setup
90-
91- Have a `Channel` CRD installed and set as the default channel for the namespace
92- you are interested in. For development, the
93- [InMemoryChannel](https://github.com/knative/eventing/tree/{{< branch >}}/config/channels/in-memory-channel)
94- is normally used.
95-
96- # ### Changing
97-
98- **Note** changing the `Channel` of a running `Broker` will lose all in-flight
99- events.
100-
101- If you want to change which `Channel` is used by a given `Broker`, then
102- determine if the `spec.channelTemplateSpec` is specified or not.
103-
104- If `spec.channelTemplateSpec` is specified :
105-
106- 1. Delete the `Broker`.
107- 1. Create the `Broker` with the updated `spec.channelTemplateSpec`.
108-
109- If `spec.channelTemplateSpec` is not specified :
110-
111- 1. Change the
112- [default channel](./channels/default-channels.md#setting-the-default-channel-configuration)
113- for the namespace that `Broker` is in.
114- 1. Delete and recreate the `Broker`.
115-
116- # ## Broker
117-
118- There are two ways to create a Broker :
119-
120- - [namespace annotation](#annotation)
121- - [manual setup](#manual-setup)
122-
123- Normally the [namespace annotation](#annotation) is used to do this setup.
124-
125- # ### Annotation
126-
127- The easiest way to get started, is to annotate your namespace (replace `default`
128- with the desired namespace) :
129-
130- ` ` ` shell
131- kubectl label namespace default knative-eventing-injection=enabled
132- ` ` `
133-
134- This should automatically create a `Broker` named `default` in the `default`
135- namespace.
136-
137- ` ` ` shell
138- kubectl -n default get broker default
139- ` ` `
140-
141- _NOTE_ `Broker`s created due to annotation will not be removed if you remove the
142- annotation. For example, if you annotate the namespace, which will then create
143- the `Broker` as described above. If you now remove the annotation, the `Broker`
144- will not be removed, you have to manually delete it.
145-
146- For example, to delete the injected Broker from the foo namespace :
147-
148- ` ` ` shell
149- kubectl -n foo delete broker default
150- ` ` `
151-
152- # ### Manual Setup
153-
154- In order to setup a `Broker` manually, we must first create the required
155- ` ServiceAccount` s and give them the proper RBAC permissions. This setup is
156- required once per namespace. These instructions will use the `default`
157- namespace, but you can replace it with any namespace you want to install a
158- ` Broker` into.
159-
160- Create the `ServiceAccount` objects.
161-
162- ` ` ` shell
163- kubectl -n default create serviceaccount eventing-broker-ingress
164- kubectl -n default create serviceaccount eventing-broker-filter
165- ` ` `
166-
167- Then give them the needed RBAC permissions :
168-
169- ` ` ` shell
170- kubectl -n default create rolebinding eventing-broker-ingress \
171- --clusterrole=eventing-broker-ingress \
172- --serviceaccount=default:eventing-broker-ingress
173- kubectl -n default create rolebinding eventing-broker-filter \
174- --clusterrole=eventing-broker-filter \
175- --serviceaccount=default:eventing-broker-filter
176- ` ` `
116+ # # Complete end-to-end example
177117
178- Note that these commands each use three different objects, all named
179- ` eventing-broker-ingress` or `eventing-broker-filter`. The `ClusterRole` is
180- installed with Knative Eventing
181- [here](https://github.com/knative/eventing/blob/master/config/200-broker-clusterrole.yaml).
182- The `ServiceAccount` was created two commands prior. The `RoleBinding` is
183- created with this command.
184-
185- Create RBAC permissions granting access to shared configmaps for logging,
186- tracing, and metrics configuration.
187-
188- _These commands assume the shared Knative Eventing components are installed in
189- the `knative-eventing` namespace. If you installed the shared Knative Eventing
190- components in a different namespace, replace `knative-eventing` with the name of
191- that namespace._
192-
193- ` ` ` shell
194- kubectl -n knative-eventing create rolebinding eventing-config-reader-default-eventing-broker-ingress \
195- --clusterrole=eventing-config-reader \
196- --serviceaccount=default:eventing-broker-ingress
197- kubectl -n knative-eventing create rolebinding eventing-config-reader-default-eventing-broker-filter \
198- --clusterrole=eventing-config-reader \
199- --serviceaccount=default:eventing-broker-filter
200- ` ` `
201-
202- Now we can create the `Broker`. Note that this example uses the name `default`,
203- but could be replaced by any other valid name.
118+ # ## Broker setup
204119
205- ` ` ` shell
206- cat << EOF | kubectl apply -f -
207- apiVersion: eventing.knative.dev/v1alpha1
208- kind: Broker
209- metadata:
210- namespace: default
211- name: default
212- EOF
213- ` ` `
120+ We assume that you have installed a Broker in namespace `default`. If you haven't done that
121+ yet, [install it from here](./channel-based-broker.md).
214122
215123# ## Subscriber
216124
217- Now create a function to receive those events. This document will assume the
218- following manifest describing a Knative Service is created, but it could be
219- anything that is `Addressable`.
125+ Create a function to receive events. This document uses a Knative Service, but
126+ it could be anything that is [Callable](https://github.com/knative/eventing/blob/master/docs/spec/interfaces.md).
220127
221128` ` ` yaml
222129apiVersion: serving.knative.dev/v1
@@ -229,25 +136,26 @@ spec:
229136 spec:
230137 containers:
231138 - # This corresponds to
232- # https://github.com/knative/eventing-contrib/blob/v0.2.1 /cmd/message_dumper/dumper.go.
233- image: gcr.io/knative-releases/github.com/knative/ eventing-sources /cmd/message_dumper @sha256:ab5391755f11a5821e7263686564b3c3cd5348522f5b31509963afb269ddcd63
139+ # https://github.com/knative/eventing-contrib/tree/master /cmd/event_display
140+ - image: gcr.io/knative-releases/knative.dev/ eventing-contrib /cmd/event_display @sha256:a214514d6ba674d7393ec8448dd272472b2956207acb3f83152d3071f0ab1911
234141` ` `
235142
236143# ## Trigger
237144
238- Create a `Trigger` using the following manifest that sends only events of a
239- particular type to `my-service` :
145+ Create a `Trigger` that sends only events of a particular type to the subscriber
146+ created above (`my-service`). For this example, we use Ping Source, and it
147+ emits events types `dev.knative.sources.ping`.
240148
241149` ` ` yaml
242- apiVersion: eventing.knative.dev/v1alpha1
150+ apiVersion: eventing.knative.dev/v1beta1
243151kind: Trigger
244152metadata:
245153 name: my-service-trigger
246154 namespace: default
247155spec:
248156 filter:
249157 attributes:
250- type: dev.knative.foo.bar
158+ type: dev.knative.sources.ping
251159 subscriber:
252160 ref:
253161 apiVersion: serving.knative.dev/v1
@@ -263,7 +171,7 @@ unspecified.
263171The Webhook will default the YAML above to :
264172
265173` ` ` yaml
266- apiVersion: eventing.knative.dev/v1alpha1
174+ apiVersion: eventing.knative.dev/v1beta1
267175kind: Trigger
268176metadata:
269177 name: my-service-trigger
@@ -272,7 +180,7 @@ spec:
272180 broker: default # Defaulted by the Webhook.
273181 filter:
274182 attributes:
275- type: dev.knative.foo.bar
183+ type: dev.knative.sources.ping
276184 subscriber:
277185 ref:
278186 apiVersion: serving.knative.dev/v1
@@ -283,62 +191,24 @@ spec:
283191You can make multiple `Trigger`s on the same `Broker` corresponding to different
284192types, sources (or any other CloudEvents attribute), and subscribers.
285193
286- # ## Source
287-
288- Now have something emit an event of the correct type (`dev.knative.foo.bar`)
289- into the `Broker`. We can either do this manually or with a normal Knative
290- Source.
291-
292- # ### Manual
293-
294- The `Broker`'s address is well known, it will always be
295- ` <name>-broker.<namespace>.svc.<ending>` . In our case, it is
296- ` default-broker.default.svc.cluster.local` .
194+ # ## Emitting Events using Ping Source
297195
298- While SSHed into a `Pod` and run :
299-
300- ` ` ` shell
301- curl -v "http://default-broker.default.svc.cluster.local/" \
302- -X POST \
303- -H "X-B3-Flags: 1" \
304- -H "CE-SpecVersion: 0.2" \
305- -H "CE-Type: dev.knative.foo.bar" \
306- -H "CE-Time: 2018-04-05T03:56:24Z" \
307- -H "CE-ID: 45a8b444-3213-4758-be3f-540bf93f85ff" \
308- -H "CE-Source: dev.knative.example" \
309- -H 'Content-Type: application/json' \
310- -d '{ "much": "wow" }'
311- ` ` `
312-
313- # ### Knative Source
314-
315- Provide the Knative Source the `default` `Broker` as its sink (note you'll need
316- to use ko apply -f <source_file>.yaml to create it) :
196+ Knative Eventing comes with a [Ping Source](./samples/ping-source/README.md) which
197+ emits an event on a configured schedule. For this we'll configure it to emit
198+ events once a minute, saying, yes, you guessed it `Hello World!`.
317199
318200` ` ` yaml
319- apiVersion: sources.eventing. knative.dev/v1alpha1
320- kind: ContainerSource
201+ apiVersion: sources.knative.dev/v1alpha1
202+ kind: PingSource
321203metadata:
322- name: heartbeats-sender
204+ name: test-ping-source
323205spec:
324- template:
325- spec:
326- containers:
327- - image: github.com/knative/eventing-contrib/cmd/heartbeats/
328- name: heartbeats-sender
329- args:
330- - --eventType=dev.knative.foo.bar
331- env:
332- - name: POD_NAME
333- valueFrom:
334- fieldRef:
335- fieldPath: metadata.name
336- - name: POD_NAMESPACE
337- valueFrom:
338- fieldRef:
339- fieldPath: metadata.namespace
206+ schedule: "*/1 * * * *"
207+ data: '{"message": "Hello world!"}'
340208 sink:
341- apiVersion: eventing.knative.dev/v1alpha1
342- kind: Broker
343- name: default
209+ ref:
210+ # Deliver events to Broker.
211+ apiVersion: eventing.knative.dev/v1alpha1
212+ kind: Broker
213+ name: default
344214` ` `
0 commit comments