你好,我是Qiuner. 为帮助别人少走弯路和记录自己编程学习过程而写博客 这是我的 github https://github.com/Qiuner ⭐️ gitee https://gitee.com/Qiuner 🌹 如果本篇文章帮到了你 不妨点个赞吧~ 我会很高兴的 😄 (^ ~ ^) 想看更多 那就点个关注吧 我会尽力带来有趣的内容 😎
https://blog.csdn.net/qq_61654952/article/details/139453099?spm=1001.2014.3001.5501 (这篇解释的比较官方,看目录,在最后那边)
- id: item # 路由规则id,自定义,唯一
uri: lb://item-service # 路由的目标服务,lb代表负载均衡,会从注册中心拉取服务列表
predicates: # 路由断言,判断当前请求是否符合当前规则,符合则路由到目标服务
- Path=/items/**,/search/** # 这里是以请求路径作为判断规则
/items/**
或 /search/**
时, 满足 Path
条件。符合条件的请求将会被路由从注册中心拉取 item-service
的服务列表到目标服务。推断
package com.hmall.gateway.filters;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@Component
public class MyGlobalFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// TODO 登录校验逻辑
ServerHttpRequest request=exchange.getRequest();
HttpHeaders headers=request.getHeaders();
return chain.filter(exchange) ;
}
@Override
public int getOrder() {
return 0;
}
}
https://blog.csdn.net/qq_61654952/article/details/138126798?spm=1001.2014.3001.5501
@ConditionalOnClass(DispatcherServlet.class
是Spring Boot中的一个条件注解,它在特定条件下有选择地加载某些配置或BeanDispatcherServlet
。只有当 DispatcherServlet
类存在于类路径中时,Spring才会实例化和加载标注了这个注解的配置类或Bean。微服务02-09.网关登录校验-OpenFeign传递用户信息_哔哩哔哩_bilibili
先进行登录操作,查看有那些发出了信息
二:点击结算
package com.hmall.api.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection;
@FeignClient("cart-service")
public interface CartClient {
@DeleteMapping("/carts")
void deleteCartItemByIds(@RequestParam("ids") Collection<Long> ids);
}
开始清理购物车商品 itemIds的值是[40305713537]
15:59:54:118 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] ---> DELETE http://cart-service/carts?ids=40305713537 HTTP/1.1
15:59:54:118 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] user-info: 1
15:59:54:118 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] ---> END HTTP (0-byte body)
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] <--- HTTP/1.1 200 (25ms)
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] connection: keep-alive
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] content-length: 0
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] date: Tue, 23 Jul 2024 07:59:54 GMT
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] keep-alive: timeout=60
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds]
15:59:54:144 DEBUG 39592 --- [nio-8085-exec-1] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] <--- END HTTP (0-byte body)
我是UserInfoInterceptor 我将要把数据存储到线程中 userInfo = 1
15:59:54:235 DEBUG 39592 --- [nio-8085-exec-2] c.h.trade.mapper.OrderMapper.selectById : ==> Preparing: SELECT id,total_fee,payment_type,user_id,status,create_time,pay_time,consign_time,end_time,close_time,comment_time,update_time FROM `order` WHERE id=?
15:59:54:235 DEBUG 39592 --- [nio-8085-exec-2] c.h.trade.mapper.OrderMapper.selectById : ==> Parameters: 1815658079372996609(Long)
15:59:54:243 DEBUG 39592 --- [nio-8085-exec-2] c.h.trade.mapper.OrderMapper.selectById : <== Total: 1
15:59:54:539 INFO 39592 --- [ent-executor-16] com.alibaba.nacos.common.remote.client : [f9caff51-eccd-4556-bcfd-9974893d2976] Receive server push request, request = NotifySubscriberRequest, requestId = 267
15:59:54:539 INFO 39592 --- [ent-executor-16] com.alibaba.nacos.common.remote.client : [f9caff51-eccd-4556-bcfd-9974893d2976] Ack server push request, request = NotifySubscriberRequest, requestId = 267
15:59:54:638 INFO 39592 --- [ent-executor-17] com.alibaba.nacos.common.remote.client : [f9caff51-eccd-4556-bcfd-9974893d2976] Receive server push request, request = NotifySubscriberRequest, requestId = 268
15:59:54:638 INFO 39592 --- [ent-executor-17] com.alibaba.nacos.common.remote.client : [f9caff51-eccd-4556-bcfd-9974893d2976] Ack server push request, request = NotifySubscriberRequest, requestId = 268
我是UserInfoInterceptor 我将要把数据存储到线程中 userInfo = 1
16:02:00:026 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] ---> GET http://item-service/items?ids=8533120 HTTP/1.1
16:02:00:027 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] user-info: 1
16:02:00:027 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] ---> END HTTP (0-byte body)
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] <--- HTTP/1.1 200 (7ms)
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] connection: keep-alive
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] content-type: application/json
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] date: Tue, 23 Jul 2024 08:02:00 GMT
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] keep-alive: timeout=60
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] transfer-encoding: chunked
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds]
16:02:00:033 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] [{"id":"8533120","name":"海尔 (Haier )LQ65H31 65英寸 4K曲面人工智能全面屏超高清LED液晶电视","price":379500,"stock":10000,"image":"https://m.360buyimg.com/mobilecms/s720x720_jfs/t1/2851/14/13998/101463/5bd9723cE81b2c299/1bfdf2d1628648e4.jpg!q70.jpg.webp","category":"曲面电视","brand":"海尔","spec":"{}","sold":0,"commentCount":0,"isAD":false,"status":1}]
16:02:00:035 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.ItemClient : [ItemClient#queryItemByIds] <--- END HTTP (384-byte body)
16:02:00:036 DEBUG 39592 --- [nio-8085-exec-4] c.hmall.trade.mapper.OrderMapper.insert : ==> Preparing: INSERT INTO `order` ( id, total_fee, payment_type, user_id, status ) VALUES ( ?, ?, ?, ?, ? )
16:02:00:036 DEBUG 39592 --- [nio-8085-exec-4] c.hmall.trade.mapper.OrderMapper.insert : ==> Parameters: 1815658607628808194(Long), 379500(Integer), 3(Integer), 1(Long), 1(Integer)
16:02:00:037 DEBUG 39592 --- [nio-8085-exec-4] c.hmall.trade.mapper.OrderMapper.insert : <== Updates: 1
16:02:00:038 DEBUG 39592 --- [nio-8085-exec-4] c.h.t.mapper.OrderDetailMapper.insert : ==> Preparing: INSERT INTO order_detail ( order_id, item_id, num, name, spec, price, image ) VALUES ( ?, ?, ?, ?, ?, ?, ? )
16:02:00:038 DEBUG 39592 --- [nio-8085-exec-4] c.h.t.mapper.OrderDetailMapper.insert : ==> Parameters: 1815658607628808194(Long), 8533120(Long), 1(Integer), 海尔 (Haier )LQ65H31 65英寸 4K曲面人工智能全面屏超高清LED液晶电视(String), {}(String), 379500(Integer), https://m.360buyimg.com/mobilecms/s720x720_jfs/t1/2851/14/13998/101463/5bd9723cE81b2c299/1bfdf2d1628648e4.jpg!q70.jpg.webp(String)
开始清理购物车商品 itemIds的值是[8533120]
16:02:00:040 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] ---> DELETE http://cart-service/carts?ids=8533120 HTTP/1.1
16:02:00:040 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] user-info: 1
16:02:00:040 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] ---> END HTTP (0-byte body)
16:02:00:050 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] <--- HTTP/1.1 200 (9ms)
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] connection: keep-alive
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] content-length: 0
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] date: Tue, 23 Jul 2024 08:02:00 GMT
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] keep-alive: timeout=60
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds]
16:02:00:051 DEBUG 39592 --- [nio-8085-exec-4] com.hmall.api.client.CartClient : [CartClient#deleteCartItemByIds] <--- END HTTP (0-byte body)