Red Hat Camel K is deprecated
Red Hat Camel K is deprecated and the End of Life date for this product is June 30, 2025. For help migrating to the current go-to solution, Red Hat build of Apache Camel, see the Migration Guide.4.2.2. 提供配置值
您可以使用 kamel run
命令的 --config
选项,提供希望 Camel K 运算符处理并解析为运行时属性的配置值。您可以在本地文本(UTF-8)文件中、OpenShift ConfigMap 或 OpenShift secret 中提供配置值。
当您运行集成时,Camel K operator 会复制提供的文件并将其添加到类路径中,以便您可以引用集成代码中的配置值,而无需提供确切的位置。
4.2.2.1. 指定文本文件
如果您的 UTF-8 文本文件包含配置值,您可以使用 --config file:/path/to/file
选项使该文件在运行集成的类路径上可用(具有相同文件名)。
前提条件
- 设置 Camel K 开发环境
您有一个或多个(非二进制)文本文件,其中包含配置值。
例如,创建一个名为
resources-data.txt
的文件,该文件含有以下行文本:the file body
流程
创建一个 Camel K 集成来引用包含配置值的文本文件。
例如,以下集成(
ConfigFileRoute.java
)预期resources-data.txt
文件在运行时在 classpath 上可用:import org.apache.camel.builder.RouteBuilder; public class ConfigFileRoute extends RouteBuilder { @Override public void configure() throws Exception { from("timer:config-file") .setBody() .simple("resource:classpath:resources-data.txt") .log("resource file content is: ${body}"); } }
运行集成并使用
--config
选项指定文本文件,使其可用于正在运行的集成。例如:kamel run --config file:resources-data.txt ConfigFileRoute.java --dev
另外,您可以通过重复添加
--config
选项来提供多个文件,例如:kamel run --config file:resources-data1.txt --config file:resources-data2.txt ConfigFileRoute.java --dev