Skip to content

Commit 19e0392

Browse files
authored
Merge pull request #40880 from rh-max/srvls-kn-event
SRVCLI-325: Add docs on kn event
2 parents be01b72 + d2b4d2c commit 19e0392

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,3 +3352,5 @@ Topics:
33523352
File: serverless-listing-event-sources
33533353
- Name: kn func
33543354
File: kn-func-ref
3355+
- Name: kn event
3356+
File: kn-event-ref
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[id="serverless-build-events-kn_{context}"]
2+
= Building events
3+
4+
You can use the builder-like interface of the `kn event build` command to build an event. You can then send that event at a later time or use it in another context.
5+
6+
.Procedure
7+
8+
* Build an event:
9+
+
10+
[source,terminal]
11+
----
12+
$ kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format>
13+
----
14+
where:
15+
** The `--field` flag adds data to the event as a field-value pair. You can use it multiple times.
16+
** The `--type` flag enables you to specify a string that designates the type of the event.
17+
** The `--id` flag specifies the ID of the event.
18+
** You can use the `json` or `yaml` arguments with the `--output` flag to change the output format of the event.
19+
+
20+
All of these flags are optional.
21+
+
22+
.Building a simple event
23+
[source,terminal]
24+
----
25+
$ kn event build -o yaml
26+
----
27+
+
28+
.Resultant event in the YAML format
29+
[source,yaml]
30+
----
31+
data: {}
32+
datacontenttype: application/json
33+
id: 81a402a2-9c29-4c27-b8ed-246a253c9e58
34+
source: kn-event/v0.4.0
35+
specversion: "1.0"
36+
time: "2021-10-15T10:42:57.713226203Z"
37+
type: dev.knative.cli.plugin.event.generic
38+
----
39+
+
40+
.Building a sample transaction event
41+
[source,terminal]
42+
----
43+
$ kn event build \
44+
--field operation.type=local-wire-transfer \
45+
--field operation.amount=2345.40 \
46+
--field operation.from=87656231 \
47+
--field operation.to=2344121 \
48+
--field automated=true \
49+
--field signature='FGzCPLvYWdEgsdpb3qXkaVp7Da0=' \
50+
--type org.example.bank.bar \
51+
--id $(head -c 10 < /dev/urandom | base64 -w 0) \
52+
--output json
53+
----
54+
+
55+
.Resultant event in the JSON format
56+
[source,json]
57+
----
58+
{
59+
"specversion": "1.0",
60+
"id": "RjtL8UH66X+UJg==",
61+
"source": "kn-event/v0.4.0",
62+
"type": "org.example.bank.bar",
63+
"datacontenttype": "application/json",
64+
"time": "2021-10-15T10:43:23.113187943Z",
65+
"data": {
66+
"automated": true,
67+
"operation": {
68+
"amount": "2345.40",
69+
"from": 87656231,
70+
"to": 2344121,
71+
"type": "local-wire-transfer"
72+
},
73+
"signature": "FGzCPLvYWdEgsdpb3qXkaVp7Da0="
74+
}
75+
}
76+
----
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[id="serverless-send-events-kn_{context}"]
2+
= Sending events
3+
4+
You can use the `kn event send` command to send an event. The events can be sent either to publicly available addresses or to addressable resources inside a cluster, such as Kubernetes services, as well as Knative services, brokers, and channels. The command uses the same builder-like interface as the `kn event build` command.
5+
6+
.Procedure
7+
8+
* Send an event:
9+
+
10+
[source,terminal]
11+
----
12+
$ kn event send --field <field-name>=<value> --type <type-name> --id <id> --to-url <url> --to <cluster-resource> --namespace <namespace>
13+
----
14+
where:
15+
** The `--field` flag adds data to the event as a field-value pair. You can use it multiple times.
16+
** The `--type` flag enables you to specify a string that designates the type of the event.
17+
** The `--id` flag specifies the ID of the event.
18+
** If you are sending the event to a publicly accessible destination, specify the URL using the `--to-url` flag.
19+
** If you are sending the event to an in-cluster Kubernetes resource, specify the destination using the `--to` flag.
20+
*** Specify the Kubernetes resource using the `<Kind>:<ApiVersion>:<name>` format.
21+
** The `--namespace` flag specifies the namespace. If omitted, the namespace is taken from the current context.
22+
+
23+
All of these flags are optional, except for the destination specification, for which you need to use either `--to-url` or `--to`.
24+
+
25+
The following example shows sending an event to a URL:
26+
+
27+
.Example command
28+
[source,terminal]
29+
----
30+
$ kn event send \
31+
--field player.id=6354aa60-ddb1-452e-8c13-24893667de20 \
32+
--field player.game=2345 \
33+
--field points=456 \
34+
--type org.example.gaming.foo \
35+
--to-url http://ce-api.foo.example.com/
36+
----
37+
+
38+
The following example shows sending an event to an in-cluster resource:
39+
+
40+
.Example command
41+
[source,terminal]
42+
----
43+
$ kn event send \
44+
--type org.example.kn.ping \
45+
--id $(uuidgen) \
46+
--field event.type=test \
47+
--field event.data=98765 \
48+
--to Service:serving.knative.dev/v1:event-display
49+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include::modules/serverless-document-attributes.adoc[]
2+
[id="kn-event-ref"]
3+
= kn event
4+
:context: kn-event-ref
5+
include::modules/common-attributes.adoc[]
6+
7+
toc::[]
8+
9+
:FeatureName: The `kn event` plug-in
10+
include::modules/technology-preview.adoc[leveloffset=+2]
11+
12+
You can use the `kn event` set of commands to manage cloud events from the command line.
13+
14+
include::modules/serverless-build-events-kn.adoc[leveloffset=+1]
15+
include::modules/serverless-send-events-kn.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)