第9章 Camel アプリケーションの A-MQ ブローカーとの統合

このチュートリアルでは、A-MQ イメージを使用してクイックスタートをデプロイする方法を説明します。

9.1. Spring Boot Camel A-MQ クイックスタートのビルドおよびデプロイ

このクイックスタートでは、Spring Boot アプリケーションを AMQ Online に接続する方法と、Fuse on OpenShift を使用して 2 つの Camel ルートの間で JMS メッセージングを使用する方法を実証します。

前提条件

  • AMQ Online がデプロイされ、稼働しているようにしてください。AMQ Online を OpenShift にインストールするには、Installing and configuring AMQ Online on OpenShift を参照してください。
  • OpenShift が適切に稼働し、Fuse イメージストリームがすでに OpenShift にインストールされている。管理者向けの基本情報 を参照してください。
  • Maven リポジトリーが Fuse に対して設定されているようにしてください。詳細は Maven リポジトリーの設定 を参照してください。

手順

  1. 開発者として OpenShift サーバーにログインします。

    oc login -u developer -p developer
  2. openshift プロジェクトにログインします。

    oc project openshift
  3. Maven ワークフローを使用して、クイックスタートプロジェクトを作成します。

    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \
    -DarchetypeCatalog=https://maven.repository.redhat.com/ga/io/fabric8/archetypes/archetypes-catalog/2.2.0.fuse-sb2-7_11_1-00018-redhat-00002/archetypes-catalog-2.2.0.fuse-sb2-7_11_1-00018-redhat-00002-archetype-catalog.xml \
    -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \
    -DarchetypeArtifactId=spring-boot-camel-amq-archetype \
    -DarchetypeVersion=2.2.0.fuse-sb2-7_11_1-00018-redhat-00002
  4. archetype プラグインが対話モードに切り替わり、残りのフィールドの入力を要求されます。

    Define value for property 'groupId': : org.example.fis
    Define value for property 'artifactId': : fuse77-spring-boot-camel-amq
    Define value for property 'version':  1.0-SNAPSHOT: :
    Define value for property 'package':  org.example.fis: :
    Confirm properties configuration:
    groupId: org.example.fis
    artifactId: fuse77-spring-boot-camel-amq
    version: 1.0-SNAPSHOT
    package: org.example.fis
    Y: :Y

    プロンプトが表示されたら、org.example.fisgroupId の値として入力し、fuse77-spring-boot-camel-amqartifactId の値として入力します。残りのフィールドではデフォルト値を使用します。

  5. クイックスタートディレクトリー fuse77-spring-boot-camel-amq に移動します。

    cd fuse77-spring-boot-camel-amq
  6. 以下のコマンドを実行し、設定ファイルを AMQ Online に適用します。これらの設定ファイルによって、管理者権限を持つ AMQ Online ユーザーおよびキューが作成されます。

    oc login -u system:admin
    oc apply -f src/main/resources/k8s
  7. mvn コマンドを実行し、クイックスタートを OpenShift サーバーにデプロイします。

    mvn fabric8:deploy -Popenshift
  8. クイックスタートが正常に実行されていることを確認するには、以下を行います。

    1. ブラウザーで https://OPENSHIFT_IP_ADDR の OpenShift Web コンソールに移動します。OPENSHIFT_IP_ADDR はクラスターの IP アドレスに置き換えます。クレデンシャル (例: ユーザー名 developer、パスワード developer) を使用して、コンソールにログインします。
    2. 左側のパネルで Home をデプロイメントし、Status をクリックして openshift プロジェクトの Project Status ページを表示します。
    3. fuse77-spring-boot-camel-amq をクリックし、クイックスタートの概要情報ページを表示します。
    4. 左側のパネルで、Workloads を展開します。
    5. Pods をクリックした後、fuse77-spring-boot-camel-amq-xxxxx をクリックします。クイックスタートの Pod の詳細が表示されます。
    6. Logs をクリックし、アプリケーションのログを確認します。

      出力にはメッセージが正常に送信されたことが表示されます。

      10:17:59.825 [Camel (camel) thread #10 - timer://order] INFO  generate-order-route - Generating order order1379.xml
      10:17:59.829 [Camel (camel) thread #8 - JmsConsumer[incomingOrders]] INFO  jms-cbr-route - Sending order order1379.xml to the UK
      10:17:59.829 [Camel (camel) thread #8 - JmsConsumer[incomingOrders]] INFO  jms-cbr-route - Done processing order1379.xml
      10:18:02.825 [Camel (camel) thread #10 - timer://order] INFO  generate-order-route - Generating order order1380.xml
      10:18:02.829 [Camel (camel) thread #7 - JmsConsumer[incomingOrders]] INFO  jms-cbr-route - Sending order order1380.xml to another country
      10:18:02.829 [Camel (camel) thread #7 - JmsConsumer[incomingOrders]] INFO jms-cbr-route - Done processing order1380.xml
  9. Web インターフェイスでルートを表示するには、Open Java Console をクリックし、AMQ キューのメッセージをチェックします。