✨ gateway-远程调用过网关
This commit is contained in:
parent
55c99b306e
commit
f9f40b362a
|
@ -1412,3 +1412,23 @@ spring:
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **负载均衡**:确保正确配置服务发现和负载均衡器
|
2. **负载均衡**:确保正确配置服务发现和负载均衡器
|
||||||
|
|
||||||
|
3. **远程调用是否过网关**
|
||||||
|
|
||||||
|
正常的远程调用是不过网关的,毕竟直接调用nacos中服务就行,多走一遍路没什么意思,如果非要过网关可以按照下面格式:
|
||||||
|
|
||||||
|
将`value`值修改为`gateway`,通常不建议过网关。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Feign 客户端
|
||||||
|
// @FeignClient(value = "service-product", path = "/api/product", fallback = ProductFeignClientFallback.class)
|
||||||
|
@FeignClient(value = "gateway", path = "/api/product", fallback = ProductFeignClientFallback.class)
|
||||||
|
public interface ProductFeignClient {
|
||||||
|
|
||||||
|
// 标注在 Controller 上是接受请求
|
||||||
|
// 标注在 FeignClient 时发送请求
|
||||||
|
@GetMapping("{id}")
|
||||||
|
Product getProduct(@PathVariable("id") Long productId);
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class RTFilter implements GlobalFilter, Ordered {
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
URI uri = request.getURI();
|
URI uri = request.getURI();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
log.error("请求【{}】开始时间:{}", uri, start);
|
log.info("请求【{}】开始时间:{}", uri, start);
|
||||||
|
|
||||||
// 处理逻辑
|
// 处理逻辑
|
||||||
// return chain.filter(exchange)
|
// return chain.filter(exchange)
|
||||||
|
|
|
@ -7,7 +7,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
// Feign 客户端
|
// Feign 客户端
|
||||||
@FeignClient(value = "service-product", path = "/api/product", fallback = ProductFeignClientFallback.class)
|
// @FeignClient(value = "service-product", path = "/api/product", fallback = ProductFeignClientFallback.class)
|
||||||
|
@FeignClient(value = "gateway", path = "/api/product", fallback = ProductFeignClientFallback.class)
|
||||||
public interface ProductFeignClient {
|
public interface ProductFeignClient {
|
||||||
|
|
||||||
// 标注在 Controller 上是接受请求
|
// 标注在 Controller 上是接受请求
|
||||||
|
|
Loading…
Reference in New Issue