Fuse 7 アプリケーションの Red Hat build of Apache Camel for Quarkus への移行
Fuse 7 アプリケーションの Red Hat build of Apache Camel for Quarkus への移行
概要
はじめに
Red Hat build of Apache Camel ドキュメントに関するフィードバック
エラーを報告したり、ドキュメントの改善を提案したりするには、Red Hat Jira アカウントにログインし、課題を送信してください。Red Hat Jira アカウントをお持ちでない場合は、アカウントを作成するように求められます。
手順
- 次のリンクをクリックして チケットを作成 します。
- Summary に課題の簡単な説明を入力します。
- Description に課題や機能拡張の詳細な説明を入力します。問題があるドキュメントのセクションへの URL も記載してください。
- Submit をクリックすると、課題が作成され、適切なドキュメントチームに転送されます。
第1章 Fuse 7 アプリケーションの Red Hat build of Apache Camel for Quarkus への移行の概要
1.1. EAP 上の Fuse、Red Hat build of Apache Camel for Quarkus および Camel
1.1.1. Fuse
Red Hat Fuse は、Apache Camel や Apache Karaf などのオープンソースコミュニティーに基づくアジャイル統合ソリューションです。Red Hat Fuse は軽量かつ柔軟性のある統合プラットフォームで、オンプレミスのクラウドの迅速な統合を可能にします。
Red Hat Fuse は、次の 3 つの異なるランタイムを使用して実行できます。
- OSGi アプリケーションをサポートする Karaf
- Spring Boot
- JBoss EAP (Enterprise Application Platform)
1.1.2. Red Hat build of Apache Camel for Quarkus
Red Hat build of Apache Camel for Quarkus は、Apache Camel とその膨大なコンポーネントライブラリーの統合機能を Quarkus ランタイムに提供します。Red Hat build of Camel Quarkus は、多くの Camel コンポーネントに Quarkus エクステンションを提供します。
Camel Quarkus は、Camel 3 に追加された多くのパフォーマンス上の改善点を活用します。これにより、メモリーフットプリントが削減し、リフレクションへの依存が減り、起動時間が短縮します。
Red Hat build of Apache Camel for Quarkus アプリケーションでは、Java DSL を使用して Camel ルートを定義するため、Fuse アプリケーションで使用する Camel ルートを CEQ に移行できます。
1.1.3. Camel on EAP
OSGI 依存関係管理の概念に従う Karaf と、JEE 仕様に従う EAP は、コンテナー化されたアプリケーションの採用の影響を受けるアプリケーションサーバーです。
コンテナーは、アプリケーションをパッケージ化するための主要な方法として出現しました。その結果、デプロイメント、スケーリング、クラスタリング、負荷分散を含むアプリケーション管理の役割が、アプリケーションサーバーから Kubernetes を使用したコンテナーオーケストレーションに移りました。
EAP は Red Hat Openshift で引き続きサポートされますが、Camel 3 は EAP サーバーではサポートされなくなりました。したがって、EAP サーバー上で Fuse 7 アプリケーションを実行している場合は、アプリケーションを Red Hat Build of Apache Camel for Spring Boot または Red Hat build of Apache Camel for Quarkus に移行することを検討する必要があります。その際、移行プロセスを利用して、モノリスアーキテクチャーからマイクロサービスアーキテクチャーへのアプリケーションの再設計、または部分的な再設計を検討することが推奨されます。
OpenShift を使用しない場合、Spring Boot および Quarkus を使用したアプリケーションのデプロイには、引き続き RHEL 仮想マシンを利用することが有効なアプローチとなります。また、Quarkus を使用する場合は、ネイティブコンパイル機能のメリットも得られます。このようなプラットフォーム上でマイクロサービスアーキテクチャーの管理をサポートするツールを評価することが重要です。
Red Hat は、Red Hat Ansible for Middleware コレクション を使用し、Ansible を通じてこの機能を提供します。
1.2. 標準的な移行パス
1.2.1. XML パス
Spring XML または Blueprint XML で記述された Fuse アプリケーションは、XML ベースのフレーバーに移行する必要があり、Spring Boot または Quarkus ランタイムのどちらかをターゲットにできます (移行手順はどちらも同じです)。
1.2.2. Java パス
Java DSL で記述された Fuse アプリケーションは Java ベースのフレーバーに移行する必要があり、移行手順は同じままで Spring Boot または Quarkus ランタイムのいずれかをターゲットにできます。
1.3. アーキテクチャーの変更
Openshift は Fabric8 に代わって Fuse 6 ユーザーのランタイムプラットフォームとなり、Fuse アプリケーションの移行における推奨ターゲットになります。
アプリケーションを移行するときは、次のアーキテクチャーの変更を考慮する必要があります。
- Fuse 6 アプリケーションが Fabric8 サービスディスカバリーに依存していた場合は、OpenShift で Camel 3 を実行するときに Kubernetes Service Discovery を使用する必要があります。
- Fuse 6 アプリケーションが OSGi バンドル設定に依存している場合は、OpenShift で Camel 3 を実行するときに Kubernetes ConfigMaps と Secret を使用する必要があります。
- アプリケーションがファイルベースのルート定義を使用している場合は、OpenShift で Camel 3 を実行するときに AWS S3 テクノロジーの使用を検討してください。
- アプリケーションが標準のファイルシステムを使用している場合は、結果として得られる Spring Boot または Quarkus アプリケーションを Openshift プラットフォームではなく標準の RHEL 仮想マシンにデプロイする必要があります。
- SSL 要件を処理する Openshift Router へのインバウンド HTTPS 接続の委譲。
- Hystrix 機能の Service Mesh への委譲。
1.4. javax
から jakarta
へのパッケージ名前空間の変更
Java EE は Eclipse Foundation に移行し、Jakarta EE が設立されました。Jakarta EE 9 以降、すべての EE API に使用されるパッケージは jakarta.*
に変更されました。
ドキュメント内のコードスニペットは jakarta.*
名前空間を使用するように更新されています。ただし、お客様のアプリケーションは注意してご確認いただく必要があります。
この変更は、Java SE に含まれる javax パッケージには影響しません。
アプリケーションを EE 10 に移行する場合は、次のことを行う必要があります。
-
import ステートメントまたはその他のソースコードにおける EE API クラスの使用を
javax
パッケージからjakarta
に更新します。 -
名前が
javax.
で始まる EE 指定のシステムプロパティーまたはその他の設定プロパティーを、jakarta.
で始まるものに変更します。 -
META-INF/services/jakarta.[rest_of_name]
名前形式を使用して、実装 EE インターフェイスを使用するアプリケーション内の実装クラス、またはjava.util.ServiceLoader
メカニズムでブートストラップされる抽象クラスを識別します。
1.4.1. 移行ツール
- ソースコードの移行: How to use Red Hat Migration Toolkit for Auto-Migration of an Application to the Jakarta EE 10 Namespace
- バイトコード変換: ソースコードの移行が可能ではない場合は、オープンソースの Eclipse Transformer
関連情報
第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 ツールでのワークスペースの変更監視などを行います。プロジェクトの変更は自動的に実行中のアプリケーションに適用されます。
2.2. Blueprint XML DSL ルートの移行
Blueprint XML ルート定義を Fuse アプリケーションから CEQ に移行するには、camel-quarkus-xml-io-dsl
エクステンションを使用し、Fuse アプリケーションのルート定義を CEQ アプリケーションに直接コピーします。次に、必要な依存関係を CEQ pom.xml
ファイルに追加し、application.properties
ファイル内の CEQ 設定を更新する必要があります。
CEQ は Camel 3 をサポートしますが、Fuse 7 は Camel 2 をサポートします。
Red Hat Fuse 7 アプリケーションを CEQ に移行する際の Camel のアップグレードに関する詳細は、Apache Camel の移行 を参照してください。
Camel Quarkus での Bean の使用に関する詳細は、Red Hat build of Apache Camel for Quarkus を使用したアプリケーションの開発 ガイドの CDI および Camel Bean コンポーネント セクションを参照してください。
2.2.1. XML-IO-DSL の制限事項
camel-quarkus-xml-io-dsl
エクステンションを使用すると、Blueprint XML ルート定義の CEQ への移行を支援できます。
camel-quarkus-xml-io-dsl
エクステンションは、次の <camelContext>
サブ要素のみをサポートします。
- routeTemplates
- templatedRoutes
- rests
- routes
- routeConfigurations
Blueprint XML は camel-quarkus-xml-io-dsl
エクステンションでサポートされていない他の Bean 定義をサポートしているため、Blueprint XML ルート定義に含まれる他の Bean 定義を書き直す必要が生じる場合があります。
すべての要素 (XML IO DSL) をそれぞれ別のファイルで定義する必要があります。たとえば、これは Blueprint XML ルート定義の簡単な例です。
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <restConfiguration contextPath="/camel" /> <rest path="/books"> <get uri="/"> <to ..../> </get> </rest> <route> <from ..../> </route> </camelContext> </blueprint>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration contextPath="/camel" />
<rest path="/books">
<get uri="/">
<to ..../>
</get>
</rest>
<route>
<from ..../>
</route>
</camelContext>
</blueprint>
次のファイルで定義されているように、XML IO DSL を使用して、この Blueprint XML ルート定義を CEQ に移行できます。
src/main/resources/routes/camel-rests.xml
<rests xmlns="http://camel.apache.org/schema/spring"> <rest path="/books"> <get path="/"> <to ..../> </get> </rest> </rests>
<rests xmlns="http://camel.apache.org/schema/spring">
<rest path="/books">
<get path="/">
<to ..../>
</get>
</rest>
</rests>
src/main/resources/routes/camel-routes.xml
<routes xmlns="http://camel.apache.org/schema/spring"> <route> <from ..../> </route> </routes>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from ..../>
</route>
</routes>
<restConfiguration>
など、サポートされていない他の要素を定義するには、Java DSL を使用する必要があります。たとえば、次のように、camel-rests.xml
ファイルで定義されたルートビルダーを使用します。
src/main/resources/routes/camel-rests.xml
import org.apache.camel.builder.RouteBuilder; public class Routes extends RouteBuilder { public void configure() { restConfiguration() .contextPath("/camel"); } }
import org.apache.camel.builder.RouteBuilder;
public class Routes extends RouteBuilder {
public void configure() {
restConfiguration()
.contextPath("/camel");
}
}
2.2.2. Blueprint XML DSL ルート移行の例
XML IO DSL エクステンションの使用に関する詳細は、Red Hat build of Apache Camel for Quarkus Extensions の XML IO DSL ドキュメントを参照してください。
この例では、Blueprint XML ルート定義を CEQ アプリケーションの camel-routes.xml
という名前のファイルにコピーして、Fuse アプリケーションから新しい CEQ アプリケーションにコンテンツベースのルート定義を移行しています。
手順
Web サイト
code.quarkus.redhat.com
を使用して、この例で使用する次のエクステンションを選択します。- camel-quarkus-xml-io-dsl
- camel-quarkus-file
- camel-quarkus-xpath
- Generate your application を選択して選択内容を確認し、生成されたプロジェクトを含むアーカイブのダウンロードリンクが記載されたオーバーレイ画面を表示します。
- Download the ZIP を選択して、生成されたプロジェクトファイルを含むアーカイブをマシンに保存します。
- アーカイブの内容をデプロイメントします。
直前の手順で生成されたプロジェクトファイルの展開先ディレクトリーに移動します。
cd <directory_name>
$ cd <directory_name>
Copy to Clipboard Copied! -
src/main/resources/routes/
ディレクトリーにcamel-routes.xml
という名前のファイルを作成します。 次の例
blueprint-example.xml
の<route>
要素とサブ要素をcamel-routes.xml
ファイルにコピーします。blueprint-example.xml
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint"> <route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route> </camelContext> </blueprint>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint"> <route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route> </camelContext> </blueprint>
Copy to Clipboard Copied! camel-routes.xml
<route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route>
<route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route>
Copy to Clipboard Copied! application.properties
を修正します。Camel
# Camel # camel.context.name = camel-quarkus-xml-io-dsl-example camel.main.routes-include-pattern = file:src/main/resources/routes/camel-routes.xml
Copy to Clipboard Copied! CEQ アプリケーションをコンパイルします。
mvn clean compile quarkus:dev
mvn clean compile quarkus:dev
Copy to Clipboard Copied! 注記このコマンドでは、プロジェクトのコンパイル、アプリケーションの起動、Quarkus ツールでのワークスペースの変更監視などを行います。プロジェクトの変更は自動的に実行中のアプリケーションに適用されます。