extract field action Extract Field Action

Provided by: "Apache Software Foundation"

Support Level for this Kamelet is: "Stable"

Extract a field from the message body.

The extract field action expects an application/json content type.

The field parameter allows you to specify which field of the json the user wants to extract. By default the message body will be overriden with the extracted field.

The optional parameter headerOutput allows the user to specify wheter the extracted field should be stored in a message header named 'CamelKameletsExtractFieldName', leaving the message body untouched.

The optional parameter headerOutputName allows the user to specify a custom header name instead of the default 'CamelKameletsExtractFieldName'. This parameter must be used in conjunction with headerOutput. If no headerOutputName parameter will be provided, the default 'CamelKameletsExtractFieldName' will be used.

The optional parameter strictHeaderCheck allows to user to enable a strict header name check. If enabled the action will check if the header output name (custom or default) has been used already in the exchange. If so, the extracted field will be stored in the message body, if not, the extracted field will be stored in the selected header (custom or default).

The headerOutput/headerOutputName/strictHeaderCheck parameters are particulary useful in case you would like to reuse an extracted field as parameter for another header, for example.

Configuration Options

The following table summarizes the configuration options available for the extract-field-action Kamelet:

Property Name Description Type Default Example

field

Field

Required The name of the field to extract.

string

headerOutput

Header Output

If enable the action will store the extracted field in an header named CamelKameletsExtractFieldName.

boolean

false

headerOutputName

Header Output Name

A custom name for the header containing the extracted field.

string

none

strictHeaderCheck

Strict Header Check

If enabled the action will check if the header output name (custom or default) has been used already in the exchange. If so, the extracted field will be stored in the message body, if not, the extracted field will be stored in the selected header (custom or default).

boolean

false

trimField

Trim Field

If enabled we return the Raw extracted field.

boolean

false

Dependencies

At runtime, the extract-field-action Kamelet relies upon the presence of the following dependencies:

  • mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.4.2-SNAPSHOT

  • camel:kamelet

  • camel:core

  • camel:jackson

Camel JBang usage

Prerequisites

  • You’ve installed JBang.

  • You have executed the following command:

jbang app install camel@apache/camel

Supposing 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

Camel K Environment Usage

This section describes how you can use the extract-field-action.

Knative action

You can use the extract-field-action Kamelet as an intermediate step in a Knative binding.

extract-field-action-pipe.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: extract-field-action-pipe
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: kafka-source
      properties:
        bootstrapServers: localhost:9092
        topic: mytopic
        user: kafka
        password: kafka123!
  steps:
    - ref:
        kind: Kamelet
        apiVersion: camel.apache.org/v1
        name: extract-field-action
      properties:
        field: The Field
  sink:
    ref:
      kind: Channel
      apiVersion: messaging.knative.dev/v1
      name: mychannel

Prerequisite

You have Camel K installed on the cluster.

Procedure for using the cluster CLI

  1. Save the extract-field-action-pipe.yaml file to your local drive, and then edit it as needed for your configuration.

  2. Run the action by using the following command:

    kubectl apply -f extract-field-action-pipe.yaml

Procedure for using the Kamel CLI

Configure and run the action by using the following command:

kamel bind channel:mychannel -p "step-0.field=The Field" extract-field-action

This command creates the Kamelet Pipe in the current namespace on the cluster.

Kafka action

You can use the extract-field-action Kamelet as an intermediate step in a Kafka binding.

extract-field-action-pipe.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: extract-field-action-pipe
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: kafka-source
      properties:
        bootstrapServers: localhost:9092
        topic: mytopic
        user: kafka
        password: kafka123!
  steps:
    - ref:
        kind: Kamelet
        apiVersion: camel.apache.org/v1
        name: extract-field-action
      properties:
        field: The Field
  sink:
    ref:
      kind: KafkaTopic
      apiVersion: kafka.strimzi.io/v1beta1
      name: my-topic

Prerequisites

  • You’ve installed Strimzi.

  • You’ve created a topic named my-topic in the current namespace.

  • You have Camel K installed on the cluster.

Procedure for using the cluster CLI

  1. Save the extract-field-action-pipe.yaml file to your local drive, and then edit it as needed for your configuration.

  2. Run the action by using the following command:

    kubectl apply -f extract-field-action-pipe.yaml

Procedure for using the Kamel CLI

Configure and run the action by using the following command:

kamel bind kafka.strimzi.io/v1beta1:KafkaTopic:my-topic -p "step-0.field=The Field" extract-field-action

This command creates the Kamelet Pipe in the current namespace on the cluster.