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 章 配置 Camel K 集成
Camel K 集成生命周期有两个配置阶段:
- 构建时间 - 当 Camel Quarkus 构建 Camel K 集成时,它会消耗 build-time 属性。
- Runtime - 当 Camel K 集成运行时,集成将使用本地文件、OpenShift ConfigMap 或 Secret 中的运行时属性或配置信息。
您可以在 kamel run
命令中使用以下选项来提供配置信息:
-
对于 build-time 配置,请使用
--build-property
选项,如 指定 build-time 配置属性中所述 -
对于运行时配置,请使用
--property
、--config
或--resource
选项,如 指定运行时配置选项中所述
例如,您可以使用 build-time 和 runtime 选项在 Camel K 中快速配置数据源,如链接: Connect Camel K with database sample configuration 所示。
4.1. 指定构建时配置属性
您可能需要为 Camel Quarkus 运行时提供属性值,以便它可以构建 Camel K 集成。有关构建期间生效的 Quarkus 配置的更多信息,请参阅 Quarkus 构建时间配置文档。您可以在命令行中直接指定 build-time 属性,或引用属性文件。如果两个位置上都定义了属性,则直接在命令行中指定的值优先于属性文件中的值。
先决条件
- 您必须有权访问安装了 Camel K Operator 和 OpenShift Serverless Operator 的 OpenShift 集群:
- 安装 Camel K
- 从 OperatorHub 安装 OpenShift Serverless
- 您知道您要应用到 Camel K 集成的 Camel Quarkus 配置选项。
流程
使用 Camel K
kamel run
命令指定--build-property
选项:kamel run --build-property <quarkus-property>=<property-value> <camel-k-integration>
例如,以下 Camel K 集成(名为
my-simple-timer.yaml
)使用quarkus.application.name
配置选项:- from: uri: "timer:tick" steps: - set-body: constant: "{{quarkus.application.name}}" - to: "log:info"
要覆盖默认应用程序名称,请在运行集成时为
quarkus.application.name
属性指定一个值。例如,将名称从
my-simple-timer
改为my-favorite-app
:kamel run --build-property quarkus.application.name=my-favorite-app my-simple-timer.yaml
要提供多个 build-time 属性,请在
kamel run
命令中添加额外的--build-property
选项:kamel run --build-property <quarkus-property1>=<property-value1> -build-property=<quarkus-property2>=<property-value12> <camel-k-integration>
另外,如果您需要指定多个属性,您可以创建一个属性文件,并使用
--build-property 文件
选项指定属性文件:kamel run --build-property file:<property-filename> <camel-k-integration>
例如,以下属性文件(名为
quarkus.properties
)定义两个 Quarkus 属性:quarkus.application.name = my-favorite-app quarkus.banner.enabled = true
quarkus.banner.enabled
属性指定在集成启动时显示 Quarkus 横幅。使用 Camel Kamel run 命令指定
quarkus.properties
文件:kamel run --build-property file:quarkus.properties my-simple-timer.yaml
Quarkus 解析属性文件,并使用属性值来配置 Camel K 集成。
其他资源
有关 Camel Quarkus 作为 Camel K 集成运行时的详情,请参考 Quarkus Trait。