第2章 Camel ルートの Fuse 7 から Camel への移行
Java DSL、XML IO DSL、または YAML を使用して、Red Hat build of Apache Camel for Quarkus アプリケーションで Camel ルートを定義できます。
2.1. Java DSL ルート移行の例
既存のルート定義を Red Hat build of Apache Camel for Quarkus アプリケーションに直接コピーし、必要な依存関係を Red Hat build of Apache Camel for Quarkus pom.xml ファイルに追加することで、Java DSL ルート定義を Fuse アプリケーションから CEQ に移行できます。
この例では、Java DSL ルートを CEQ アプリケーションの Routes.java
という名前のファイルにコピーして、コンテンツベースのルート定義を Fuse 7 アプリケーションから新しい CEQ アプリケーションに移行します。
手順
Web サイト
code.quarkus.redhat.com
を使用して、この例に必要なエクステンションを選択します。- camel-quarkus-file
- camel-quarkus-xpath
直前の手順で生成されたプロジェクトファイルの展開先ディレクトリーに移動します。
cd <directory_name>
$ cd <directory_name>
Copy to Clipboard Copied! -
src/main/java/org/acme/
サブフォルダーにRoutes.java
という名前のファイルを作成します。 次の例のように、Fuse アプリケーションから
Routes.java
にルート定義を追加します。package org.acme; import org.apache.camel.builder.RouteBuilder; public class Routes extends RouteBuilder { // Add your Java DSL route definition here public void configure() { from("file:work/cbr/input") .log("Receiving order ${file:name}") .choice() .when().xpath("//order/customer/country[text() = 'UK']") .log("Sending order ${file:name} to the UK") .to("file:work/cbr/output/uk") .when().xpath("//order/customer/country[text() = 'US']") .log("Sending order ${file:name} to the US") .to("file:work/cbr/output/uk") .otherwise() .log("Sending order ${file:name} to another country") .to("file:work/cbr/output/others"); } }
package org.acme; import org.apache.camel.builder.RouteBuilder; public class Routes extends RouteBuilder { // Add your Java DSL route definition here public void configure() { from("file:work/cbr/input") .log("Receiving order ${file:name}") .choice() .when().xpath("//order/customer/country[text() = 'UK']") .log("Sending order ${file:name} to the UK") .to("file:work/cbr/output/uk") .when().xpath("//order/customer/country[text() = 'US']") .log("Sending order ${file:name} to the US") .to("file:work/cbr/output/uk") .otherwise() .log("Sending order ${file:name} to another country") .to("file:work/cbr/output/others"); } }
Copy to Clipboard Copied! CEQ アプリケーションをコンパイルします。
mvn clean compile quarkus:dev
mvn clean compile quarkus:dev
Copy to Clipboard Copied!
このコマンドでは、プロジェクトのコンパイル、アプリケーションの起動、Quarkus ツールでのワークスペースの変更監視などを行います。プロジェクトの変更は自動的に実行中のアプリケーションに適用されます。