Back-end HTTP library technology: (tools for sending HTTP requests and processing HTTP responses on the back-end server)
Spring WebClient
, Spring RestTemplate
, Retrofit
, Okhttp
,Feign
Feign is a declarative Web Service client
that uses annotations and reflection mechanisms to generate HTTP client code, allowing developers to call HTTP services through simple interface definitions without writing a lot of boilerplate code.
Feign also provides functions such as load balancing and service discovery, making it easier for developers to use distributed systems.
Spring Cloud OpenFeign:
- Official website
https://docs.spring.io/spring-cloud-openfeign/docs/2.2.x-SNAPSHOT/reference/html/index.html#spring-cloud-feign
use
The service discovery name or url address of the service can be known. There is an http interface under the service /post/test1
, /post/test2
which is called by FeignClient
- introduce
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
- Create a new interface class to call a series of interfaces in a certain project
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(name = "负载均衡器、服务发现中的服务名", url = "手动指定调用地址,绝对值或主机名")
public interface ComputeClient {
@RequestMapping(value = "/post/test1", method = RequestMethod.POST)
Response<TestDTO> test1(@RequestBody Test test);
@RequestMapping(value = "/post/test2", method = RequestMethod.POST)
Response<TestDTO> test2(@RequestBody Test test);
}
- transfer
@Resource
ComputeClient computeClient;
@Test
public void test1() {
return computeClient.test1(new Test());
}
@Test
public void test2() {
return computeClient.test2(new Test());
}