mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
92 lines
4.3 KiB
Plaintext
92 lines
4.3 KiB
Plaintext
[id="serverless-kn-func-emit-reference_{context}"]
|
|
= kn func emit optional parameters
|
|
|
|
You can specify optional parameters for the emitted CloudEvent by using the `kn func emit` CLI command flags.
|
|
|
|
.List of flags from --help command output
|
|
[source,terminal]
|
|
----
|
|
Flags:
|
|
-c, --content-type string The MIME Content-Type for the CloudEvent data (Env: $FUNC_CONTENT_TYPE) (default "application/json")
|
|
-d, --data string Any arbitrary string to be sent as the CloudEvent data. Ignored if --file is provided (Env: $FUNC_DATA)
|
|
-f, --file string Path to a local file containing CloudEvent data to be sent (Env: $FUNC_FILE)
|
|
-h, --help help for emit
|
|
-i, --id string CloudEvent ID (Env: $FUNC_ID) (default "306bd6a0-0b0a-48ba-b187-b633571d072a")
|
|
-p, --path string Path to the project directory. Ignored when --sink is provided (Env: $FUNC_PATH) (default "/home/lanceball/src/github.com/nodeshift/opossum")
|
|
-k, --sink string Send the CloudEvent to the function running at [sink]. The special value "local" can be used to send the event to a function running on the local host. When provided, the --path flag is ignored (Env: $FUNC_SINK)
|
|
-s, --source string CloudEvent source (Env: $FUNC_SOURCE) (default "/boson/fn")
|
|
-t, --type string CloudEvent type (Env: $FUNC_TYPE) (default "boson.fn")
|
|
----
|
|
|
|
In particular, you might find it useful to specify the following parameters:
|
|
|
|
Event type:: The type of event being emitted. You can find information about the `type` parameter that is set for events from a certain event producer in the documentation for that event producer. For example, the API server source may set the `type` parameter of produced events as `dev.knative.apiserver.resource.update`.
|
|
Event source:: The unique event source that produced the event. This may be a URI for the event source, for example `https://10.96.0.1/`, or the name of the event source.
|
|
Event ID:: A random, unique ID that is created by the event producer.
|
|
Event data:: Allows you to specify a `data` value for the event sent by the `kn func emit` command. For example, you can specify a `--data` value such as `"Hello world!"` so that the event contains this data string. By default, no data is included in the events created by `kn func emit`.
|
|
+
|
|
[NOTE]
|
|
====
|
|
Functions that have been deployed to a cluster can respond to events from an existing event source that provides values for properties such as `source` and `type`. These events often have a `data` value in JSON form, which captures the domain specific context of the event. Using the CLI flags noted in this document, developers can simulate those events for local testing.
|
|
====
|
|
+
|
|
You can also send event data using the `--file` flag to provide a local file containing data for the event.
|
|
Data content type:: If you are using the `--data` flag to add data for events, you can also specify what type of data is carried by the event, by using the `--content-type` flag. In the previous example, the data is plain text, so you might specify `kn func emit --data "Hello world!" --content-type "text/plain"`.
|
|
|
|
.Example commands specifying event parameters by using flags
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --type <event_type> --source <event_source> --data <event_data> --content-type <content_type> -i <event_ID>
|
|
----
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --type ping --source example-ping --data "Hello world!" --content-type "text/plain" -i example-ID
|
|
----
|
|
|
|
.Example commands specifying a file on disk that contains the event parameters
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --file <path>
|
|
----
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --file ./test.json
|
|
----
|
|
|
|
.Example commands specifying a path to the function
|
|
|
|
You can specify a path to the function project by using the `--path` flag, or specify an endpoint for the function by using the `--sink` flag:
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --path <path_to_function>
|
|
----
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --path ./example/example-function
|
|
----
|
|
|
|
.Example commands specifying a function deployed as a Knative service (sink)
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --sink <service_URL>
|
|
----
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --sink "http://example.function.com"
|
|
----
|
|
|
|
The `--sink` flag also accepts the special value `local` to send an event to a function running locally:
|
|
|
|
[source,terminal]
|
|
----
|
|
$ kn func emit --sink local
|
|
----
|