This folder contains the source code for the Taco Cloud sample from Spring in Action, 5th edition, as presented in Chapter 19.
At this time, the code in this folder focuses primarily on the Eureka service registry, a Spring Cloud config server, the Hystrix dashboard, a Turbine server, an ingredient service, and a client that discovers that ingredient service from Eureka. That is to say that it contains only code relevant to the content in chapter 19, but not the complete Taco Cloud application. At some time in the future I may build out the remainder of the Taco Cloud application as a collection of microservices that register and discover each other through Eureka and use Spring Cloud Config Server for configuration.
It’s also important to note that example code tends to evolve throughout the course of a chapter. Moreover, there are often many different variants of a given piece of code presented. The sample code given here may only represent one such variant or evolution.
This folder contains three distinct projects:
-
boot-admin-server
: The Spring Boot Admin Server -
service-registry
: The Eureka service registry -
config-server
: The Spring Cloud Config Server -
hystrix-dashboard
: The Hystrix Dashboard -
turbine-server
: The Turbine server -
ingredient-service
: The ingredient service -
ingredient-client
: A client application that discovers the ingredient service from Eureka and consumes its endpoints -
taco-service
: A very basic, Spring Data REST-based taco service, primarily to demonstrate a few Actuator customizations
You’ll need to build and run each of the applications individually. In all cases, you can build the application using Maven like this:
% ./mvnw clean package
Once the projects are built, you can run their executable JAR files individually. For example, you can run the service registry like this:
% java -jar target/service-registry-0.0.19-SNAPSHOT.jar
The config server can be run like this:
% java -jar target/config-server-0.0.19-SNAPSHOT.jar
The admin server can be run like this:
% java -jar target/boot-admin-server-0.0.19-SNAPSHOT.jar
The Hystrix Dashboard can be run like this:
% java -jar target/hystrix-dashboard-0.0.19-SNAPSHOT.jar
The Turbine server can be run like this:
% java -jar target/turbine-server-0.0.19-SNAPSHOT.jar
The ingredient service can be run like this:
% java -jar target/ingredient-service-0.0.19-SNAPSHOT.jar
And the ingredient client can be run like this:
% java -jar target/ingredient-client-0.0.19-SNAPSHOT.jar
Finally, the taco service can be run like this:
% java -jar target/taco-service-0.0.19-SNAPSHOT.jar
Once each application has started up, the applications will be listening on the following ports:
-
boot-admin-server
: 9090 -
service-registry
: 8761 -
config-server
: 8888 -
hystrix-dashboard
: 7979 -
turbine-server
: 8989 -
ingredient-service
: A randomly chosen port -
ingredient-client
: 8080 -
taco-service
: 8081 (as specified by the configuration served by the config server from https://github.com/habuma/tacocloud-config)
To see it all in action, open your web browser and navigate to http://localhost:8080 to see a list of ingredients. If you click on an ingredient, you’ll be shown an ingredient detail page. The list and the data for each ingredient is ultimately produced by the ingredient service and consumed/presented by the ingredient client.
Note that it may take a few moments for the ingredient service to become fully registered with the service registry so that the ingredient client can find it. If you get errors from the ingredient client application, give it a few moments and refresh the page.
By default, the ingredient service is consumed by a @LoadBalanced
RestTemplate
. But the ingredient client project also contains code for consuming the service with WebClient
and with Feign. These options can be enabled by running the ingredient-client application with either the "webclient" profile or the "feign" profile active. For example, to run the client to use WebClient
:
% java -jar -Dspring.profiles.active=webclient target/ingredient-client-0.0.19-SNAPSHOT.jar
Or, to run it with the Feign-based client:
% java -jar -Dspring.profiles.active=feign target/ingredient-client-0.0.19-SNAPSHOT.jar
To try creating a taco through the taco service, you may use the curl
command like this:
% curl localhost:8081/tacos -H"Content-type: application/json" \
-d'{"name":"TEST TACO", "ingredients":[{"id":"FLTO","name":"Flour Tortilla"}, {"id":"LETC","name":"Lettuce"}, {"id":"GRBF", "name":"Ground Beef"}]}'
This should create a taco in the taco service, but most important to the discussion in chapter 19, it should also enable you to see the "taco-stats":"count" information in the /actuator/info
endpoint as well as view the "tacocloud" metrics from the /metrics/tacocloud
endpoint.
Note that per the ActuatorSecurityConfig
configuration class, all Actuator endpoint in the taco service, except for /info
and /health
, will require authentication. Using HTTP Basic authentication, the username is "admin" and the password is "password".
To view the Spring Boot Admin Server, navigate to http://localhost:9090 in your web browser. Per the security configuration described in section 19.3.1 in the book, you will be prompted to login. The username is "admin" and the password is "53cr3t".