이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 2. Getting Started with Spring Boot


2.1. Overview of the circuit breaker booster

The Netflix/Hystrix circuit breaker enables distributed applications to cope with interruptions to network connectivity and temporary unavailability of backend services. The basic idea of the circuit breaker pattern is that the loss of a dependent service is detected automatically and an alternative behavior can be programmed, in case the backend service is temporarily unavailable.

The Fuse circuit breaker booster consists of two related services:

  • A name service, the backend service that returns a name to greet.
  • A greetings service, the frontend service that invokes the name service to get a name and then returns the string, Hello, NAME.

In this booster demonstration, the Hystrix circuit breaker is inserted between the greetings service and the name service. If the backend name service becomes unavailable, the greetings service can fall back to an alternative behavior and respond to the client immediately, instead of being blocked while it waits for the name service to restart.

2.2. Prerequisites

To build and run the booster demonstration, install the following prerequisites:

2.3. Generate the booster project

To generate the circuit breaker booster project, perform the following steps:

  1. Navigate to https://developers.redhat.com/launch.
  2. Click START.

    The launcher wizard prompts you to log in to your Red Hat account.

  3. Click the Log in or register button and then log in.
  4. On the Launcher page, click the Deploy an Example Application button.
  5. On the Create Example Application page, type the name, fuse-circuit-breaker, in the Create Example Application as field.
  6. Click Select an Example.
  7. In the Example dialog, select the Circuit Breaker option. A Select a Runtime dropdown menu appears.

    1. From the Select a Runtime dropdown, select Fuse.
    2. From the version dropdown menu, select 7.2.0 (Red Hat Fuse) (do not select the 2.21.2 (Community) version).
    3. Click Save.
  8. On the Create Example Application page, click Download.
  9. When you see the Your Application is Ready dialog, click Download.zip. Your browser downloads the generated booster project (packaged as a ZIP file).
  10. Use an archive utility to extract the generated project to a convenient location on your local file system.

2.4. Build and run the booster

To build and run the booster project, perform the following steps:

  1. Open a shell prompt and build the project from the command line, using Maven:

    cd fuse-circuit-breaker
    mvn clean package

    After Maven builds the project, it displays a Build Success message.

  2. Open a new shell prompt and start the name service, as follows:

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

    As Spring Boot starts up, you should see output similar to the following:

    ...
    2019-06-14 15:38:37.380  INFO 31260 --- [           main] o.a.camel.spring.SpringCamelContext      : Total 1 routes, of which 1 are started
    2019-06-14 15:38:37.381  INFO 31260 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.21.0.fuse-720050-redhat-00001 (CamelContext: camel-1) started in 0.553 seconds
    2019-06-14 15:38:37.384  INFO 31260 --- [           main] o.a.c.c.s.CamelHttpTransportServlet      : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
    2019-06-14 15:38:37.463  INFO 31260 --- [           main] b.c.e.u.UndertowEmbeddedServletContainer : Undertow started on port(s) 8081 (http)
    2019-06-14 15:38:37.469  INFO 31260 --- [           main] com.redhat.fuse.boosters.cb.Application  : Started Application in 6.436 seconds (JVM running for 10.097)
  3. Open a new shell prompt and start the greetings service, as follows:

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

    As Spring Boot starts up, you should see output similar to the following:

    ...
    2019-06-14 15:39:57.650  INFO 31435 --- [           main] o.a.c.c.s.CamelHttpTransportServlet      : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
    2019-06-14 15:39:57.725  INFO 31435 --- [           main] b.c.e.u.UndertowEmbeddedServletContainer : Undertow started on port(s) 8080 (http)
    2019-06-14 15:39:57.732  INFO 31435 --- [           main] com.redhat.fuse.boosters.cb.Application  : Started Application in 6.91 seconds (JVM running for 11.243)

    The greetings service exposes a REST endpoint at the http://localhost:8080/camel/greetings URL.

  4. Invoke the REST endpoint by either opening the URL in a web browser or by opening another shell prompt and typing the following curl command:

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

    Here is the response:

    {"greetings":"Hello, Jacopo"}
  5. To demonstrate the circuit breaker functionality provided by Camel Hystrix, kill the backend name service by typing Ctrl-C in the shell prompt window where the name service is running.

    Now that the name service is unavailable, the circuit breaker kicks in to prevent the greetings service from hanging when it is invoked.

  6. Invoke the greetings REST endpoint by either opening http://localhost:8080/camel/greetings in a web browser or by typing the following curl command in another shell prompt window:

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

    Here is the response:

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

    In the window where the greetings service is running, the log shows the following sequence of messages:

    2019-06-14 15:42:27.016  INFO 31435 --- [-CamelHystrix-3] route2                                   :  Try to call name Service
    2019-06-14 15:42:27.019  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-06-14 15:42:27.019  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-06-14 15:42:27.020  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-06-14 15:42:27.020  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-06-14 15:42:27.020  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
    2019-06-14 15:42:27.020  INFO 31435 --- [-CamelHystrix-3] o.a.c.httpclient.HttpMethodDirector      : Retrying request
    2019-06-14 15:42:27.029  INFO 31435 --- [-CamelHystrix-3] route2                                   :  We are falling back!!!!
  7. For more information about this example, open the Circuit Breaker - Red Hat Fuse page at http://localhost:8080/ (while the greetings-service is running). This page includes a link to the Hystrix dashboard that monitors the state of the circuit breaker.
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동