第1章 Camel Spring Boot の概要
このガイドでは、Camel Spring Boot を紹介し、Camel Spring Boot を使用してアプリケーションの構築を開始する方法を示します。
1.1. Camel Spring Boot スターター
Spring Boot の Camel サポートは、多くの Camel コンポーネント の Camel とスターターの自動設定を提供します。Camel コンテキストのオピニオン自動設定は、Spring コンテキストで使用できる Camel ルートを自動検出し、プロデューサーテンプレート、コンシューマーテンプレート、タイプコンバーターなどの主な Camel ユーティリティーを Bean として登録します。
Maven archtype を使用して Camel for Spring Boot アプリケーションを生成する方法については 、Generating a Camel for Spring Boot application using Maven を 参照してください。
開始するには、Camel Spring Boot BOM を Maven pom.xml
ファイルに追加する必要があります。
<dependencyManagement> <dependencies> <!-- Camel BOM --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-bom</artifactId> <version>3.14.2.redhat-00054</version> <type>pom</type> <scope>import</scope> </dependency> <!-- ... other BOMs or dependencies ... --> </dependencies> </dependencyManagement>
<dependencyManagement>
<dependencies>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-bom</artifactId>
<version>3.14.2.redhat-00054</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- ... other BOMs or dependencies ... -->
</dependencies>
</dependencyManagement>
camel-spring-boot-bom
は、Camel Spring Boot スターター JAR のリストを含む基本的な BOM です。
次に、Camel Spring Boot スターター を追加して Camel Context を起動します。
<dependencies> <!-- Camel Starter --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-starter</artifactId> </dependency> <!-- ... other dependencies ... --> </dependencies>
<dependencies>
<!-- Camel Starter -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<!-- ... other dependencies ... -->
</dependencies>
Spring Boot アプリケーションに必要な コンポーネントスターター も追加する必要があります。次の例は、自動設定スターター を ActiveMQ コンポーネント に追加する方法を示しています。
<dependencies> <!-- ... other dependencies ... --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-activemq-starter</artifactId> </dependency> </dependencies>
<dependencies>
<!-- ... other dependencies ... -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-activemq-starter</artifactId>
</dependency>
</dependencies>
1.1.1. Camel Spring Boot BOM と Camel Spring Boot の依存関係 BOM
生成される精選された camel-spring-boot-dependencies
BOM には、Spring Boot と Apache Camel の両方が競合を回避するために使用する調整された JAR が含まれています。この BOM は camel-spring-boot 自体をテストするために使用されます。
Spring Boot ユーザーは、管理対象の依存関係として Camel スターター JAR のみを持つ camel-spring-boot-bom
を使用して、純粋な Camel 依存関係を使用することを選択できます。ただし、Spring Boot のサードパーティー JAR が特定の Camel コンポーネントと互換性がない場合、クラスパスの競合が発生する可能性があります。
1.1.2. Spring Boot 設定のサポート
各 スターター には、標準の application.properties
または application.yml
ファイルで設定できる設定パラメーターがリストされています。これらのパラメーターの形式は camel.component.[component-name].[parameter]
です。たとえば、ActiveMQ ブローカーの URL を設定するには、次のように設定できます。
camel.component.activemq.broker-url=tcp://localhost:61616
camel.component.activemq.broker-url=tcp://localhost:61616
1.1.3. Camel ルートの追加
Camel ルート は Spring アプリケーションコンテキストで検出されます。たとえば、org.springframework.stereotype.Component
でアノテーションが付けられたルートがロードされ、Camel コンテキストに追加されて実行されます。
import org.apache.camel.builder.RouteBuilder; import org.springframework.stereotype.Component; @Component public class MyRoute extends RouteBuilder { @Override public void configure() throws Exception { from("...") .to("..."); } }
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class MyRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("...")
.to("...");
}
}