Search

Chapter 2. Using Fuse boosters

download PDF

Red Hat Fuse provides the following boosters to help you get started with Fuse applications and demonstrate useful components:

Prerequisites To build and run the booster demonstrations, install the following prerequisites:

  • A supported version of the Java Developer Kit (JDK). See the Supported Configurations page for details.
  • Apache Maven 3.3.x or later. See the Maven Download page.

2.1. Generating your booster project

Fuse booster projects exist to help developers get started with running standalone applications. The instructions provided here guide you through generating one of those booster projects, the Circuit Breaker booster. This exercise demonstrates useful components of the Fuse on Spring Boot.

The Netflix/Hystrix circuit breaker enables distributed applications to handle 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.

Prerequisites

Procedure

  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.10 (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.2. Build and run the Circuit Breaker booster

The Netflix/Hystrix circuit breaker component 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, which returns a name to greet
  • A greetings service, which invokes the name service to get a name and then returns the string, Hello, NAME.

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

Prerequisites

Procedure

Follow these steps to build and run the Circuit breaker booster project:

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

    cd PROJECT_DIR
    mvn clean package
  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 some output like the following:

    ...
    2017-12-08 15:44:24.223  INFO 22758 --- [           main] o.a.camel.spring.SpringCamelContext      : Total 1 routes, of which 1 are started
    2017-12-08 15:44:24.227  INFO 22758 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.20.0 (CamelContext: camel-1) started in 0.776 seconds
    2017-12-08 15:44:24.234  INFO 22758 --- [           main] org.jboss.fuse.boosters.cb.Application   : Started Application in 4.137 seconds (JVM running for 4.744)
  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 some output like the following:

    ...
    2017-12-08 15:46:58.521  INFO 22887 --- [           main] o.a.c.c.s.CamelHttpTransportServlet      : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
    2017-12-08 15:46:58.524  INFO 22887 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
    2017-12-08 15:46:58.536  INFO 22887 --- [           main] org.jboss.fuse.boosters.cb.Application   : Started Application in 6.263 seconds (JVM running for 6.819)

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

  4. Go to http://localhost:8080

    When you open this page, it invokes the Greeting Service:

    Circuit breaker greeting service

    This page also provides a link to the Hystrix dashboard, which monitors the state of the circuit breaker.

    Hystrix dashboard for circuit breaker project
  5. To demonstrate the circuit breaker functionality provided by Camel Hystrix, kill the backend name service by pressing Ctrl+C while in the window of the shell prompt 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. Observe the changes in the Hystrix Monitor dashboard and in the Greeting Service output:

    Greeting service output

2.3. Build and run the Externalized Configuration booster

The Externalized Configuration booster provides an example of how to externalize configuration for an Apache Camel route. For Spring Boot standalone deployments, the configuration data is stored in an application.properties file.

Note

For Fuse on OpenShift deployments, the configuration data is stored in a ConfigMap object.

Prerequisites

Procedure

After you follow the Section 2.1, “Generating your booster project” steps for the Externalized Configuration mission, follow these steps to build and run the Externalized Configuration booster as a standalone project on your local machine:

  1. Download the project and extract the archive on your local filesystem.
  2. Build the project:

    cd PROJECT_DIR
    mvn clean package
  3. Run the service:

    mvn spring-boot:run
  4. Open a web browser to http://localhost:8080. This page invokes a Greeting Service every 5 seconds. The Greetings Service responds by using the booster.nameToGreetvalue from the target/classes/application.properties file.

    The Greeting Service prints a greeting to “default” every five seconds:

    Greeting serivce output for externalized configuration booster
  5. Modify the booster.nameToGreet value:

    1. Open the target/classes/application.properties file in an editor.
    2. Change the value of the booster.nameToGreetvalue from default to another value, for example Thomas:

      booster.nameToGreetvalue=Thomas
  6. In the Terminal window, stop the service by pressing CTRL+C.
  7. Run the service again:

    mvn spring-boot:run
  8. In the web browser, return to the http://localhost:8080 page to view the changed value in the Greeting Service’s results window.

    Changes in greeting service output

2.4. Build and run the REST API booster

The REST API Level 0 mission shows how to map business operations to a remote procedure call endpoint over HTTP by using a REST framework. This mission corresponds to Level 0 in the Richardson Maturity Model.

The REST API booster introduces the mechanics of interacting with a remote (exposed by Apache Camel) service using the HTTP protocol. By using this Fuse booster, you can quickly prototype and flexibly design a REST API.

Use this booster to:

  • Execute an HTTP GET request on the camel/greetings/{name} endpoint. This request produces a response in JSON format with a payload of Hello, $name! (where $name is replaced by the value of the URL parameter from the HTTP GET request).
  • Change the value of the URL {name} parameter to see the changed value reflected in the response.
  • View the REST API’s Swagger page.

Prerequisites

Procedure

Follow these steps to build and run the REST API booster as a standalone project on your local machine:

  1. Download the project and extract the archive on your local filesystem.
  2. Build the project:

    cd PROJECT_DIR
    mvn clean package
  3. Run the service:

    mvn spring-boot:run
  4. Open a web browser to: http://localhost:8080
  5. To execute the example HTTP GET request, click the camel/greetings/{name} button.

    A new web browser window opens with the localhost:8080/camel/greetings/Jacopo URL. The default value of the URL {name} parameter is Jacopo.

    The JSON response appears in the browser window:

    JSON response for REST API booster
  6. To change the value of the {name} parameter, change the URL. For example, to change the name to Thomas, use this URL: localhost:8080/camel/greetings/Thomas.

    The updated JSON response appears in the browser window:

    Updated JSON response for REST API booster
  7. To view the REST API’s Swagger page, click the API Swagger page button.

    The API swagger page opens in a browser window.

    REST API Swagger page
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.