Chapter 2. Using Fuse boosters Red Hat Fuse provides the following boosters to help you get started with Fuse applications and demonstrate useful components: Section 2.2, "Build and run the Circuit Breaker booster" - An example of enabling a distributed application to cope with interruptions to network connectivity and temporary unavailability of backend services. Section 2.3, "Build and run the Externalized Configuration booster" - An example of how to externalize configuration for an Apache Camel route. Section 2.4, "Build and run the REST API booster" - An example that introduces the mechanics of interacting with a remote (exposed by Apache Camel) service using the HTTP protocol. 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 You must have access to the Red Hat Developer Platform . You must have a supported version of the Java Developer Kit (JDK). See the Supported Configurations page for details. You must have installed and configured Apache Maven 3.3.x or later as described in Setting up Maven locally ). Procedure Navigate to https://developers.redhat.com/launch . Click START . The launcher wizard prompts you to log in to your Red Hat account. Click the Log in or register button and then log in. On the Launcher page, click the Deploy an Example Application button. On the Create Example Application page, type the name, fuse-circuit-breaker , in the Create Example Application as field. Click Select an Example . In the Example dialog, select the Circuit Breaker option. A Select a Runtime dropdown menu appears. From the Select a Runtime dropdown, select Fuse . From the version dropdown menu, select 7.13 (Red Hat Fuse) (do not select the 2.21.2 (Community) version). Click Save . On the Create Example Application page, click Download . When you see the Your Application is Ready dialog, click Download.zip . Your browser downloads the generated booster project (packaged as a ZIP file). 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 you have completed the steps mentioned in the Section 2.1, "Generating your booster project" section. Procedure Follow these steps to build and run the Circuit breaker booster project: Open a shell prompt and build the project from the command line, using Maven: Open a new shell prompt and start the name service, as follows: As Spring Boot starts up, you should see some output like the following: Open a new shell prompt and start the greetings service, as follows: As Spring Boot starts up, you should see some output like the following: The greetings service exposes a REST endpoint at the URL, http://localhost:8080/camel/greetings . Go to http://localhost:8080 When you open this page, it invokes the Greeting Service: This page also provides a link to the Hystrix dashboard, which monitors the state of the circuit breaker. 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. Observe the changes in the Hystrix Monitor dashboard and in the 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 you have completed the steps mentioned in the Section 2.1, "Generating your booster project" section. 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: Download the project and extract the archive on your local filesystem. Build the project: Run the service: 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: Modify the booster.nameToGreet value: Open the target/classes/application.properties file in an editor. Change the value of the booster.nameToGreetvalue from default to another value, for example Thomas : In the Terminal window, stop the service by pressing CTRL+C . Run the service again: In the web browser, return to the http://localhost:8080 page to view the changed value in the Greeting Service's results window. 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, USDname! (where USDname 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 you have completed the steps mentioned in the Section 2.1, "Generating your booster project" section. Procedure Follow these steps to build and run the REST API booster as a standalone project on your local machine: Download the project and extract the archive on your local filesystem. Build the project: Run the service: Open a web browser to: http://localhost:8080 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: 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: To view the REST API's Swagger page, click the API Swagger page button. The API swagger page opens in a browser window.

Commands:
cd PROJECT_DIR mvn clean package
cd name-service mvn spring-boot:run -DskipTests -Dserver.port=8081
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)
cd greetings-service mvn spring-boot:run -DskipTests
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)
cd PROJECT_DIR mvn clean package
mvn spring-boot:run
booster.nameToGreetvalue=Thomas
mvn spring-boot:run
cd PROJECT_DIR mvn clean package
mvn spring-boot:run