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.3.6. 使用 modeline 运行 Camel K 集成
您可以使用 Camel K modeline 在 Camel K 集成源文件中指定多个配置选项,这些文件在运行时执行。这样可以节省重新输入多个命令行选项的时间,并有助于防止输入错误。
以下示例显示了 Java 集成文件中的 modeline 条目,它启用了 3scale 并限制集成容器内存。
先决条件
- 设置 Camel K 开发环境
- 您必须已有一个使用 Java 或 YAML DSL 编写的 Camel 集成。
流程
在您的集成文件中添加 Camel K modeline 条目。例如:
ThreeScaleRest.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow // camel-k: trait=3scale.enabled=true trait=container.limit-memory=256Mi import org.apache.camel.builder.RouteBuilder; public class ThreeScaleRest extends RouteBuilder { @Override public void configure() throws Exception { rest().get("/") .route() .setBody().constant("Hello"); } }
// camel-k: trait=3scale.enabled=true trait=container.limit-memory=256Mi
1 import org.apache.camel.builder.RouteBuilder; public class ThreeScaleRest extends RouteBuilder { @Override public void configure() throws Exception { rest().get("/") .route() .setBody().constant("Hello"); } }
- 1
- 启用容器和 3scale 特征,通过 3scale 公开路由并限制容器内存。
运行集成,例如:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow kamel run ThreeScaleRest.java
kamel run ThreeScaleRest.java
kamel run
命令输出集成中指定的任何模式选项,例如:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Modeline options have been loaded from source files Full command: kamel run ThreeScaleRest.java --trait=3scale.enabled=true --trait=container.limit-memory=256Mi
Modeline options have been loaded from source files Full command: kamel run ThreeScaleRest.java --trait=3scale.enabled=true --trait=container.limit-memory=256Mi
其他资源
- Camel K 模式行选项
- 有关运行模式集成的开发工具的详情,请参阅 Apache Camel K Modeline 的 IDE 支持。