Menu Close

Chapter 4. Kamelets reference

4.1. Kamelet structure

A kamelet is typically coded in the YAML domain-specific language. The file name prefix is the name of the kamelet. For example, a kamelet with the name FTP sink has the filename ftp-sink.kamelet.yaml.

Note that in OpenShift, a kamelet is a resource that shows the name of the kamelet (not the filename).

At a high level, a kamelet resource describes:

  • A metadata section containing the ID of the kamelet and other information, such as the type of kamelet (source, sink, or action).
  • A definition (JSON-schema specification) that contains a set of parameters that you can use to configure the kamelet.
  • An optional types section containing information about input and output expected by the kamelet.
  • A Camel flow in YAML DSL that defines the implementation of the kamelet.

The following diagram shows an example of a kamelet and its parts.

Example kamelet structure

telegram-text-source.kamelet.yaml
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: telegram-source 1
  annotations: 2
    camel.apache.org/catalog.version: "master-SNAPSHOT"
    camel.apache.org/kamelet.icon: "data:image/..."
    camel.apache.org/provider: "Red Hat"
    camel.apache.org/kamelet.group: "Telegram"
  labels: 3
    camel.apache.org/kamelet.type: "source"
spec:
  definition: 4
    title: "Telegram Source"
    description: |-
        Receive all messages that people send to your telegram bot.
    required:
        - authorizationToken
    type: object
    properties:
        authorizationToken:
          title: Token
          description: The token to access your bot on Telegram, that you
                   can obtain from the Telegram "Bot Father".
          type: string
          format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
  types: 5
    out:
      mediaType: application/json
  dependencies:
  - "camel:jackson"
  - "camel:kamelet"
  - "camel:telegram"
  flow: 6
    from:
        uri: telegram:bots
        parameters:
            authorizationToken: "{{authorizationToken}}"
        steps:
        - marshal:
          json: {}
        - to: "kamelet:sink"
  1. The kamelet ID - Use this ID in Camel K integrations when you want to reference the kamelet.
  2. Annotations, such as icon, provide display features for the kamelet.
  3. Labels allow a user to query kamelets (for example, by kind: "source", "sink", or “action”)
  4. Description of the kamelet and parameters in JSON-schema specification format.
  5. The media type of the output (can include a schema).
  6. The route template that defines the behavior of the kamelet.

4.2. Example source kamelet

Here is the content of the example coffee-source kamelet:

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: coffee-source
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "Coffee Source"
    description: "Retrieve a random coffee from a catalog of coffees"
    properties:
      period:
        title: Period
        description: The interval between two events in seconds
        type: integer
        default: 1000
  types:
    out:
      mediaType: application/json
  flow:
    from:
      uri: timer:tick
      parameters:
        period: "{{period}}"
      steps:
      - to: "https://random-data-api.com/api/coffee/random_coffee"
      - to: "kamelet:sink"

4.3. Example sink kamelet

Here is the content of the example log-sink kamelet:

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: log-sink
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "Log Sink"
    description: "Consume events"
  flow:
    from:
      uri: "kamelet:source"
      steps:
      - convert-body-to: 'java.lang.String'
      - log: "${body}"