当前位置:网站首页>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
边栏推荐
- Problèmes de concurrence dans l'allocation de mémoire en tas
- Online filing process
- Panorama of enterprise power in China SSD industry
- NIO 零拷贝
- Genesis public chain and a group of encryption investors in the United States gathered in consensus 2022
- STP spanning tree protocol Foundation
- 磁盘的结构
- L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
- [ingénierie logicielle] points clés à la fin de la période
- [QT] QT event handling
猜你喜欢

In the era of full programming, should I give up this road?

Idea close global search box

socket done

Selection and comparison of message oriented middleware MQ

Cross border e-commerce, early entry and early benefit

Nuscenes -- remedies for missing image files or 0-size images encountered during dataset configuration

How to extract dates from web pages?

电力系统| IEEE论文投稿流程

AQS source code analysis

Data center basic network platform
随机推荐
Chapter 10 project stakeholder management
Why can some programmers get good offers with average ability?
Online filing process
envoy获取客户端真实IP
find your present (2)
Idea global search replace shortcut key
Selection and comparison of message oriented middleware MQ
Firewall working principle and detailed conversation table
Redis-跳表
CSRF and SSRF for web attacks
重磅!法大大上榜“专精特新”企业
New features of go1.18: efficient replication, new clone API for strings and bytes standard library
Layer 2 and layer 3 forwarding principle based on VLAN
cat写多行内容到文件
Idea close global search box
img2pdf
Process communication mode
Embedded development: tips and tricks -- clean jump from boot loader to application code
Docker installs redis-5.0.12. Detailed steps
NIO多路复用之Selector的使用