Red Hat build of Apache Camel for Spring Boot のスタートガイド


Red Hat build of Apache Camel 4.0

概要

このガイドでは、Red Hat build of Apache Camel を紹介し、Red Hat build of Apache Camel を使用してアプリケーションを作成およびデプロイするさまざまな方法について説明します。

はじめに

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。まずは、マスター (master)、スレーブ (slave)、ブラックリスト (blacklist)、ホワイトリスト (whitelist) の 4 つの用語の置き換えから始めます。この取り組みは膨大な作業を要するため、今後の複数のリリースで段階的に用語の置き換えを実施して参ります。詳細は、Red Hat CTO である Chris Wright のメッセージ をご覧ください。

第1章 Red Hat build of Apache Camel for Spring Boot のスタートガイド

このガイドでは、Red Hat build of Apache Camel for Spring Boot を紹介し、Red Hat build of Apache Camel for Spring Boot を使用してアプリケーションの構築を開始する方法を示します。

1.1. Red Hat build of Apache Camel for Spring Boot のスターター

Spring Boot の Camel サポートは、Camel の自動設定と多くの Camel コンポーネント のスターターを提供します。Camel コンテキストの独自の自動設定は、Spring コンテキストで使用可能な Camel ルートを自動検出し、主要な Camel ユーティリティー (プロデューサーテンプレート、コンシューマーテンプレート、型コンバーターなど) を Bean として登録します。

注記

Maven アーキタイプを使用して Camel for Spring Boot アプリケーションを生成する方法については、Maven を使用した Spring Boot アプリケーション用の Camel 生成 を参照してください。

まず、Camel Spring Boot BOM を Maven pom.xml ファイルに追加する必要があります。

<dependencyManagement>

    <dependencies>
        <!-- Camel BOM -->
        <dependency>
            <groupId>com.redhat.camel.springboot.platform</groupId>
            <artifactId>camel-spring-boot-bom</artifactId>
            <version>4.0.0.redhat-00039</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>

Spring Boot アプリケーションに必要な コンポーネントスターター も追加する必要があります。次の例は、自動設定スターターMQTT5 コンポーネント に追加する方法を示しています。

    <dependencies>
        <!-- ... other dependencies ... -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-paho-mqtt5</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] です。たとえば、MQTT5 ブローカーの URL を設定するには、次のように設定できます。

camel.component.paho-mqtt5.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("...");
    }

}

1.2. Spring Boot

Spring Boot は Camel を自動的に設定します。Camel コンテキストの独自の自動設定は、Spring コンテキストで使用可能な Camel ルートを自動検出し、主要な Camel ユーティリティー (プロデューサーテンプレート、コンシューマーテンプレート、型コンバーターなど) を Bean として登録します。

Maven ユーザーは、このコンポーネントを使用するために pom.xml に次の依存関係を追加する必要があります。

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot</artifactId>
    <version>4.0.0.redhat-00039</version> <!-- use the same version as your Camel core version -->
</dependency>

camel-spring-boot jar には spring.factories ファイルが付属しているため、その依存関係をクラスパスに追加するとすぐに、Spring Boot によって Camel が自動的に設定されます。

1.2.1. Camel Spring Boot スターター

Apache Camel には、Spring Boot Starter モジュールが同梱されています。このモジュールを使用すると、スターターを使用して Spring Boot アプリケーションを開発できます。また、ソースコードに サンプルアプリケーション があります。

スターターを使用するには、Spring Boot pom.xml ファイルに以下を追加します。

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-bom</artifactId>
    <version>4.0.0.redhat-00039</version> <!-- use the same version as your Camel core version -->
</dependency>

さらに、次のような Camel ルートでクラスを追加します。

package com.example;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("timer:foo").to("log:bar");
    }
}

その後、これらのルートは自動的に開始されます。

application.properties または application.yml ファイルで Camel アプリケーションをカスタマイズできます。

1.2.2. Spring Boot 自動設定

Spring Boot で spring-boot を使用する場合は、自動設定をサポートするために必ず次の Maven 依存関係を使用してください。

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-spring-boot-starter</artifactId>
  <version>4.0.0.redhat-00039</version> <!-- use the same version as your Camel core version -->
</dependency>

1.2.3. 自動設定された Camel コンテキスト

Camel 自動設定によって提供される最も重要な機能は、CamelContext インスタンスです。Camel 自動設定は、SpringCamelContext を作成し、そのコンテキストの適切な初期化とシャットダウンを処理します。作成された Camel コンテキストは、Spring アプリケーションコンテキストにも (camelContext Bean 名で) 登録されるため、他の Spring Bean と同じようにアクセスできます。

@Configuration
public class MyAppConfig {

  @Autowired
  CamelContext camelContext;

  @Bean
  MyService myService() {
    return new DefaultMyService(camelContext);
  }

}

1.2.4. Camel ルートの自動検出

Camel 自動設定は、Spring コンテキストからすべての RouteBuilder インスタンスを収集し、提供された CamelContext にこれらのインスタンスを自動的に注入します。そのため、Spring Boot スターターを使用して新しい Camel ルートを作成するのは、@Component アノテーション付きクラスをクラスパスに追加するのと同じくらい簡単です。

@Component
public class MyRouter extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("jms:invoices").to("file:/invoices");
  }

}

または、新しいルートの RouteBuilder Bean を @Configuration クラスで作成します。

@Configuration
public class MyRouterConfiguration {

  @Bean
  RoutesBuilder myRouter() {
    return new RouteBuilder() {

      @Override
      public void configure() throws Exception {
        from("jms:invoices").to("file:/invoices");
      }

    };
  }

}

1.2.5. Camel プロパティー

Spring Boot の自動設定は、Camel プロパティーのサポートを使用して Spring Boot 外部設定 (プロパティーのプレースホルダー、OS 環境変数、またはシステムプロパティーを含む) に自動的に接続します。そのため、基本的に、次のように application.properties ファイルで定義されているプロパティーや、

route.from = jms:invoices

次のようにシステムプロパティーを介して設定されているプロパティーを、

java -Droute.to=jms:processed.invoices -jar mySpringApp.jar

次のように Camel ルートのプレースホルダーとして使用できます。

@Component
public class MyRouter extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("{{route.from}}").to("{{route.to}}");
  }

}

1.2.6. カスタムの Camel コンテキスト設定

Camel 自動設定によって作成された CamelContext Bean でいくつかの操作を実行する場合は、Spring コンテキストに CamelContextConfiguration インスタンスを登録します。

@Configuration
public class MyAppConfig {

  @Bean
  CamelContextConfiguration contextConfiguration() {
    return new CamelContextConfiguration() {
      @Override
      void beforeApplicationStart(CamelContext context) {
        // your custom configuration goes here
      }
    };
  }

}

beforeApplicationStart メソッドは Spring コンテキストが開始される直前に呼び出されるため、このコールバックに渡される CamelContext インスタンスは完全に自動設定されます。CamelContextConfiguration の複数のインスタンスを Spring コンテキストに追加すると、各インスタンスが実行されます。

1.2.7. 自動設定されたコンシューマーおよびプロデューサーのテンプレート

Camel 自動設定によって、事前設定された ConsumerTemplate および ProducerTemplate インスタンスが提供されます。それらを Spring 管理の Bean に簡単に注入できます。

@Component
public class InvoiceProcessor {

  @Autowired
  private ProducerTemplate producerTemplate;

  @Autowired
  private ConsumerTemplate consumerTemplate;

  public void processNextInvoice() {
    Invoice invoice = consumerTemplate.receiveBody("jms:invoices", Invoice.class);
    ...
    producerTemplate.sendBody("netty-http:http://invoicing.com/received/" + invoice.id());
  }

}

デフォルトでは、コンシューマーテンプレートとプロデューサーテンプレートのエンドポイントキャッシュサイズは 1000 に設定されています。これらの値は、次の Spring プロパティーを変更することで変更できます。

camel.springboot.consumer-template-cache-size = 100
camel.springboot.producer-template-cache-size = 200

1.2.8. 自動設定された TypeConverter

Camel 自動設定では、Spring コンテキストの typeConverter という名前の TypeConverter インスタンスを登録します。

@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public long parseInvoiceValue(Invoice invoice) {
    String invoiceValue = invoice.grossValue();
    return typeConverter.convertTo(Long.class, invoiceValue);
  }

}
1.2.8.1. Spring タイプコンバージョン API ブリッジ

Spring には、強力な タイプコンバージョン API が付属しています。Spring API は Camel の 型コンバーター API と似ています。両方の API は非常に似ているため、Camel Spring Boot は、Spring コンバージョン API に委譲するブリッジコンバーター (SpringTypeConverter) を自動的に登録します。そのため、初期状態の Camel は Spring コンバーターを Camel コンバーターと同様に扱います。このアプローチでは、Camel TypeConverter API 経由でアクセスする Camel コンバーターと Spring コンバーターの両方を使用できます。

@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public UUID parseInvoiceId(Invoice invoice) {
    // Using Spring's StringToUUIDConverter
    UUID id = invoice.typeConverter.convertTo(UUID.class, invoice.getId());
  }

}

Camel Spring Boot は内部で、アプリケーションコンテキストで利用可能な Spring の ConversionService インスタンスに変換を委譲します。ConversionService インスタンスが利用できない場合は、Camel Spring Boot 自動設定によってインスタンスが作成されます。

1.2.9. アプリケーションの存続

この機能が有効になっている Camel アプリケーションは、JVM の終了を防止してアプリケーションを存続させることのみを目的として、起動時に新しいスレッドを起動します。つまり、Spring Boot で Camel アプリケーションを開始した後、アプリケーションは Ctrl+C シグナルを待機し、すぐには終了しません。

コントローラースレッドは、Camel.springboot.main-run-controllertrue に設定することでアクティブ化できます。

camel.springboot.main-run-controller = true

Web モジュールを使用するアプリケーション (たとえば org.springframework.boot:spring-boot-web-starter モジュールをインポートするアプリケーション) は、他の非デーモンスレッドの存在によってアプリケーションが維持されるため、通常この機能を使用する必要はありません。

1.2.10. XML ルートの追加

デフォルトでは、Camel XML ルートをディレクトリー camel の下のクラスパスに配置できます。このルートは、camel-spring-boot によって自動検出されて組み込まれます。設定オプションを使用すると、ディレクトリー名を設定したり、この機能を無効化できます。

# turn off
camel.springboot.routes-include-pattern = false
# scan only in the com/foo/routes classpath
camel.springboot.routes-include-pattern = classpath:com/foo/routes/*.xml

XML ファイルは、(<CamelContext> ではなく) 次のような Camel XML ルートである必要があります。

<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="test">
        <from uri="timer://trigger"/>
        <transform>
            <simple>ref:myBean</simple>
        </transform>
        <to uri="log:out"/>
    </route>
</routes>

1.2.11. JUnit 5 方式のテスト

テストのために、Maven ユーザーは次の依存関係を pom.xml に追加する必要があります。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>3.1.6</version> <!-- Use the same version as your Spring Boot version -->
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-spring-junit5</artifactId>
    <version>4.0.0.redhat-00031</version> <!-- use the same version as your Camel core version -->
    <scope>test</scope>
</dependency>

Camel Spring Boot アプリケーションをテストするには、テストクラスに @CamelSpringBootTest のアノテーションを付けます。これにより、Camel の Spring Test サポートがアプリケーションに提供されるため、Spring Boot テスト規則 を使用してテストを作成できるようになります。

CamelContext または ProducerTemplate を取得するには、@Autowired を使用して、Spring の通常の方法でクラスに注入できます。

camel-test-spring-junit5 を使用して、テストを宣言的に設定することもできます。この例では、@MockEndpoints アノテーションを使用して、エンドポイントを自動モックします。

@CamelSpringBootTest
@SpringBootApplication
@MockEndpoints("direct:end")
public class MyApplicationTest {

    @Autowired
    private ProducerTemplate template;

    @EndpointInject("mock:direct:end")
    private MockEndpoint mock;

    @Test
    public void testReceive() throws Exception {
        mock.expectedBodiesReceived("Hello");
        template.sendBody("direct:start", "Hello");
        mock.assertIsSatisfied();
    }

}

1.3. コンポーネントスターター

Camel Spring Boot は、Spring Boot スターターとして次の Camel アーティファクトをサポートします。

Expand
表1.1 Camel コンポーネント
コンポーネントアーティファクト説明

AMQP

camel-amqp-starter

Apache QPid クライアントを使用した AMQP プロトコルによるメッセージング。

AWS Cloudwatch

camel-aws2-cw-starter

AWS SDK バージョン 2.x を使用してメトリクスを AWS CloudWatch に送信します。

AWS DynamoDB

camel-aws2-ddb-starter

AWS SDK バージョン 2.x を使用して、AWS DynamoDB サービスからデータを保存および取得します。

AWS Kinesis

camel-aws2-kinesis-starter

AWS SDK バージョン 2.x を使用して、AWS Kinesis Streams からレコードを消費し、AWS Kinesis Streams にレコードを作成します。

AWS Lambda

camel-aws2-lambda-starter

AWS SDK バージョン 2.x を使用して、AWS Lambda 関数を管理および呼び出します。

AWS S3 Storage Service

camel-aws2-s3-starter

AWS SDK バージョン 2.x を使用して、AWS S3 Storage Service からオブジェクトを保存および取得します。

AWS Simple Notification System (SNS)

camel-aws2-sns-starter

AWS SDK バージョン 2.x を使用して AWS Simple Notification Topic にメッセージを送信します。

AWS Simple Queue Service (SQS)

camel-aws2-sqs-starter

AWS SDK バージョン 2.x を使用して AWS SQS サービスを送信先および送信元としてメッセージを送受信します。

Azure ServiceBus

camel-azure-servicebus-starter

Azure Event Bus との間でメッセージを送受信します。

Azure Storage Blob Service

camel-azure-storage-blob-starter

SDK v12 を使用して Azure Storage Blob Service からブロブを保存および取得します。

Azure Storage Queue Service

camel-azure-storage-queue-starter

azure-storage-queue コンポーネントは、Azure SDK v12 を使用して Azure Storage Queue への/からのメッセージを保存および取得するために使用されます。

Bean

camel-bean-starter

Camel レジストリーに格納されている Java Bean のメソッドを呼び出します。

Bean Validator

camel-bean-validator-starter

Java Bean Validation API を使用してメッセージボディーを検証します。

Browse

camel-browse-starter

BrowsableEndpoint をサポートするエンドポイントで受信したメッセージを調べます。

Cassandra CQL

camel-cassandraql-starter

CQL3 API (Thrift API 以外) を使用して Cassandra 2.0 と統合します。DataStax が提供する Cassandra Java Driver をベースにしています。

Control Bus

camel-controlbus-starter

Camel ルートを管理および監視します。

Cron

camel-cron-starter

Unix cron 構文で指定されたタイミングでイベントをトリガーする汎用インターフェイス。

Crypto (JCE)

camel-crypto-starter

Java Cryptographic Extension (JCE) の署名サービスを使用してエクスチェンジに署名し、検証します。

CXF

camel-cxf-soap-starter

Apache CXF を使用して SOAP WebServices を公開するか、CXF WS クライアントを使用して外部 WebServices に接続します。

Data Format

camel-dataformat-starter

Camel Data Format を通常の Camel コンポーネントとして使用します。

Dataset

camel-dataset-starter

Camel アプリケーションの負荷テストおよびソークテスト用のデータを提供します。

Direct

camel-direct-starter

同じ Camel コンテキストから別のエンドポイントを同期的に呼び出します。

Elastic Search

camel-elasticsearch-starter

Java クライアント API 経由で ElasticSearch にリクエストを送信します。

FHIR

camel-fhir-starter

FHIR (Fast Healthcare Interoperability Resources) 規格を使用して、ヘルスケアドメインの情報を交換します。

File

camel-file-starter

ファイルの読み取りと書き込みを行います。

FTP

camel-ftp-starter

FTP サーバーとの間でファイルをアップロードおよびダウンロードします。

Google BigQuery

camel-google-bigquery-starter

分析用の Google BigQuery データウェアハウス。

Google Pubsub

camel-google-pubsub-starter

Google Cloud Platform PubSub サービスとの間でメッセージを送受信します。

gRPC

camel-grpc-starter

gRPC エンドポイントを公開し、外部 gRPC エンドポイントにアクセスします。

HTTP

camel-http-starter

Apache HTTP Client 4.x を使用して、外部の HTTP サーバーにリクエストを送信します。

Infinispan

camel-infinispan-starter

Infinispan の分散キー/値のストアとデータグリッドの読み取りと書き込みを行います。

Infinispan Embedded

camel-infinispan-embedded-starter

Infinispan の分散キー/値のストアとデータグリッドの読み取りと書き込みを行います。

JDBC

camel-jdbc-starter

SQL および JDBC を通じてデータベースにアクセスします。

Jira

camel-jira-starter

JIRA 問題トラッカーと対話します。

JMS

camel-jms-starter

JMS Queue または Topic との間でメッセージを送受信します。

JPA

camel-jpa-starter

Java Persistence API (JPA) を使用して、データベースから Java オブジェクトを保存し、取得します。

JSLT

camel-jslt-starter

JSLT を使用して JSON ペイロードをクエリーまたは変換します。

Kafka

camel-kafka-starter

Apache Kafka ブローカーとの間でメッセージを送受信します。

Kamelet

camel-kamelet-starter

Kamelets を呼び出します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-configmap-component-starter

camel-kubernetes-starter

Kubernetes ConfigMaps に対する操作を実行し、ConfigMaps の変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-custom-resources-component-starter

camel-kubernetes-starter

Kubernetes カスタムリソースに対する操作を実行し、デプロイメントの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-deployments-component-starter

camel-kubernetes-starter

Kubernetes デプロイメントに対する操作を実行し、デプロイメントの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-event-component-starter

camel-kubernetes-starter

Kubernetes イベントに対する操作を実行し、イベントの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-hpa-component-starter

camel-kubernetes-starter

Kubernetes Horizontal Pod Autoscaler (HPA) に対する操作を実行し、HPA の変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-job-component-starter

camel-kubernetes-starter

Kubernetes ジョブに対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-namespaces-component-starter

camel-kubernetes-starter

Kubernetes 名前空間に対する操作を実行し、名前空間の変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-nodes-component-starter

camel-kubernetes-starter

Kubernetes ノードに対する操作を実行し、ノードの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-persistent-volume-component-starter

camel-kubernetes-starter

Kubernetes 永続ボリュームに対する操作を実行し、永続ボリュームの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-persistent-volume-claim-component-starter

camel-kubernetes-starter

Kubernetes 永続ボリューム要求に対する操作を実行し、永続ボリューム要求の変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-pods-component-starter

camel-kubernetes-starter

Kubernetes Pod に対する操作を実行し、Pod の変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-replication-controller-component-starter

camel-kubernetes-starter

Kubernetes レプリケーションコントローラーに対する操作を実行し、レプリケーションコントローラーの変更に関する通知を受け取ります。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-resources-quota-component-starter

camel-kubernetes-starter

Kubernetes リソースクォータに対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-secrets-component-starter

camel-kubernetes-starter

Kubernetes シークレットに対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-service-account-component-starter

camel-kubernetes-starter

Kubernetes サービスアカウントに対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-services-component-starter

camel-kubernetes-starter

Kubernetes サービスに対する操作を実行し、サービスの変更に関する通知を受け取ります。

言語

camel-language-starter

Camel がサポートする任意の言語でスクリプトを実行します。

LDAP

camel-ldap-starter

LDAP サーバーで検索を実行します。

Log

camel-log-starter

基礎となるロギングメカニズムにメッセージをログとして記録します。

Mail

camel-mail-starter

imap、pop3、および smtp プロトコルを使用してメールを送受信します。

Mail Microsoft OAuth

camel-mail-microsoft-oauth-starter

Camel Mail OAuth2 Authenticator for Microsoft Exchange Online

MapStruct

camel-mapstruct-starter

Mapstruct を使用した型変換

Master

camel-master-starter

クラスター内の単一のコンシューマーのみが特定のエンドポイントから消費するようにします。JVM が停止した場合に自動的にフェイルオーバーします。

Micrometer

camel-micrometer-starter

Micrometer ライブラリーを使用して、Camel ルートからさまざまなメトリクスを直接収集します。

Minio

camel-minio-starter

Minio SDK を使用して、Minio Storage Service からオブジェクトを保存および取得します。

MLLP

camel-mllp-starter

MLLP プロトコルを使用して外部システムと通信します。

Mock

camel-mock-starter

モックを使用してルートおよび仲介ルールをテストします。

MongoDB

camel-mongodb-starter

MongoDB ドキュメントおよびコレクションの操作を実行します。

MyBatis

camel-mybatis-starter

MyBatis を使用して、リレーショナルデータベースでクエリー、ポーリング、挿入、更新、または削除を実行します。

Netty

camel-netty-starter

Netty 4.x で TCP または UDP を使用するソケットレベルのネットワーク。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-openshift-build-config-component-starter

camel-kubernetes-starter

OpenShift ビルド設定に対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-openshift-builds-component-starter

camel-kubernetes-starter

OpenShift ビルドに対する操作を実行します。

link:https://access.redhat.com/documentation/ja-jp/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_spring_boot_reference/index#csb-camel-kubernetes-openshift-deploymentconfigs-component-starter

camel-kubernetes-starter

Openshift デプロイメント設定に対する操作を実行し、デプロイメント設定の変更に関する通知を受け取ります。

Netty HTTP

camel-netty-http-starter

Netty 4.x を使用する Netty HTTP サーバーおよびクライアント。

Paho

camel-paho-starter

Eclipse Paho MQTT クライアントを使用して MQTT メッセージブローカーと通信します。

Paho MQTT 5

camel-paho-mqtt5-starter

Eclipse Paho MQTT v5 クライアントを使用して MQTT メッセージブローカーと通信します。

Platform HTTP

camel-platform-http-starter

現在のプラットフォームで利用可能な HTTP サーバーを使用して HTTP エンドポイントを公開します。

Quartz

camel-quartz-starter

Quartz 2.x スケジューラーを使用してメッセージの送信をスケジュールします。

Ref

camel-ref-starter

Camel Registry で名前によって動的に検索されたエンドポイントにメッセージをルーティングします。

REST

camel-rest-starter

REST サービスを公開するか、外部 REST サービスを呼び出します。

Saga

camel-saga-starter

Saga EIP を使用して、ルート内でカスタムアクションを実行します。

Salesforce

camel-salesforce-starter

Java DTO を使用して Salesforce と通信します。

SAP

camel-sap-starter

SAP Java コネクター (SAP JCo) ライブラリーを使用して SAP との双方向通信を容易にし、SAP IDoc ライブラリーを使用して中間ドキュメント (IDoc) 形式でのドキュメントの送信を容易にします。

Scheduler

camel-scheduler-starter

java.util.concurrent.ScheduledExecutorService を使用して、指定された間隔でメッセージを生成します。

SEDA

camel-seda-starter

同じ JVM の Camel コンテキストから別のエンドポイントを非同期に呼び出します。

Servlet

camel-servlet-starter

Servlet によって HTTP リクエストを処理します。

Slack

camel-slack-starter

Slack との間でメッセージを送受信します。

SNMP

camel-snmp-starter

トラップを受信し、SNMP (Simple Network Management Protocol) 対応デバイスをポーリングします。

Spring Batch

camel-spring-batch-starter

さらに処理するためにメッセージを Spring Batch に送信します。

Spring JDBC

camel-spring-jdbc-starter

Spring Transaction サポートにより、SQL および JDBC を介してデータベースにアクセスします。

Spring LDAP

camel-spring-ldap-starter

メッセージペイロードとしてフィルターを使用して、LDAP サーバーで検索を実行します。

Spring RabbitMQ

camel-spring-rabbitmq-starter

Spring RabbitMQ クライアントを使用して RabbitMQ からメッセージを送受信します。

Spring Redis

camel-spring-redis-starter

Redis からメッセージを送受信します。

Spring Webservice

camel-spring-ws-starter

このコンポーネントを使用して、Spring Web Services と統合できます。Web サービスにアクセスするためのクライアント側のサポート、およびコントラクトファースト Web サービスを作成するためのサーバー側のサポートを提供します。

SQL

camel-sql-starter

Spring JDBC を使用して SQL クエリーを実行します。

Stub

camel-stub-starter

開発中またはテスト中に物理エンドポイントをスタブアウトします。

Telegram

camel-telegram-starter

Telegram Bot API として動作するメッセージを送受信します。

Timer

camel-timer-starter

java.util.Timer を使用して、指定された間隔でメッセージを生成します。

Validator

camel-validator-starter

XML スキーマと JAXP 検証を使用してペイロードを検証します。

Velocity

camel-velocity-starter

Velocity テンプレートを使用してメッセージを変換します。

Vert.x HTTP クライアント

camel-vertx-http-starter

Vert.x を使用して、外部 HTTP サーバーにリクエストを送信します。

Vert.x WebSocket

camel-vertx-websocket-starter

WebSocket エンドポイントを公開し、Vert.x を使用してリモート WebSocket サーバーに接続します。

Webhook

camel-webhook-starter

Webhook エンドポイントを公開して、他の Camel コンポーネントのプッシュ通知を受信します。

XJ

camel-xj-starter

XSLT を使用して、JSON および XML メッセージを変換します。

XSLT

camel-xslt-starter

XSLT テンプレートを使用して XML ペイロードを変換します。

XSLT Saxon

camel-xslt-saxon-starter

Saxon を使用した XSLT テンプレートを使用して XML ペイロードを変換します。

Expand
表1.2 Camel データフォーマット
コンポーネントアーティファクト説明

Avro

camel-avro-starter

Apache Avro バイナリーデータフォーマットを使用して、メッセージをシリアライズおよびデシリアライズします。

Avro Jackson

camel-jackson-avro-starter

Jackson を使用して、POJO を Avro に (およびその逆に) マーシャリングします。

Bindy

camel-bindy-starter

Camel Bindy を使用して、POJO とキーと値のペア (KVP) 形式の間でマーシャリングおよびアンマーシャリングします。

HL7

camel-hl7-starter

HL7 MLLP コーデックを使用して、HL7 (Health Care) モデルオブジェクトをマーシャリングおよびアンマーシャリングします。

JacksonXML

camel-jacksonxml-starter

Jackson の XMLMapper エクステンションを使用して、XML ペイロードを POJO に、およびその逆にアンマーシャリングします。

JAXB

camel-jaxb-starter

JAXB2 XML マーシャリング標準を使用して、XML ペイロードを POJO に、およびその逆にアンマーシャリングします。

JSON Gson

camel-gson-starter

Gson を使用して、POJO を JSON に、およびその逆にマーシャリングします。

JSON Jackson

camel-jackson-starter

Jackson を使用して、POJO を JSON に、およびその逆にマーシャリングします。

Protobuf Jackson

camel-jackson-protobuf-starter

Jackson を使用して、POJO を Protobuf に、およびその逆にマーシャリングします。

SOAP

camel-soap-starter

Java オブジェクトを SOAP メッセージに、およびその逆にマーシャリングします。

Zip ファイル

camel-zipfile-starter

java.util.zip.ZipStream を使用して、ストリームを圧縮および圧縮解除します。

Expand
表1.3 Camel 言語
言語アーティファクト説明

Constant

camel-core-starter

固定の値は、ルートの起動時に一度だけ設定されます。

CSimple

camel-core-starter

コンパイルされた単純な式を評価します。

ExchangeProperty

camel-core-starter

Exchange からプロパティーを取得します。

File

camel-core-starter

Simple 言語のファイル関連機能。

Header

camel-core-starter

Exchange からヘッダーを取得します。

JQ

camel-jq-starter

JQ 式を JSON メッセージボディーに対して評価します。

JSONPath

camel-jsonpath-starter

JSON メッセージのボディーに対して、JsonPath 式を評価します。

Ref

camel-core-starter

レジストリーの既存の式を使用します。

Simple (単純)

camel-core-starter

Camel 単純式を評価します。

Tokenize

camel-core-starter

区切り文字パターンを使用してテキストペイロードをトークン化します。

XML Tokenize

camel-xml-jaxp-starter

XML ペイロードをトークン化します。

XPath

camel-xpath-starter

XML ペイロードに対して XPath 式を評価します。

XQuery

camel-saxon-starter

XQuery および Saxon を使用して XML ペイロードをクエリーまたは変換します。

Expand
表1.4 その他のエクステンション
エクステンションアーティファクト説明

Kamelet Main

camel-kamelet-main-starter

Kamelet スタンドアロンを実行するためのメイン

Openapi Java

camel-openapi-java-starter

openapi ドキュメントを使用するための REST-dsl サポート

OpenTelemetry

camel-opentelemetry-starter

OpenTelemetry を使用した分散トレース

Spring Security

camel-spring-security-starter

Spring Security を使用したセキュリティー

YAML DSL

camel-yaml-dsl-starter

YAML を使用した Camel DSL

1.4. スターター設定

明確でアクセスしやすい設定は、アプリケーションの重要な部分です。Camel スターター は、Spring Boot の 外部設定 メカニズムを完全にサポートします。より複雑なユースケースでは、Spring Bean を介してこのようなスターター設定することもできます。

1.4.1. 外部設定の使用

内部的には、すべての スターター は Spring Boot の ConfigurationProperties を介して設定されます。各設定パラメーターは、さまざまな 方法 で設定できます (application.[properties|json|yaml] ファイル、コマンドライン引数、環境変数など)。パラメーターの形式は camel.[component|language|dataformat].[name].[parameter] です。

たとえば、MQTT5 ブローカーの URL を設定するには、次のように設定できます。

camel.component.paho-mqtt5.broker-url=tcp://localhost:61616

また、CSV データフォーマットの delimeter をセミコロン (;) にするように設定することも可能です。

camel.dataformat.csv.delimiter=;

Camel は、プロパティーを目的のタイプに設定するときに、型コンバーター メカニズムを使用します。

#bean:name を使用して、レジストリー内の Bean を参照できます。

camel.component.jms.transactionManager=#bean:myjtaTransactionManager

通常、Bean は Java で作成されます。

@Bean("myjtaTransactionManager")
public JmsTransactionManager myjtaTransactionManager(PooledConnectionFactory pool) {
    JmsTransactionManager manager = new JmsTransactionManager(pool);
    manager.setDefaultTimeout(45);
    return manager;
}

Bean は 設定ファイル で作成することもできますが、これは複雑なユースケースには推奨されません。

1.4.2. Bean の使用

スターターは、Spring Bean を介して作成および設定することもできます。スターターを作成する前に、すでに存在する場合、Camel は最初にその名前でレジストリーを検索します。たとえば、Kafka コンポーネントを設定するには、次のようにします。

@Bean("kafka")
public KafkaComponent kafka(KafkaConfiguration kafkaconfiguration){
    return ComponentsBuilderFactory.kafka()
                        .brokers("{{kafka.host}}:{{kafka.port}}")
                        .build();
}

Bean 名は、設定するコンポーネント、データ形式、または言語の名前と同じである必要があります。Bean 名がアノテーションで指定されていない場合は、メソッド名に設定されます。

一般的な Camel Spring Boot プロジェクトでは、外部設定と Bean の組み合わせを使用してアプリケーションを設定します。Camel Spring Boot プロジェクトを設定する方法のその他の例については、サンプル リポジトリー を参照してください。

1.5. Maven を使用した Spring Boot アプリケーション用の Camel 生成

Maven アーキタイプ org.apache.camel.archetypes:camel-archetype-spring-boot:4.0.0.redhat-00039 を使用して、Red Hat build of Apache Camel for Spring Boot アプリケーションを生成できます。

手順

  1. 以下のコマンドを実行します。

    mvn archetype:generate \
     -DarchetypeGroupId=org.apache.camel.archetypes \
     -DarchetypeArtifactId=camel-archetype-spring-boot \
     -DarchetypeVersion=4.0.0.redhat-00039 \
     -DgroupId=com.redhat \
     -DartifactId=csb-app \
     -Dversion=1.0-SNAPSHOT \
     -DinteractiveMode=false
  2. アプリケーションをビルドします。

    mvn package -f csb-app/pom.xml
  3. アプリケーションを実行します。

    java -jar csb-app/target/csb-app-1.0-SNAPSHOT.jar
  4. アプリケーションによって生成された Hello World 出力のコンソールログを調べて、アプリケーションが実行されていることを確認します。

    com.redhat.MySpringBootApplication       : Started MySpringBootApplication in 3.514 seconds (JVM running for 4.006)
    Hello World
    Hello World

1.6. Camel Spring Boot アプリケーションの OpenShift へのデプロイ

このガイドでは、Camel Spring Boot アプリケーションを OpenShift にデプロイする方法を説明します。

前提条件

  • OpenShift クラスターにアクセスできる。
  • OpenShift oc CLI クライアントがインストールされている、または OpenShift Container Platform Web コンソールにアクセスできる。
注記

認定 OpenShift Container プラットフォームは、Camel for Spring Boot Supported Configurations にリストされています。次の例では、Red Hat OpenJDK 11 (ubi8/openjdk-11) コンテナーイメージを使用しています。

手順

  1. このガイドのセクション 1.5 Maven を使用した Spring Boot アプリケーション用の Camel 生成 の手順に従って、Maven を使用して Spring Boot アプリケーション用の Camel を生成します。
  2. 修正した pom.xml が存在するディレクトリー配下で以下のコマンドを実行します。

    mvn clean -DskipTests oc:deploy -Popenshift
  3. CSB アプリケーションが Pod 上で実行されていることを確認します。

    oc logs -f dc/csb-app

1.7. Red Hat build of Apache Camel for Spring Boot へのパッチ適用

新しい patch-maven-plugin メカニズムを使用すると、Red Hat Red Hat build of Apache Camel for Spring Boot アプリケーションにパッチを適用できます。このメカニズムを使用すると、異なる Red Hat アプリケーション BOM によって提供される個々のバージョン (camel-spring-boot-bom など) を変更できます。

patch-maven-plugin の目的は、Camel on Spring Boot BOM にリストされている依存関係のバージョンを、アプリケーションに適用するパッチのメタデータで指定されているバージョンに更新することです。

patch-maven-plugin は次の操作を実行します。

  • 現在の Red Hat アプリケーション BOM に関連するパッチのメタデータを取得します。
  • BOM からインポートされた <dependencyManagement> にバージョンの変更を適用します。

patch-maven-plugin は、メタデータを取得すると、プラグインが宣言されたプロジェクトの管理対象および直接の依存関係すべてに対して繰り返し処理を行い、CVE/パッチのメタデータを使用して、一致する依存関係バージョンを置き換えます。バージョンが置き換えられると、Maven ビルドが続行され、標準の Maven プロジェクトのステージに進みます。

手順

以下の手順では、アプリケーションにパッチを適用する方法を説明します。

  1. patch-maven-plugin をプロジェクトの pom.xml ファイルに追加します。patch-maven-plugin のバージョンは、Camel on Spring Boot BOM のバージョンと同じである必要があります。

    <build>
        <plugins>
            <<plugin>
                <groupId>com.redhat.camel.springboot.platform</groupId>
                <artifactId>patch-maven-plugin</artifactId>
                <version>${camel-spring-boot-version}</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
  2. mvn clean applymvn validate、または mvn dependency:tree コマンドのいずれかを実行すると、プラグインはプロジェクトモジュールを検索して、モジュールが Red Hat Red Hat build of Apache Camel for Spring Boot BOM を使用しているかどうかを確認します。サポートされている BOM は次のとおりです。

    • com.redhat.camel.springboot.platform:camel-spring-boot-bom: Red Hat build of Apache Camel for Spring Boot BOM 用
  3. プラグインは、上記の BOM を検出できない場合、次のメッセージを表示します。

    $ mvn clean install
    
    [INFO] Scanning for projects...
    [INFO]
    
    ========== Red Hat Maven patching ==========
    
    [INFO] [PATCH] No project in the reactor uses Camel on Spring Boot product BOM. Skipping patch processing.
    [INFO] [PATCH] Done in 7ms
    
    =================================================
  4. 正しい BOM が使用されている場合、パッチのメタデータが検出されますが、パッチは検出されません。

    $ mvn clean install
    
    [INFO] Scanning for projects...
    [INFO]
    
    ========== Red Hat Maven patching ==========
    
    [INFO] [PATCH] Reading patch metadata and artifacts from 2 project repositories
    [INFO] [PATCH]  - redhat-ga-repository: http://maven.repository.redhat.com/ga/
    [INFO] [PATCH]  - central: https://repo.maven.apache.org/maven2
    Downloading from redhat-ga-repository: http://maven.repository.redhat.com/ga/com/redhat/camel/springboot/platform/redhat-camel-spring-boot-patch-metadata/maven-metadata.xml
    Downloading from central: https://repo.maven.apache.org/maven2/com/redhat/camel/springboot/platform/redhat-camel-spring-boot-patch-metadata/maven-metadata.xml
    [INFO] [PATCH] Resolved patch descriptor: /path/to/.m2/repository/com/redhat/camel/springboot/platform/redhat-camel-spring-boot-patch-metadata/3.20.1.redhat-00043/redhat-camel-spring-boot-patch-metadata-3.20.1.redhat-00043.xml
    [INFO] [PATCH] Patch metadata found for com.redhat.camel.springboot.platform/camel-spring-boot-bom/[3.20,3.21)
    [INFO] [PATCH] Done in 938ms
    
    =================================================
  5. patch-maven-plugin は、この Maven メタデータを取得しようとします。

    • Camel Spring Boot BOM を含むプロジェクトの場合、com.redhat.camel.springboot.platform:redhat-camel-spring-boot-patch-metadata/maven-metadata.xml が解決されます。この XML データは、com.redhat.camel.springboot.platform:redhat-camel-spring-boot-patch-metadata:RELEASE 座標を持つアーティファクトのメタデータです。

      Maven によって生成されたメタデータの例

      <?xml version="1.0" encoding="UTF-8"?>
      <metadata>
        <groupId>com.redhat.camel.springboot.platform</groupId>
        <artifactId>redhat-camel-spring-boot-patch-metadata</artifactId>
        <versioning>
          <release>3.20.1.redhat-00041</release>
          <versions>
            <version>3.20.1.redhat-00041</version>
          </versions>
          <lastUpdated>20230322103858</lastUpdated>
        </versioning>
      </metadata>

  6. patch-maven-plugin は、メタデータを解析して、現在のプロジェクトに適用するバージョンを選択します。このアクションは特定のバージョンの Camel on Spring Boot BOM を使用する Maven プロジェクトのみで可能です。バージョン範囲以降に一致するメタデータのみが適用され、最新バージョンのメタデータのみが取得されます。
  7. patch-maven-plugin は、前の手順で見つかった groupIdartifactId、および version によって識別されるパッチのメタデータをダウンロードするためのリモート Maven リポジトリーのリストを収集します。これらの Maven リポジトリーは、アクティブなプロファイル内のプロジェクトの <repositories> 要素にリストされ、また settings.xml ファイルのリポジトリーにもリストされます。

    $ mvn clean install
    [INFO] Scanning for projects...
    [INFO]
    
    ========== Red Hat Maven patching ==========
    
    [INFO] [PATCH] Reading patch metadata and artifacts from 2 project repositories
    [INFO] [PATCH]  - MRRC-GA: https://maven.repository.redhat.com/ga
    [INFO] [PATCH]  - central: https://repo.maven.apache.org/maven2
  8. メタデータは、リモートリポジトリー、ローカルリポジトリー、または ZIP ファイルから取得されたものであっても、patch-maven-plugin によって分析されます。取得されたメタデータには CVE のリストが含まれており、CVE ごとに、影響を受ける Maven アーティファクト (glob パターンとバージョン範囲で指定) のリストと、指定の CVE に対する修正を含むバージョンが記載されています。以下に例を示します。

    <?xml version="1.0" encoding="UTF-8" ?>
    
    <<metadata xmlns="urn:redhat:patch-metadata:1">
        <product-bom groupId="com.redhat.camel.springboot.platform" artifactId="camel-spring-boot-bom" versions="[3.20,3.21)" />
        <cves>
        </cves>
        <fixes>
            <fix id="HF0-1" description="logback-classic (Example) - Version Bump">
                <affects groupId="ch.qos.logback" artifactId="logback-classic" versions="[1.0,1.3.0)" fix="1.3.0" />
            </fix>
        </fixes>
    </metadata>
  9. 最後に、現在のプロジェクトに含まれるすべての管理対象の依存関係に繰り返し処理を行うときに、パッチのメタデータで指定された修正のリストが参照されます。これらの依存関係のうち一致するもの (および管理対象の依存関係) が、固定バージョンに変更されます。以下に例を示します。

    $ mvn dependency:tree
    
    [INFO] Scanning for projects...
    [INFO]
    
    ========== Red Hat Maven patching ==========
    
    [INFO] [PATCH] Reading patch metadata and artifacts from 3 project repositories
    [INFO] [PATCH]  - redhat-ga-repository: http://maven.repository.redhat.com/ga/
    [INFO] [PATCH]  - local: file:///path/to/.m2/repository
    [INFO] [PATCH]  - central: https://repo.maven.apache.org/maven2
    [INFO] [PATCH] Resolved patch descriptor:/path/to/.m2/repository/com/redhat/camel/springboot/platform/redhat-camel-spring-boot-patch-metadata/3.20.1.redhat-00043/redhat-camel-spring-boot-patch-metadata-3.20.1.redhat-00043.xml
    [INFO] [PATCH] Patch metadata found for com.redhat.camel.springboot.platform/camel-spring-boot-bom/[3.20,3.21)
    [INFO] [PATCH]  - patch contains 1 patch fix
    [INFO] [PATCH] Processing managed dependencies to apply patch fixes...
    [INFO] [PATCH] - HF0-1: logback-classic (Example) - Version Bump
    [INFO] [PATCH]   Applying change ch.qos.logback/logback-classic/[1.0,1.3.0) -> 1.3.0
    [INFO] [PATCH]   Project com.test:yaml-routes
    [INFO] [PATCH]    - managed dependency: ch.qos.logback/logback-classic/1.2.11 -> 1.3.0
    [INFO] [PATCH] Done in 39ms
    
    =================================================

パッチのスキップ

特定のパッチをプロジェクトに適用する必要がない場合、patch-maven-plugin には skip オプションが用意されています。patch-maven-plugin をプロジェクトの pom.xml ファイルにすでに追加しており、バージョンを変更する必要がない場合は、次のいずれかの方法を使用してパッチをスキップできます。

  • 以下のように、プロジェクトの pom.xml ファイルに skip オプションを追加します。
<build>
    <plugins>
        <plugin>
            <groupId>com.redhat.camel.springboot.platform</groupId>
            <artifactId>patch-maven-plugin</artifactId>
            <version>${camel-spring-boot-version}</version>
            <extensions>true</extensions>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>
  • または、以下のように mvn コマンドの実行時に -DskipPatch オプションを使用します。
$ mvn clean install -DskipPatch
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.example:test-csb >-------------------------
[INFO] Building A Camel Spring Boot Route 1.0-SNAPSHOT
...

上記の出力にあるように、patch-maven-plugin は呼び出されず、パッチはアプリケーションに適用されません。

1.8. Camel REST DSL OpenApi Maven プラグイン

Camel REST DSL OpenApi Maven プラグインは、次の目的をサポートします。

  • camel-restdsl-openapi:generate - OpenApi 仕様からコンシューマー REST DSL RouteBuilder ソースコードを生成する
  • camel-restdsl-openapi:generate-with-dto - OpenApi 仕様から、swagger-codegen-maven-plugin 経由で生成された DTO モデルクラスを使用してコンシューマー REST DSL RouteBuilder ソースコードを生成する
  • camel-restdsl-openapi:generate-xml - OpenApi 仕様からコンシューマー REST DSL XML ソースコードを生成する
  • camel-restdsl-openapi:generate-xml-with-dto - OpenApi 仕様から、swagger-codegen-maven-plugin 経由で生成された DTO モデルクラスを使用してコンシューマー REST DSL XML ソースコードを生成する
  • camel-restdsl-openapi:generate-yaml - OpenApi 仕様からコンシューマー REST DSL YAML ソースコードを生成する
  • camel-restdsl-openapi:generate-yaml-with-dto - OpenApi 仕様から、swagger-codegen-maven-plugin 経由で生成された DTO モデルクラスを使用してコンシューマー REST DSL YAML ソースコードを生成する

1.8.1. Maven pom.xml へのプラグインの追加

このプラグインは、Spring Boot アプリケーションなどの plugins セクションに追加することで、Maven pom.xml ファイルに追加できます。

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

    <plugin>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-restdsl-openapi-plugin</artifactId>
      <version>{CamelCommunityVersion}</version>
    </plugin>

  </plugins>
</build>

次に、以下に示すように、接頭辞 camel-restdsl-openapi を使用してプラグインを実行できます。

$mvn camel-restdsl-openapi:generate

1.8.2. camel-restdsl-openapi:generate

Camel REST DSL OpenApi Maven プラグインの目的は、Maven から REST DSL RouteBuilder 実装ソースコードを生成するために使用されます。

1.8.3. オプション

プラグインは、コマンドラインから設定するか (-D 構文を使用)、configuration タグの pom.xml ファイルに定義できる次のオプションをサポートします。

Expand
パラメーターデフォルト値説明

skip

false

コード生成をスキップするには、true に設定します。

filterOperation

 

指定された操作 ID のみを含めるために使用されます。複数の ID はコンマで区切ることができます。ワイルドカードを使用できます。たとえば、find* を使用して、find で始まるすべての操作を含めることができます。

specificationUri

src/spec/openapi.json

OpenApi 仕様の URI は、ファイルシステムパス、HTTP およびクラスパスリソースをサポートします。デフォルトでは、プロジェクトディレクトリー内の src/spec/openapi.json です。JSON と YAML をサポートします。

auth

 

OpenApi 仕様定義をリモートで取得するときに認証ヘッダーを追加します。複数の値をコンマで区切って、name:header の URL エンコード文字列を渡します。

className

title または RestDslRoute から

生成されたクラスの名前。OpenApi 仕様のタイトルから取得されるか、デフォルトで RestDslRoute に設定されます。

packageName

host または rest.dsl.generatedから

生成されたクラスのパッケージの名前。OpenApi 仕様のホスト値またはデフォルトで rest.dsl.generated から取得されます。

indent

" "

使用するインデント文字 (デフォルトでは 4 つのスペース)、\t を使用してタブ文字を表すことができます。

outputDirectory

generated-sources/restdsl-openapi

生成されたソースファイルを配置する場所。デフォルトでは、プロジェクトディレクトリー内の generated-sources/restdsl-openapi

destinationGenerator

 

宛先エンドポイントをカスタマイズするための org.apache.camel.generator.openapi.DestinationGenerator インターフェイスを実装するクラスの完全修飾クラス名

destinationToSyntax

direct:${operationId}

to uri のデフォルトの to 構文では、direct コンポーネントが使用されます。

restConfiguration

true

検出された残りコンポーネントを使用した残り設定の生成を含めるかどうか。

apiContextPath

 

restConfiguration が true に設定されている場合は、openapi エンドポイントパスを定義します。

clientRequestValidation

false

リクエストの検証を有効にするかどうか。

basePath

 

OpenAPI 仕様で定義されている API ベースパスをオーバーライドします。

requestMappingValues

/**

カスタム RequestMapping マッピング値の生成を許可します。複数のマッピング値は次のように渡すことができます。

<requestMappingValues> <param>/my-api-path/</param> <param>/my-other-path/</param> </requestMappingValues>

1.8.4. サーブレットコンポーネントを含む Spring Boot プロジェクト

Maven プロジェクトが Spring Boot プロジェクトであり、restConfiguration が有効で、サーブレットコンポーネントが REST コンポーネントとして使用されている場合、このプラグインは @SpringBootApplication メインクラスが配置されているパッケージ名 (packageName が明示的に設定されていない場合) を自動検出します。そして、Rest DSL ソースコードと必要な CamelRestController サポートクラスの生成に同じパッケージ名を使用します。

1.8.5. camel-restdsl-openapi:generate-with-dto

generate ゴールとして機能しますが、swagger-codegen-maven-plugin を自動的に実行して OpenApi 仕様から DTO モデルクラスの Java ソースコードを生成することにより、DTO モデルクラスも生成します。

このプラグインは、モデル DTO を生成するために swagger-codegen-maven-plugin を使用するためのデフォルトの優れた努力セットのみをサポートするように範囲が定められ、制限されています。さらなるパワーと柔軟性が必要な場合は、このプラグインではなく、Swagger Codegen Maven プラグイン を直接使用して DTO を生成します。

DTO クラスには、次のような追加の依存関係が必要になる場合があります。

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.10.1</version>
    </dependency>
    <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-core</artifactId>
      <version>2.2.8</version>
    </dependency>
    <dependency>
      <groupId>org.threeten</groupId>
      <artifactId>threetenbp</artifactId>
      <version>1.6.8</version>
    </dependency>

1.8.6. オプション

プラグインは次の 追加 オプションをサポートしています。

Expand
パラメーターデフォルト値説明

swaggerCodegenMavenPluginVersion

3.0.36

使用する io.swagger.codegen.v3:swagger-codegen-maven-plugin Maven プラグインのバージョン。

modelOutput

 

ターゲット出力パス (デフォルトは ${project.build.directory}/generated-sources/openapi)

modelPackage

io.swagger.client.model

生成されたモデルオブジェクト/クラスに使用するパッケージ

modelNamePrefix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelNameSuffix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelWithXml

false

生成されたモデル内で XML アノテーションを有効にします (JSON および XML のサポートを提供するライブラリーのみで機能)。

configOptions

 

言語固有のパラメーターのマップを swagger-codegen-maven-plugin に渡します。

1.8.7. camel-restdsl-openapi:generate-xml

Camel REST DSL OpenApi Maven プラグインの camel-restdsl-openapi:generate-xml ゴールは、Maven から REST DSL XML 実装ソースコードを生成するために使用されます。

1.8.8. オプション

プラグインは、コマンドラインから設定するか (-D 構文を使用)、<configuration> タグの pom.xml ファイルに定義できる次のオプションをサポートします。

Expand
パラメーターデフォルト値説明

skip

false

コード生成をスキップするには、true に設定します。

filterOperation

 

指定された操作 ID のみを含めるために使用されます。複数の ID はコンマで区切ることができます。ワイルドカードを使用できます。たとえば、find* を使用して、find で始まるすべての操作を含めることができます。

specificationUri

src/spec/openapi.json

OpenApi 仕様の URI は、ファイルシステムパス、HTTP およびクラスパスリソースをサポートします。デフォルトでは、プロジェクトディレクトリー内の src/spec/openapi.json です。JSON と YAML をサポートします。

auth

 

OpenApi 仕様定義をリモートで取得するときに認証ヘッダーを追加します。複数の値をコンマで区切って、name:header の URL エンコード文字列を渡します。

outputDirectory

generated-sources/restdsl-openapi

生成されたソースファイルを配置する場所。デフォルトでは、プロジェクトディレクトリー内の generated-sources/restdsl-openapi

fileName

camel-rest.xml

出力としての XML ファイルの名前。

blueprint

false

有効にすると、Spring XML の代わりに OSGi Blueprint XML が生成されます。

destinationGenerator

 

宛先エンドポイントをカスタマイズするための org.apache.camel.generator.openapi.DestinationGenerator インターフェイスを実装するクラスの完全修飾クラス名

destinationToSyntax

direct:${operationId}

to uri のデフォルトの to 構文では、direct コンポーネントが使用されます。

 

restConfiguration

true

検出された残りコンポーネントを使用した残り設定の生成を含めるかどうか。

apiContextPath

 

restConfigurationtrue に設定されている場合は、openapi エンドポイントパスを定義します。

clientRequestValidation

false

リクエストの検証を有効にするかどうか。

basePath

 

OpenAPI 仕様で定義されている API ベースパスをオーバーライドします。

requestMappingValues

/**

1.8.9. camel-restdsl-openapi:generate-xml-with-dto

generate-xml ゴールとして機能しますが、swagger-codegen-maven-plugin を自動的に実行して OpenApi 仕様から DTO モデルクラスの Java ソースコードを生成することにより、DTO モデルクラスも生成します。

このプラグインは、モデル DTO を生成するために swagger-codegen-maven-plugin を使用するためのデフォルトの優れた努力セットのみをサポートするように範囲が定められ、制限されています。さらなるパワーと柔軟性が必要な場合は、このプラグインではなく、Swagger Codegen Maven プラグイン を直接使用して DTO を生成します。

DTO クラスには、次のような追加の依存関係が必要になる場合があります。

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.10.1</version>
    </dependency>
    <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-core</artifactId>
      <version>2.2.8</version>
    </dependency>
    <dependency>
      <groupId>org.threeten</groupId>
      <artifactId>threetenbp</artifactId>
      <version>1.6.8</version>
    </dependency>

1.8.10. オプション

プラグインは次の 追加 オプションをサポートしています。

Expand
パラメーターデフォルト値説明

swaggerCodegenMavenPluginVersion

3.0.36

使用する io.swagger.codegen.v3:swagger-codegen-maven-plugin Maven プラグインのバージョン。

modelOutput

 

ターゲット出力パス (デフォルトは ${project.build.directory}/generated-sources/openapi)

modelPackage

io.swagger.client.model

生成されたモデルオブジェクト/クラスに使用するパッケージ

modelNamePrefix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelNameSuffix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelWithXml

false

生成されたモデル内で XML アノテーションを有効にします (JSON および XML のサポートを提供するライブラリーのみで機能)。

configOptions

 

言語固有のパラメーターのマップを swagger-codegen-maven-plugin に渡します。

1.8.11. camel-restdsl-openapi:generate-yaml

Camel REST DSL OpenApi Maven プラグインの camel-restdsl-openapi:generate-yaml ゴールは、Maven から REST DSL YAML 実装ソースコードを生成するために使用されます。

1.8.12. オプション

プラグインは、コマンドラインから設定するか (-D 構文を使用)、<configuration> タグの pom.xml ファイルに定義できる次のオプションをサポートします。

Expand
パラメーターデフォルト値説明

skip

false

コード生成をスキップするには、true に設定します。

filterOperation

 

指定された操作 ID のみを含めるために使用されます。複数の ID はコンマで区切ることができます。ワイルドカードを使用できます。たとえば、find* を使用して、find で始まるすべての操作を含めることができます。

specificationUri

src/spec/openapi.json

OpenApi 仕様の URI は、ファイルシステムパス、HTTP およびクラスパスリソースをサポートします。デフォルトでは、プロジェクトディレクトリー内の src/spec/openapi.json です。JSON と YAML をサポートします。

auth

 

OpenApi 仕様定義をリモートで取得するときに認証ヘッダーを追加します。複数の値をコンマで区切って、name:header の URL エンコード文字列を渡します。

outputDirectory

generated-sources/restdsl-openapi

生成されたソースファイルを配置する場所。デフォルトでは、プロジェクトディレクトリー内の generated-sources/restdsl-openapi

fileName

camel-rest.xml

出力としての XML ファイルの名前。

destinationGenerator

 

宛先エンドポイントをカスタマイズするための org.apache.camel.generator.openapi.DestinationGenerator インターフェイスを実装するクラスの完全修飾クラス名

destinationToSyntax

direct:${operationId}

to uri のデフォルトの to 構文では、direct コンポーネントが使用されます。

 

restConfiguration

true

検出された残りコンポーネントを使用した残り設定の生成を含めるかどうか。

apiContextPath

 

restConfigurationtrue に設定されている場合は、openapi エンドポイントパスを定義します。

clientRequestValidation

false

リクエストの検証を有効にするかどうか。

basePath

 

OpenAPI 仕様で定義されている API ベースパスをオーバーライドします。

requestMappingValues

/**

1.8.13. camel-restdsl-openapi:generate-yaml-with-dto

generate-yaml ゴールとして機能しますが、swagger-codegen-maven-plugin を自動的に実行して OpenApi 仕様から DTO モデルクラスの Java ソースコードを生成することにより、DTO モデルクラスも生成します。

このプラグインは、モデル DTO を生成するために swagger-codegen-maven-plugin を使用するためのデフォルトの優れた努力セットのみをサポートするように範囲が定められ、制限されています。さらなるパワーと柔軟性が必要な場合は、このプラグインではなく、Swagger Codegen Maven プラグイン を直接使用して DTO を生成します。

DTO クラスには、次のような追加の依存関係が必要になる場合があります。

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.10.1</version>
    </dependency>
    <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-core</artifactId>
      <version>2.2.8</version>
    </dependency>
    <dependency>
      <groupId>org.threeten</groupId>
      <artifactId>threetenbp</artifactId>
      <version>1.6.8</version>
    </dependency>

1.8.14. オプション

プラグインは次の 追加 オプションをサポートしています。

Expand
パラメーターデフォルト値説明

swaggerCodegenMavenPluginVersion

3.0.36

使用する io.swagger.codegen.v3:swagger-codegen-maven-plugin Maven プラグインのバージョン。

modelOutput

 

ターゲット出力パス (デフォルトは ${project.build.directory}/generated-sources/openapi)

modelPackage

io.swagger.client.model

生成されたモデルオブジェクト/クラスに使用するパッケージ

modelNamePrefix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelNameSuffix

 

モデルクラスと列挙型の接頭辞または接尾辞を設定します。

modelWithXml

false

生成されたモデル内で XML アノテーションを有効にします (JSON および XML のサポートを提供するライブラリーのみで機能)。

configOptions

 

言語固有のパラメーターのマップを swagger-codegen-maven-plugin に渡します。

1.9. FIPS 準拠のサポート

FIPS で検証済み/進行中のモジュール (Modules in Process) 暗号ライブラリーを使用する OpenShift Container Platform クラスターを x86_64 アーキテクチャーにインストールすることができます。

クラスター内の Red Hat Enterprise Linux CoreOS (RHCOS) マシンの場合、この変更は、ユーザーがクラスターのデプロイ中に変更できるクラスターオプションを制御する install-config.yaml ファイル内のオプションのステータスに基づいてマシンをデプロイするときに適用されます。Red Hat Enterprise Linux (RHEL) マシンでは、ワーカーマシンとして使用する予定のマシンにオペレーティングシステムをインストールする場合に FIPS モードを有効にする必要があります。これらの設定方法により、クラスターが FIPS コンプライアンス監査の要件を満たしていることが保証されます。最初のシステム起動前に、FIPS 検証済み/プロセス中のモジュール暗号化パッケージのみが有効になります。

クラスターのオペレーティングシステムを初めて起動する前に FIPS を有効にする必要があるため、クラスターのデプロイ後に FIPS を有効にすることはできません。

1.9.1. OpenShift Container Platform での FIPS 検証

OpenShift Container Platform は、オペレーティングシステムコンポーネントに RHEL および RHCOS 内の特定の FIPS Validated/Modules in Process モジュールを使用します。たとえば、ユーザーが OpenShift Container Platform クラスターおよびコンテナーに対して SSH を実行する場合、それらの接続は適切に暗号化されます。

OpenShift Container Platform コンポーネントは Go で作成され、Red Hat の Golang コンパイラーを使用してビルドされます。クラスターの FIPS モードを有効にすると、暗号署名を必要とするすべての OpenShift Container Platform コンポーネントは RHEL および RHCOS 暗号ライブラリーを呼び出します。

FIPS の詳細は、FIPS モードの属性と制限事項 を参照してください。

OpenShift での Camel Spring Boot のデプロイの詳細は、Camel Spring Boot アプリケーションを OpenShift にデプロイする方法 を参照してください。

サポートされている設定の詳細は、Camel for Spring Boot Supported Configurations を参照してください。

第2章 Camel Spring Boot インテグレーションのモニタリング

この章では、実行時に Red Hat build of Camel Spring Boot のインテグレーションを監視する方法について説明します。OpenShift Monitoring の一部としてすでにデプロイされている Prometheus Operator を使用して、独自のアプリケーションを監視することができます。

2.1. OpenShift でのユーザーワークロードモニタリングの有効化

ユーザー定義プロジェクトのモニタリングを有効にするには、クラスターモニタリング ConfigMap オブジェクトの enableUserWorkload: true フィールドを設定します。

重要

OpenShift Container Platform 4.13 では、ユーザー定義プロジェクトのモニタリングを有効にする前に、カスタム Prometheus インスタンスを削除する必要があります。

前提条件

OpenShift Container Platform のユーザー定義プロジェクトのモニタリングを有効にするには、cluster-admin クラスターロールアクセスを持つユーザーとしてクラスターにアクセスできる必要があります。これにより、クラスター管理者は任意で、ユーザー定義のプロジェクトをモニターするコンポーネントを設定するパーミッションをユーザーに付与できます。

  • OpenShift クラスターにアクセス可能な cluster admin 権限がある。
  • OpenShift CLI (oc) がインストールされている。
  • cluster-monitoring-config ConfigMap オブジェクトを作成している。
  • オプション: user-workload-monitoring-config ConfigMap を openshift-user-workload-monitoring プロジェクトに作成している。ユーザー定義プロジェクトを監視するコンポーネントの ConfigMap オブジェクトに設定オプションを追加できます。
注記

設定の変更を user-workload-monitoring-config ConfigMap に保存するたびに、openshift-user-workload-monitoring プロジェクトの Pod が再デプロイされます。これらのコンポーネントが再デプロイするまで時間がかかる場合があります。ユーザー定義プロジェクトのモニタリングを最初に有効にする前に ConfigMap オブジェクトを作成し、設定することができます。これにより、Pod を頻繁に再デプロイする必要がなくなります。

手順

  1. 管理者権限で OpenShift にログインします。

    oc login --user system:admin --token=my-token --server=https://my-cluster.example.com:6443
  2. cluster-monitoring-config ConfigMap オブジェクトを編集します。

    $ oc -n openshift-monitoring edit configmap cluster-monitoring-config
  3. data/config.yaml セクションに enableUserWorkload: true を追加します。

        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: cluster-monitoring-config
          namespace: openshift-monitoring
        data:
          config.yaml: |
            enableUserWorkload: true

    true に設定すると、enableUserWorkload パラメーターはクラスター内のユーザー定義プロジェクトのモニタリングを有効にします。

  4. 変更を適用するためにファイルを保存します。ユーザー定義プロジェクトのモニタリングは自動的に有効になります。

    注記

    変更が cluster-monitoring-config ConfigMap オブジェクトに保存されると、openshift-monitoring プロジェクトの Pod および他のリソースは再デプロイされる可能性があります。該当するプロジェクトの実行中のモニタリングプロセスも再起動する可能性があります。

  5. prometheus-operatorprometheus-user-workload および thanos-ruler-user-workload Pod が openshift-user-workload-monitoring プロジェクトで実行中であることを確認します。

    $ oc -n openshift-user-workload-monitoring get pod
    
        Example output
    
        NAME                                   READY   STATUS        RESTARTS   AGE
        prometheus-operator-6f7b748d5b-t7nbg   2/2     Running       0          3h
        prometheus-user-workload-0             4/4     Running       1          3h
        prometheus-user-workload-1             4/4     Running       1          3h
        thanos-ruler-user-workload-0           3/3     Running       0          3h
        thanos-ruler-user-workload-1           3/3     Running       0          3h

2.2. Camel Spring Boot アプリケーションのデプロイ

プロジェクトのモニタリングを有効にすると、Camel Spring Boot アプリケーションをデプロイして監視できるようになります。このセクションでは、Camel Spring Boot Examples にリスト表示されている monitoring-micrometrics-grafana-prometheus の例を使用します。

手順

  1. openshift-maven-plugin を、monitoring-micrometrics-grafana-prometheus サンプルの pom.xml ファイルに追加します。pom.xmlopenshift プロファイルを追加して、openshift-maven-plugin を介して openshift にデプロイできるようにします。

        <profiles>
            <profile>
                <id>openshift</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jkube</groupId>
                            <artifactId>openshift-maven-plugin</artifactId>
                            <version>1.13.1</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>resource</goal>
                                        <goal>build</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
  2. Prometheus サポートを追加します。Prometheus サポートを Camel Spring Boot アプリケーションに追加するには、アクチュエーターエンドポイントで Prometheus 統計情報を公開します。

    1. src/main/resources/application.properties ファイルを編集します。management.endpoints.web.exposure.include エントリーがある場合は、prometheus、metrics、health を追加します。management.endpoints.web.exposure.include エントリーがない場合は、エントリーを追加してください。

      # expose actuator endpoint via HTTP
      management.endpoints.web.exposure.include=mappings,metrics,health,shutdown,jolokia,prometheus
  3. pom.xml の <dependencies/> セクションに以下を追加して、アプリケーションにスターターサポートを追加します。

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.jolokia</groupId>
        <artifactId>jolokia-core</artifactId>
        <version>${jolokia-version}</version>
    </dependency>
    
    <dependency>
        <groupId>io.prometheus.jmx</groupId>
        <artifactId>collector</artifactId>
        <version>${prometheus-version}</version>
    </dependency>
  4. Camel Spring Boot アプリケーションの Application.java に以下を追加します。

    import org.springframework.context.annonation.Bean;
    import org.apache.camel.component.micrometer.MicrometerConstants;
    import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
    import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
    import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
    import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
  5. 更新された Application.java を以下に示します。

    @SpringBootApplication
    public class SampleCamelApplication {
    
    @Bean(name = {MicrometerConstants.METRICS_REGISTRY_NAME, "prometheusMeterRegistry"})
    public PrometheusMeterRegistry prometheusMeterRegistry(
            PrometheusConfig prometheusConfig, CollectorRegistry collectorRegistry, Clock clock) throws MalformedObjectNameException, IOException {
    
        InputStream resource = new ClassPathResource("config/prometheus_exporter_config.yml").getInputStream();
    
        new JmxCollector(resource).register(collectorRegistry);
        new BuildInfoCollector().register(collectorRegistry);
        return new PrometheusMeterRegistry(prometheusConfig, collectorRegistry, clock);
    }
    
    @Bean
    public CamelContextConfiguration camelContextConfiguration(@Autowired PrometheusMeterRegistry registry) {
    
        return new CamelContextConfiguration() {
            @Override
            public void beforeApplicationStart(CamelContext camelContext) {
                MicrometerRoutePolicyFactory micrometerRoutePolicyFactory = new MicrometerRoutePolicyFactory();
                micrometerRoutePolicyFactory.setMeterRegistry(registry);
                camelContext.addRoutePolicyFactory(micrometerRoutePolicyFactory);
    
                MicrometerMessageHistoryFactory micrometerMessageHistoryFactory = new MicrometerMessageHistoryFactory();
                micrometerMessageHistoryFactory.setMeterRegistry(registry);
                camelContext.setMessageHistoryFactory(micrometerMessageHistoryFactory);
    
                MicrometerExchangeEventNotifier micrometerExchangeEventNotifier =  new MicrometerExchangeEventNotifier();
                micrometerExchangeEventNotifier.setMeterRegistry(registry);
                camelContext.getManagementStrategy().addEventNotifier(micrometerExchangeEventNotifier);
    
                MicrometerRouteEventNotifier micrometerRouteEventNotifier = new MicrometerRouteEventNotifier();
                micrometerRouteEventNotifier.setMeterRegistry(registry);
                camelContext.getManagementStrategy().addEventNotifier(micrometerRouteEventNotifier);
    
            }
    
            @Override
            public void afterApplicationStart(CamelContext camelContext) {
            }
        };
    }
  6. アプリケーションを OpenShift にデプロイします。

    mvn -Popenshift oc:deploy
  7. アプリケーションがデプロイされているかを確認します。

    oc get pods -n myapp
    
    NAME                                        READY   STATUS      RESTARTS   AGE
    camel-example-spring-boot-xml-2-deploy      0/1     Completed   0          13m
    camel-example-spring-boot-xml-2-x78rk       1/1     Running     0          13m
    camel-example-spring-boot-xml-s2i-2-build   0/1     Completed   0          14m
  8. このアプリケーションのサービスモニターを追加して、Openshift の Prometheus インスタンスが / actuator/prometheus エンドポイントからスクレイピングを開始できるようにします。

    1. サービスモニター用に次の YAML マニフェストを作成します。この例では、ファイルの名前は servicemonitor.yaml です。

      apiVersion: monitoring.coreos.com/v1
      kind: ServiceMonitor
      metadata:
        labels:
          k8s-app: csb-demo-monitor
        name: csb-demo-monitor
      spec:
        endpoints:
        - interval: 30s
          port: http
          scheme: http
          path: /actuator/prometheus
        selector:
          matchLabels:
            app: camel-example-spring-boot-xml
    2. このアプリケーションのサービスモニターを追加します。

      oc apply -f servicemonitor.yml
      servicemonitor.monitoring.coreos.com/csb-demo-monitor "myapp" created
  9. サービスモニターが正常にデプロイされたことを確認します。

    oc get servicemonitor
    
    NAME                   AGE
    csb-demo-monitor       9m17s
  10. スクレイプターゲットのリストにサービスモニターが表示されていることを確認します。Administrator ビューで、Observe → Targets に移動します。csb-demo-monitor は、スクレイプターゲットのリスト内にあります。
  11. servicemonitor をデプロイした後、約 10 分間待ちます。次に、Developer ビューで Observe → Metrics に移動します。ドロップダウンメニューで Custom query を選択し、camel と入力して、/actuator/prometheus エンドポイントを介して公開される Camel メトリクスを表示します。
注記

Red Hat は、OCP 以外の環境での Prometheus と Grafana のインストールおよび設定はサポートしません。

第3章 Spring XML での Camel の使用

Spring XML

Spring XML ファイルで Camel を使用して、Camel で XML DSL を使用できます。Camel は歴史的に長い間 Spring XML を使用してきました。Spring フレームワークは、Spring アプリケーションを構築するための一般的な設定として XML ファイルから始まりました。

Spring アプリケーションの例

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="direct:a"/>
            <choice>
                <when>
                    <xpath>$foo = 'bar'</xpath>
                    <to uri="direct:b"/>
                </when>
                <when>
                    <xpath>$foo = 'cheese'</xpath>
                    <to uri="direct:c"/>
                </when>
                <otherwise>
                    <to uri="direct:d"/>
                </otherwise>
            </choice>
        </route>
    </camelContext>

</beans>

3.1. Spring XML を使用した Camel ルートの指定

次に示すように、Spring XML ファイルを使用して、XML DSL を使用して Camel ルートを指定できます。

<camelContext id="camel-A" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="seda:start"/>
    <to uri="mock:result"/>
  </route>
</camelContext>

3.2. コンポーネントとエンドポイントの設定

この例の次のように、Spring XML で Component または Endpoint インスタンスを設定できます。

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
</camelContext>

<bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
  <property name="brokerURL" value="tcp:someserver:61616"/>
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory">
    <bean class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
  <property name="brokerURL" value="tcp:someserver:61616"/>
      </bean>
  </property>
</bean>

これにより、任意の名前を使用してコンポーネントを設定できますが、同じ名前 (jms など) を使用するのが一般的です。その後、jms:destinationName を使用してコンポーネントを参照できます。

これは、Camel がエンドポイント URI に使用するスキーム名の Spring コンテキストからコンポーネントを取得することによって機能します。

3.3. Spring XML ファイルでの Java DSL の使用

Java コードを使用して RouteBuilder 実装を定義できます。これらは Spring で Bean として定義され、次に示すように Camel コンテキストで参照されます。

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <routeBuilder ref="myBuilder"/>
</camelContext>

<bean id="myBuilder" class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>

3.4. パッケージスキャンの使用

Camel は、特定のパッケージ内のルートの自動検出と初期化を可能にする強力な機能も提供します。これは、Spring コンテキスト定義の Camel コンテキストにタグを追加し、RouteBuilder 実装を再帰的に検索するパッケージを指定することで設定されます。この機能を使用するには、検索するパッケージのコンマ区切りリストを指定する <package></package> タグを追加します。以下に例を示します。

<camelContext>
  <packageScan>
    <package>com.foo</package>
    <excludes>**.*Excluded*</excludes>
    <includes>**.*</includes>
  </packageScan>
</camelContext>

これにより、com.foo およびサブパッケージ内の RouteBuilder クラスがスキャンされます。

次のような包含または除外を使用してクラスをフィルタリングすることもできます。

<camelContext>
  <packageScan>
    <package>com.foo</package>
    <excludes>**.*Special*</excludes>
  </packageScan>
</camelContext>

これにより、名前に Special が含まれるクラスがスキップされます。exclude パターンは、include パターンの前に適用されます。include パターンまたは exclude パターンが定義されていない場合、パッケージで検出されたすべての Route クラスが返されます。

? は 1 つの文字に一致します。* は 0 個以上の文字に一致します。** は完全修飾名の 0 個以上のセグメントに一致します。

3.5. コンテキストスキャンの使用

Camel がコンテナーコンテキスト (たとえば、ルートビルダーインスタンスの Spring ApplicationContext) をスキャンできます。これにより、Spring の <component-scan> 機能を使用して、スキャンプロセスで Spring によって作成された RouteBuilder インスタンスを Camel にピックアップさせることができます。

<!-- enable Spring @Component scan -->
<context:component-scan base-package="org.apache.camel.spring.issues.contextscan"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <!-- and then let Camel use those @Component scanned route builders -->
    <contextScan/>
</camelContext>

これにより、Spring @Component を 使用してルートにアノテーションを付けるだけで、それらのルートを Camel に含めることができます。

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("direct:start")
            .to("mock:result");
    }
}

パッケージスキャンのセクションで説明したように、包含と除外に ANT スタイルを使用することもできます。

法律上の通知

Copyright © 2024 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る