[go: up one dir, main page]

0% found this document useful (0 votes)
24 views3 pages

05 Feign

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1/ 3

LAB- Using FEIGN

In this lab, you will be working on projects under working set 07-feign

We dont want to write code to make restful calls to the otherservices.

We just want to write the interfaces and want the implementation which makes rest calls to be
generated automatically.

If calls to restful services fail, we want fallbacks to be executed.

Now you should work on 07-01-cargo-booking-feign-start

Open pom.xml and complete TODO-1

Open CargoRoutingService.java inside


com.way2learnonline.booking.application.internal.outboundservices package and observe that
the interface methods are annotated with @RequestMapping just like in Spring@MVC Controller.

Complete the TODO-2

Can you tell what is the purpose of fallback configured in @FeignClient ?

Open CargoRoutingServiceFallback.java and observe that it is implementing


CargoRoutingService. This call contains the hystrix fallback methods which should be executed
incase the rest calls fail.

Also in Feign client we gave the name registered in Eureka. So, Feign will automatically lookup for
the service in Eureka and internally uses Ribbon also for doing load balancing.

Open CargoBookingApplication.java in 07-01-cargo-booking-feign-start and complete


TODO-3

After Enabling Feign Clients, proxies will be generated implemeting the interfaces

Start EurekaServer in 04-01-eureka-server

From boot dashboard, start 04-02-cargo-routing and 07-01-cargo-booking-feign-start


Go to Browser and check eureka console http://localhost:5001/ . You Should observe that all
the services are registered.

Open swagger ui at http://localhost:8081/swagger-ui.html

Like in earlier lab exercise, make a cargo booking and make a note of bookingId in response.

Use the below Json while making cargo booking:

{
"bookingAmount": 100,
"originLocation": "BLR",
"destLocation" : "DEL",
"destArrivalDeadline" : "2020-01-28"
}

Now make a request to route cargo from swagger ui using the bookingId

You should observe that cargo is routed successfully.

Observe the logs in STS console.

So, Feign Clients are able to make restful calls.

Now kill 04-02-cargo-routing application.

Now make a request to route cargo from swagger ui using the bookingId

You should observe in the console logs that fallback is called.

You should get 503 status code and error message as shown below:

. So, hystrix fallbacks are executed when the rest calls fail

How do you configure other hystrix related configuration?

Did you observe how we configure hystrix.command.default.execution.timeout.enabled?


Congratulations !! you know how to use Spring-Feign to create Declarative
restful clients

You might also like