Este conteúdo não está disponível no idioma selecionado.
Chapter 3. Knative CLI plugins
The Knative (kn
) CLI supports the use of plugins, which enable you to extend the functionality of your kn
installation by adding custom commands and other shared commands that are not part of the core distribution. Knative (kn
) CLI plugins are used in the same way as the main kn
functionality.
Currently, Red Hat supports the kn-source-kafka
plugin and the kn-event
plugin.
3.1. Building events by using the kn-event plugin Copiar o linkLink copiado para a área de transferência!
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.
Prerequisites
-
You have installed the Knative (
kn
) CLI.
Procedure
Build an event:
kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format>
$ kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
-
The
--field
flag adds data to the event as a field-value pair. You can use it multiple times. -
The
--type
flag enables you to specify a string that designates the type of the event. -
The
--id
flag specifies the ID of the event. You can use the
json
oryaml
arguments with the--output
flag to change the output format of the event.All of these flags are optional.
Building a simple event
kn event build -o yaml
$ kn event build -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Resultant event in the YAML format
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Building a sample transaction event
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Resultant event in the JSON format
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
The
3.2. Sending events by using the kn-event plugin Copiar o linkLink copiado para a área de transferência!
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.
Prerequisites
-
You have installed the Knative (
kn
) CLI.
Procedure
Send an event:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
-
The
--field
flag adds data to the event as a field-value pair. You can use it multiple times. -
The
--type
flag enables you to specify a string that designates the type of the event. -
The
--id
flag specifies the ID of the event. -
The
--to
flag specifies the destination of the event. The
--namespace
flag specifies the namespace. If omitted, the namespace is taken from the current context.All of these flags are optional, except for the destination specification.
-
The
You can use the following destination formats for the --to
flag:
-
--to broker:<broker>
: Specifies a broker -
--to channel:<channel>
: Specifies a channel -
--to ksvc:<service>
or--to <service>
: Specifies a Knative service in the current namespace -
--to ksvc:<service>:<namespace>
: Specifies a Knative service in another namespace -
--to svc:<service>:<namespace>
: Specifies a Kubernetes service in another namespace -
--to special.eventing.dev/v1alpha1/channels:<channel>
: SpecifiesGroupVersionResource
ofv1alpha1
channel -
--to https://example.receiver.uri
: Specifies an HTTP URL
If you do not provide a prefix, the destination defaults to a Knative service in the current namespace.
Sending an event to a URL
Sending and event to an in-cluster resource