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.2. 在 Java 中开发 Camel K 集成
本节介绍如何在 Java DSL 中开发简单的 Camel K 集成。编写 Java 中的集成以使用 Camel K 部署与在 Camel 中定义路由规则的方式相同。但是,在使用 Camel K 时,您不需要构建并打包集成为 JAR。
您可以直接在集成路由中使用任何 Camel 组件。Camel K 会自动处理依赖项管理,并使用代码检查从 Camel 目录中导入所有所需的库。
先决条件
流程
输入
kamel init
命令来生成简单的 Java 集成文件。例如:Copy to Clipboard Copied! Toggle word wrap Toggle overflow kamel init HelloCamelK.java
$ kamel init HelloCamelK.java
打开 IDE 中生成的集成文件,并根据需要编辑。例如,
HelloCamelK.java
集成自动包含 Camel计时器
和日志
组件,以帮助您开始:Copy to Clipboard Copied! Toggle word wrap Toggle overflow // camel-k: language=java import org.apache.camel.builder.RouteBuilder; public class HelloCamelK extends RouteBuilder { @Override public void configure() throws Exception { // Write your routes here, for example: from("timer:java?period=1s") .routeId("java") .setBody() .simple("Hello Camel K from ${routeId}") .to("log:info"); } }
// camel-k: language=java import org.apache.camel.builder.RouteBuilder; public class HelloCamelK extends RouteBuilder { @Override public void configure() throws Exception { // Write your routes here, for example: from("timer:java?period=1s") .routeId("java") .setBody() .simple("Hello Camel K from ${routeId}") .to("log:info"); } }
后续步骤