Chapter 31. Insert Field Action
Adds a custom field with a simple language parsed value to the message in transit.
The insert field action expects an application/json content type.
For example, if you have an object like { "foo":"John", "bar":30 }, and your action is configured with the field element and the value hello, the result is { "foo":"John", "bar":30, "element":"hello" }.
31.1. Configuration Options Copy linkLink copied to clipboard!
The following table summarizes the configuration options available for the insert-field-action Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
| field * | Field | The name of the field to be added. | string | ||
| value * | Value | The value of the field. | string |
* = Fields marked with an asterisk are mandatory.
31.2. Dependencies Copy linkLink copied to clipboard!
31.2.1. Quarkus dependencies Copy linkLink copied to clipboard!
<dependencies>
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-utils</artifactId>
<version>4.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kamelet</artifactId>
</dependency>
</dependencies>
31.3. Usage Copy linkLink copied to clipboard!
31.3.1. Camel JBang usage Copy linkLink copied to clipboard!
31.3.1.1. Prerequisites for JBang Copy linkLink copied to clipboard!
- Install JBang.
You have executed the following command:
jbang app install camel@apache/camel
31.3.1.2. Running a route with JBang Copy linkLink copied to clipboard!
Suppose you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:log-sink"
You can now run it directly through the following command.
camel run route.yaml
31.3.2. Knative Action Copy linkLink copied to clipboard!
You can use the insert-field-action Kamelet as an intermediate step in a Knative binding.
insert-field-action-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: insert-field-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: '{"foo":"John"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: insert-field-action
properties:
field: "The Field"
value: "The Value"
sink:
ref:
kind: Channel
apiVersion: messaging.knative.dev/v1
name: mychannel
31.3.3. Kafka Action Copy linkLink copied to clipboard!
You can use the insert-field-action Kamelet as an intermediate step in a Kafka binding.
insert-field-action-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: insert-field-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: '{"foo":"John"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: insert-field-action
properties:
field: "The Field"
value: "The Value"
sink:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic