Introducing IDE support for Apache Camel K Modeline

Introducing IDE support for Apache Camel K Modeline

Apache Camel K is a lightweight integration framework built on Apache Camel that runs natively on Kubernetes. Camel K is designed explicitly for serverless and microservices architectures and allows you to run an integration written in Camel DSL on your cloud.

Since Apache Camel K 1.0.0, it has been possible to specify the configuration options for starting an integration route using Apache Camel K Modeline. Just place a single comment line, // camel-k:, at the top of your config file. Using this method allows you to specify a relatively complex integration project in a single file.

Until now, you could only access these configuration options through the command line. In this article, I introduce the new IDE support for Apache Camel K’s Modeline configuration.

IDE support for Camel K Modeline

Thanks to the Apache Camel Language Server, you can now use an extension to add Camel K Modeline support to Visual Studio Code (VS Code), Eclipse desktop IDEs, and Eclipse Che.

The most useful Modeline options are available as completions. As shown in Figure 1, you can use the hover feature to view the completions and documentation for these features in VS Code.

A screenshot of the completion for a Modeline option name.

Figure 1: Use the hover feature to view Modeline completions in your IDE.

Let’s take a look at the completions and definitions for three key options available with the Modeline configuration: trait, dependency, and property.

Everything you need to grow your career.

With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.

SIGN UP

Trait

The trait option proposes a completion for trait definition names and trait property names. Hovering over a trait name or property name displays its documentation. Figure 2 shows all of the trait completion options and a definition for one of them.

The completion options for a trait.

Figure 2: Trait completion options and a definition.

Figure 3 shows the completion options and a definition for a trait property.

The completions for a trait property name.

Figure 3: Trait property completion options.

Dependency

The dependency option suggests Camel artifact IDs and a template for other Maven-specified dependencies, as shown in Figure 4.

Dependency completions.

Figure 4: The completion options for Camel and Maven dependencies.

Property

The property option offers completions for Camel components and properties. You can use the hover feature to view the documentation for any selected element. Figure 5 shows the completion options for Camel components.

Completions for Camel components.

Figure 5: Hover over a component to view its definition.

Even an integration that requires specific configurations can be contained in one file.

Figure 6 shows the completion options for a Camel property.

Completions for a Camel component property.

Figure 6: Hover over a property to view its definition.

Overriding configuration options during development

Modeline’s configuration includes the production configuration, which is a useful feature. During development, you can use additional or different parameters. You can manually launch the integration from the command line with the additional parameters. Doing this avoids modifying the source code.

If you want to launch the same configuration multiple times or share a specific configuration in development with colleagues, you can use VS Code tasks for this purpose. To do this, create a file in your project named tasks.json and place it in a vscode folder. You should then be able to use completions to access VS Code tasks that are specific to Camel K.

Here’s an example:

{
  "version": "2.0.0",
  "tasks": [
    {
    "label": "Start in dev mode Camel K integration opened in active editor",
    "type": "camel-k",
    "dev": true,
    "file": "${file}",
    "problemMatcher": []
    }
  ]
}

If you enter the Camel K options that you need, completions provide the available options. When you call the “Start Apache Camel K integration” command, you can set the “use predefined task” option to launch your task with the configuration that you require.

Share