Feign Client Exercises
The goal of this exercise is to create Open Feign based clients for the three basic web services, and then use those client to expose a new composed web service.
All work for this exercise will be in the movie-aggregator-service project.
Movie Award Client
- Create a new interface called
MovieAwardServicein themicroservice.workshop.movieaggregatorservice.servicepackage - Enable this interface to be a Feign client for the existing movie award web service with the following characteristics:
- use the name
movie-award-servicefor the Feign client. - use the URL
http://localhost:8083 - write a method that will return a
List<MovieAward>for a given movie id
- use the name
Movie Cast Client
- Create a new interface called
MovieCastServicein themicroservice.workshop.movieaggregatorservice.servicepackage - Enable this interface to be a Feign client for the existing movie cast web service with the following characteristics:
- use the name
movie-cast-servicefor the Feign client. - use the URL
http://localhost:8082 - write a method that will return a
List<CastMember>for a given movie id
- use the name
Movie Client
- Create a new interface called
MovieServicein themicroservice.workshop.movieaggregatorservice.servicepackage - Enable this interface to be a Feign client for the existing movie web service with the following characteristics:
- use the name
movie-servicefor the Feign client. - use the URL
http://localhost:8081 - write a method that will return
Movie?for a given movie id
- use the name
Movie Aggregate Service
Make the following change to the class AggregateMovieService in the microservice.workshop.movieaggregatorservice.service package
- Inject the three new services you just created
- Alter the
findByIdmethod so that it returns an aggregated object. Call theMovieServicefirst. If it returns a movie, then call the other two web services to complete the object
Enable Feign
In the class microservice.workshop.movieaggregatorservice.MovieAggregatorServiceApplication, add the @EnableFeignClients annotation.
Test the application in the following way:
- Start all three of the individual web services by running the three application classes in each project, or by using the bootRun gradle goal on each project (or better yet, use the SpringBoot support in IntelliJ to start application through the services window)
- Once all three applications are running, you should be able to run the test
microservice.workshop.movieaggregatorservice.test.AggregateMovieControllerTestin themovie-aggregator-serviceproject successfully
Use the Traffic Simulator
Start the movie-aggregator-service application and access it’s swagger interface at http://localhost:8080
The aggregate service includes a simple SPA (single page application), written with Vue.js, that will send random requests to the aggregate service. This will be very useful when we start to work with Hystrix. You can try it now by navigating to the root of the aggregator project at http://localhost:8080. Once the page is open in a browser, press the “Start” button to start sending traffic to your new aggregate web service.
Once you are satifsfied that everything is working properly, end all four running web services.