当前位置:网站首页>Feign project construction
Feign project construction
2022-06-24 22:41:00 【Daily enlightenment】
1、Feign
OpenFeign yes Netflix Developed declarative 、 templated HTTP Requesting client , It can be more convenient 、 Call... Gracefully http api.OpenFeign The template of network request will be constructed according to the annotated function information , Before sending a network request ,OpenFeign The parameter values of the function will be set in these request templates .Feign It is mainly to build the consumer end of micro services , Just use OpenFeign The annotation provided modifies the interface class that defines the network request , You can use an instance of this interface to send RESTful Network request for , It can also integrate Ribbon and Hystrix, Provide load balancing and circuit breaker . It's a Http Lightweight framework for request invocation , It can be used Java Interface annotation method call Http request , Not like Java Through encapsulation HTTP The way of request message is called directly , By processing annotations , Template the request , When actually called , Pass in the parameter , Apply to the request again according to the parameters , And turn it into a real request , This kind of request is relatively intuitive .
2、Feign and OpenFeign The relationship between
Feign Itself does not support Spring MVC Annotations , It has its own set of notes .
OpenFeign yes Spring Cloud stay Feign Based on the support of Spring MVC Annotations , Such as @RequestMapping wait .OpenFeign Of @FeignClient Can be parsed SpringMVC Of @RequestMapping Interface under annotation , And through the way of dynamic proxy to produce the implementation class , Load balancing in the implementation class and calling other services .
3、 Project structures,
(1) Create project User-Provider
Selective dependency :Spring web、Eureka Discovery Client
(2) Create project User-API
Selective dependency :spring-boot-starter-web
Create an interface RegisterApi
@RequestMapping("/User")
public interface RegisterApi {
@GetMapping("/isAlive")
public String isAlive();
}
(3)User-Provider Realization API
The configuration file
eureka.client.service-url.defaultZone=http://euk1.com:7001/eureka/
server.port=81
spring.application.name=user-providerintroduce API
- maven install User-Api project
- User-Provider Of Pom.xml Add dependency
<dependency>
<groupId>com.example.User-API</groupId>
<artifactId>User-API</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>establish UserController, And implement Api The interface of
@RestController
public class UserController implements RegisterApi {
@Override
public String isAlive() {
return "ok";
}
}(4)Consumer call
Create project User-Consumer
Selective dependency :Spring web、Eureka Discovery Client、OpenFeign
introduce API: stay Pom.xml Add dependency
<dependency>
<groupId>com.example.User-API</groupId>
<artifactId>User-API</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>The configuration file :
eureka.client.service-url.defaultZone=http://euk1.com:7001/eureka/
server.port=90
spring.application.name=consumerestablish Service Interface
@FeignClient(name = "user-provider")
public interface UserConsumerService extends RegisterApi {
}establish Controller
@RestController
public class ConsumerController {
@Autowired
UserConsumerService consumerSrv;
@GetMapping("/alive")
public String alive() {
return consumerSrv.isAlive();
}
}Modify the startup class
@SpringBootApplication
@EnableFeignClients
public class UserConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(UserConsumerApplication.class, args);
}
}(5) test
visit http://localhost:90/alive You can complete the declarative remote service invocation
边栏推荐
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
- L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
- AQS source code analysis
- Data communication and physical network
- 2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)
- In the multi network card environment, the service IP registered by Nacos is incorrect, resulting in inaccessible services
- Data center basic network platform
- Embedded development: tips and tricks -- clean jump from boot loader to application code
- Power system | IEEE paper submission process
- 华大4A0GPIO设置
猜你喜欢

重磅!法大大上榜“专精特新”企业

Embedded development: tips and tricks -- clean jump from boot loader to application code

FANUC机器人_KAREL编程入门学习(1)

2022-06-10 work record --js- obtain the date n days after a certain date

Virtual private network foundation

NiO, bio, AIO

DX 的 HLSL 和 GL 的 GLSL的 矩阵构建的行列区别

Envoy obtain the real IP address of the client

Zero code can apply data visualization to enterprise management

关于自动控制原理资料更新
随机推荐
Huada 4a0gpio settings
Chapter 10 project communication management
The ktp900f mobile download program of the fail safe mobile panel prompts that the download cannot be performed, and the target device is running or not in the transmission mode
In the multi network card environment, the service IP registered by Nacos is incorrect, resulting in inaccessible services
Cross border e-commerce, early entry and early benefit
socket done
重磅!法大大上榜“专精特新”企业
Relationnet++: a representation of fusion of multiple detection targets based on transformer | neurips 2020
磁盤的結構
AQS source code analysis
Fanuc robot_ Introduction to Karel programming (1)
Learning notes 23-- basic theory of multi-sensor information fusion (Part I)
interrupt、interrupted 、isInterrupted 区别
The usage difference between isempty and isblank is so different that so many people can't answer it
Learn more about the practical application of sentinel
Pinduoduo updates the merchant live broadcast service agreement and strictly punishes the illegal merchants
Nuscenes -- remedies for missing image files or 0-size images encountered during dataset configuration
Why can some programmers get good offers with average ability?
HTTP的缓存控制
CA Zhouji - the first lesson in 2022 rust