1.3. ブースタープロジェクトのビルド

以下の手順では、Fuse on Spring Boot で Circuit Breaker ブースターをビルドする方法を説明します。

前提条件

手順

  1. シェルプロンプトを開き、Maven を使用してコマンドラインからプロジェクトをビルドします。

    cd fuse-circuit-breaker
    mvn clean package

    Maven によってプロジェクトがビルドされると、Build Success というメッセージが表示されます。

  2. 新しいシェルプロンプトを開き、以下のように name サービスを起動します。

    cd name-service
    mvn spring-boot:run -DskipTests -Dserver.port=8081

    Spring Boot が起動すると、以下のような出力が表示されます。

    ...
    2019-05-06 20:19:59.401  INFO 9553 --- [           main] o.a.camel.spring.SpringCamelContext      : Route: route1 started and consuming from: servlet:/name?httpMethodRestrict=GET
    2019-05-06 20:19:59.402  INFO 9553 --- [           main] o.a.camel.spring.SpringCamelContext      : Total 1 routes, of which 1 are started
    2019-05-06 20:19:59.403  INFO 9553 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.21.0.fuse-730078-redhat-00001 (CamelContext: camel-1) started in 0.287 seconds
    2019-05-06 20:19:59.406  INFO 9553 --- [           main] o.a.c.c.s.CamelHttpTransportServlet      : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
    2019-05-06 20:19:59.473  INFO 9553 --- [           main] b.c.e.u.UndertowEmbeddedServletContainer : Undertow started on port(s) 8081 (http)
    2019-05-06 20:19:59.479  INFO 9553 --- [           main] com.redhat.fuse.boosters.cb.Application  : Started Application in 5.485 seconds (JVM running for 9.841)
  3. 新しいシェルプロンプトを開き、以下のように greetings サービスを起動します。

    cd greetings-service
    mvn spring-boot:run -DskipTests

    Spring Boot が起動すると、以下のような出力が表示されます。

    ...
    2019-05-06 20:22:19.051  INFO 9729 --- [           main] o.a.c.c.s.CamelHttpTransportServlet      : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
    2019-05-06 20:22:19.115  INFO 9729 --- [           main] b.c.e.u.UndertowEmbeddedServletContainer : Undertow started on port(s) 8080 (http)
    2019-05-06 20:22:19.123  INFO 9729 --- [           main] com.redhat.fuse.boosters.cb.Application  : Started Application in 7.68 seconds (JVM running for 12.66)

    greetings サービスは http://localhost:8080/camel/greetings URL で REST エンドポイントを公開します。

  4. web ブラウザーで URL を開くか、別のシェルプロンプトで以下の curl コマンドを入力して、REST エンドポイントを呼び出します。

    curl http://localhost:8080/camel/greetings

    応答は次のとおりです。

    {"greetings":"Hello, Jacopo"}
  5. Camel Hystrix によって提供されるサーキットブレーカー機能を実証するために、name サービスが実行されているシェルプロンプトウインドウで Ctrl-C を入力し、バックエンド name サービスを強制終了します。

    これで name サービスが利用できなくなるため、呼び出されたときに greetings サービスがハングしないよう、サーキットブレーカーが作動します。

  6. web ブラウザーで http://localhost:8080/camel/greetings を開くか、別のシェルプロンプトウインドウに以下の curl コマンドを入力して、greetings REST エンドポイントを呼び出します。

    curl http://localhost:8080/camel/greetings

    応答は次のとおりです。

    {"greetings":"Hello, default fallback"}

    greetings サービスが実行されているウインドウで、ログに以下のメッセージシーケンスが表示されます。

    2019-05-06 20:24:16.952  INFO 9729 --- [-CamelHystrix-2] route2                                   :  Try to call name Service
    2019-05-06 20:24:16.956  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-05-06 20:24:16.956  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-05-06 20:24:16.957  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-05-06 20:24:16.957  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-05-06 20:24:16.957  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-05-06 20:24:16.957  INFO 9729 --- [-CamelHystrix-2] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-05-06 20:24:16.964  INFO 9729 --- [-CamelHystrix-2] route2                                   :  We are falling back!!!!
  7. この例に関する詳細は、greetings-service の実行中に http://localhost:8080/Circuit Breaker - Red Hat Fuse ページを開いてください。このページには、サーキットブレーカーの状態を監視する Hystrix ダッシュボードへのリンクが含まれます。