Chapter 4. Configuring Camel K integrations


This chapter explains available options for configuring Red Hat Integration - Camel K integrations using properties:

4.1. Configuring Camel K integrations using properties

You can configure properties for Camel K integrations on the command line at runtime. When you define a property in an integration using a property placeholder, for example, {{my.message}}, you can specify the property value on the command line, for example --property my.message=Hello. You can specify multiple properties in a single command.

Procedure

  1. Develop a Camel integration that uses a property. The following simple route includes a {{my.message}} property placeholder:

    ...
       from("timer:java?period=1s")
         .routeId("java")
         .setBody()
            .simple("{{my.message}} from ${routeId}")
         .to("log:info");
    ...
  2. Enter the kamel run command using the --property option to set the property value at runtime. For example:

    $ kamel run --property my.message="Hola Mundo" HelloCamelK.java --dev
    ...
    [1] 2020-04-13 15:39:59.213 INFO  [main] ApplicationRuntime - Listener org.apache.camel.k.listener.RoutesDumper@6e0dec4a executed in phase Started
    [1] 2020-04-13 15:40:00.237 INFO  [Camel (camel-k) thread #1 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hola Mundo from java]
    ...

4.2. Configuring Camel K integrations using property files

You can configure multiple properties for Camel K integrations by specifying a property file on the command line at runtime. When you define properties in an integration using property placeholders, for example, {{my.items}}, you can specify the property values on the command line using a properties file, for example --property-file my-integration.properties.

Procedure

  1. Define your integration properties file. The following shows a simple example from a routing.properties file:

    # List of items for random generation
    items=*radiator *engine *door window
    
    # Marker to identify priority items
    priority-marker=*
  2. Develop a Camel integration that uses properties defined in the properties file. The following example from the Routing.java integration uses the {{items}} and {{priority-marker}} property placeholders:

    ...
    from("timer:java?period=6000")
        .id("generator")
        .bean(this, "generateRandomItem({{items}})")
        .choice()
          .when().simple("${body.startsWith('{{priority-marker}}')}")
            .transform().body(String.class, item -> item.substring(priorityMarker.length()))
            .to("direct:priorityQueue")
          .otherwise()
            .to("direct:standardQueue");
    ...
  3. Enter the kamel run command with the --property-file option. For example:

    $ kamel run Routing.java --property-file routing.properties --dev
    ...
    [1] 2020-04-13 15:20:30.424 INFO  [main] ApplicationRuntime - Listener org.apache.camel.k.listener.RoutesDumper@6e0dec4a executed in phase Started
    [1] 2020-04-13 15:20:31.461 INFO  [Camel (camel-k) thread #1 - timer://java] priority - !!Priority item: engine
    [1] 2020-04-13 15:20:37.426 INFO  [Camel (camel-k) thread #1 - timer://java] standard - Standard item: window
    [1] 2020-04-13 15:20:43.429 INFO  [Camel (camel-k) thread #1 - timer://java] priority - !!Priority item: door
    ...

4.3. Configuring Camel K properties using an OpenShift ConfigMap

You can configure multiple properties for Camel K integrations using an OpenShift ConfigMap. When you define properties in an integration using property placeholders, for example, {{my.message}}, you can specify the property values at runtime using a ConfigMap. You can also specify additional properties such as logging levels in the application.properties section of the ConfigMap.

Procedure

  1. Develop a Camel integration that uses properties. The following simple route includes the {{my.message}} property placeholder:

    ...
       from("timer:java?period=1s")
         .routeId("java")
         .setBody()
            .simple("{{my.message}} from ${routeId}")
         .to("log:info");
    ...
  2. Define a ConfigMap that contains your configuration properties. For example:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: my-configmap
    data:
      application.properties: |
        my.message=Bonjour le monde
        logging.level.org.apache.camel=DEBUG

    This example sets the value of the my.message property and sets the logging level for the org.apache.camel package in the application.properties.

  3. Create the ConfigMap in the same OpenShift namespace as your integration:

    $ oc apply -f my-configmap.yaml
    configmap/my-configmap created
  4. Run the integration with the --configmap option to specify the configuration properties in the ConfigMap:

    $ kamel run --configmap=my-configmap HelloCamelK.java --dev
    ...
    [1] 2020-04-14 14:18:20.654 DEBUG [Camel (camel-k) thread #1 - timer://java] DefaultReactiveExecutor - Queuing reactive work: CamelInternalProcessor - UnitOfWork - afterProcess - DefaultErrorHandler[sendTo(log://info)] - ID-hello-camel-k-5df4bcd7dc-zq4vw-1586873876659-0-25
    [1] 2020-04-14 14:18:20.654 DEBUG [Camel (camel-k) thread #1 - timer://java] SendProcessor - >>>> log://info Exchange[ID-hello-camel-k-5df4bcd7dc-zq4vw-1586873876659-0-25]
    [1] 2020-04-14 14:18:20.655 INFO  [Camel (camel-k) thread #1 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Bonjour le monde from java]
    ...

4.4. Configuring Camel K properties using an OpenShift Secret

You can configure multiple properties for Camel K integrations using an OpenShift Secret. When you define properties in an integration using property placeholders, for example, {{my.message}}, you can specify the property values at runtime using a Secret. You can also specify additional properties such as logging levels in the application.properties section of the Secret.

Note

Configuring integration properties using a Secret is similar to configuring using a ConfigMap. The main difference is that you may need to base64-encode the content of the application.properties in the Secret.

Procedure

  1. Develop a Camel integration that uses properties. The following simple route includes the {{my.message}} property placeholder:

    ...
       from("timer:java?period=1s")
         .routeId("java")
         .setBody()
            .simple("{{my.message}} from ${routeId}")
         .to("log:info");
    ...
  2. Define a Secret that contains your configuration properties. For example:

    apiVersion: v1
    kind: Secret
    metadata:
      name: my-secret
    data:
      application.properties: |
        bXkubWVzc2FnZT1IZWxsbyBXb3JsZAogICAgbG9nZ2luZy5sZXZlbC5vcmcuYXBhY2hlLmNhbWVs
        PURFQlVHCg==

    This example sets the value of the my.message property to Hello World and sets the logging level for the org.apache.camel package to DEBUG. These settings are specified in base64-encoded format in the application.properties.

  3. Create the Secret in the same OpenShift namespace as your integration:

    $ oc apply -f my-secret.yaml
    secret/my-secret created
  4. Run the integration with the --secret option to specify the configuration properties in the Secret:

    $ kamel run --secret=my-secret HelloCamelK.java --dev
    [1] 2020-04-14 14:30:29.788 DEBUG [Camel (camel-k) thread #1 - timer://java] DefaultReactiveExecutor - Queuing reactive work: CamelInternalProcessor - UnitOfWork - afterProcess - DefaultErrorHandler[sendTo(log://info)] - ID-hello-camel-k-68f85d99b9-srd92-1586874486770-0-144
    [1] 2020-04-14 14:30:29.789 DEBUG [Camel (camel-k) thread #1 - timer://java] SendProcessor - >>>> log://info Exchange[ID-hello-camel-k-68f85d99b9-srd92-1586874486770-0-144]
    [1] 2020-04-14 14:30:29.789 INFO  [Camel (camel-k) thread #1 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello World from java]

4.5. Configuring Camel integration components

You can configure Camel components programmatically in your integration code or by using configuration properties on the command line at runtime. You can configure Camel components using the following syntax:

camel.component.${scheme}.${property}=${value}

For example, to change the queue size of the Camel seda component for staged event-driven architecture, you can configure the following property on the command line:

camel.component.seda.queueSize=10

Procedure

  • Enter the kamel run command and specify the Camel component configuration using the --property option. For example:

    $ kamel run --property camel.component.seda.queueSize=10 examples/Integration.java

4.6. Configuring Camel K integration dependencies

Camel K automatically resolves a wide range of dependencies that are required to run your integration code. However, you can explicitly add dependencies on the command line at runtime using the kamel run --dependency option.

The following example integration uses Camel K automatic dependency resolution:

...
  from("imap://admin@myserver.com")
    .to("seda:output")
...

Because this integration has an endpoint starting with the imap: prefix, Camel K can automatically add the camel-mail component to the list of required dependencies. The seda: endpoint belongs to camel-core, which is automatically added to all integrations, so Camel K does not add additional dependencies for this component.

Camel K automatic dependency resolution is transparent to the user at runtime. This is very useful in development mode because you can quickly add all the components that you need without exiting the development loop.

You can explicitly add a dependency using the kamel run --dependency or -d option. You might need to use this to specify dependencies that are not included in the Camel catalog. You can specify multiple dependencies on the command line.

Procedure

  • Enter the kamel run command and specify dependencies using the -d option. For example:

    $ kamel run -d mvn:com.google.guava:guava:26.0-jre -d camel-mina2 Integration.java
Note

You can disable automatic dependency resolution by disabling the dependencies trait: -trait dependencies.enabled=false. However, this is not recommended in most cases.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.