Spring Cloud Feignbased onNetflix Feignimplementation, integration ofSpring Cloud Ribbonwith theSpring Cloud Hystrix,In addition to providing a powerful feature of both, it also provides a declarativeWebHow the service client is defined
Create a new Spring boot project and name Demo-springcloud-feign-consumer, create a new startup class Feignapplication, by @ enablefeignclients Annotations to turn on Spring Cloud feign feature support
definition Yhqservice interface, bind the service by specifying the service name demo-springcloud-client @FeignClient annotations , and then use spring MVC To bind the rest interface provided by the service provider.
Project critical dependencies and configuration spring-cloud-starter-feign provide feign support
Start the registry, start service providers 1 and 2, start feign consumer demo-springcloud-feign-consumer, browser access Http://localhost:3332/feignConsumer
Below we add an interface with parameters for service providers 1 and 2 Helloparam return the string "helloparam1+ parameter" or " helloparam2+ parameter "
In the feign interface Yhqservice binding Helloparam interface, note that the @requestparam here cannot be omitted
Browser Access Http://localhost:3332/feignConsumerParam?name=test Validation results
Dry food sharing microservices Spring-cloud (5. Declarative service call feign)