0%

首先开启gateway debug日志,可以看到:

debug

debug日志中是可以打印请求所命中的路由id的,Route matched: hello-route

然后我在想怎么在程序中获取到这个id呢?因为如果在程序中可以获取到这个id,我就可以按统计每个路由所被访问的次数。网上找了一些博客,都没有提到这个问题,所以只能自己想了。

首先我从打印日志的类开始搜,打开源码RoutePredicateHandlerMapping,找到打印日志的代码。

protected Mono<?> getHandlerInternal(ServerWebExchange exchange) {
    if (this.managmentPort != null && exchange.getRequest().getURI().getPort() == this.managmentPort) {
        return Mono.empty();
    } else {
        exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_HANDLER_MAPPER_ATTR, this.getSimpleName());
        return this.lookupRoute(exchange).flatMap((r) -> {
            exchange.getAttributes().remove(ServerWebExchangeUtils.GATEWAY_PREDICATE_ROUTE_ATTR);
            if (this.logger.isDebugEnabled()) {
                // 可以看到这里对应的r就是我们要获取的路由。因为从打印的日志中可以看出
                this.logger.debug("Mapping [" + this.getExchangeDesc(exchange) + "] to " + r);
            }

            exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR, r);
            return Mono.just(this.webHandler);
        }).switchIfEmpty(Mono.empty().then(Mono.fromRunnable(() -> {
            exchange.getAttributes().remove(ServerWebExchangeUtils.GATEWAY_PREDICATE_ROUTE_ATTR);
            if (this.logger.isTraceEnabled()) {
                this.logger.trace("No RouteDefinition found for [" + this.getExchangeDesc(exchange) + "]");
            }

        })));
    }
}
Route{id='hello-route', uri=http://127.0.0.1:8763, order=0, predicate=org.springframework........

我们只要获取到这个Route对象就可以了。那么源码中这个对象放哪儿了呢?

exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR, r);

所以我们只需要在exchange中根据ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR,这个keyAttributes获取就可以了。

下面编写一个Global Filter试试吧。

public class GatewayLogFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        Route route = (Route) exchange.getAttributes().get(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);
        System.out.println(route.getId());
        return chain.filter(exchange);
    }

}

安装git

git -v

安装nodejs

node -v
npm -v
npm config set registry https://registry.npm.taobao.org

安装hexo

npm install -g hexo-cli
hexo init MyBlog
cd MyBlog      //进入这个MyBlog文件夹
npm install

生成SSH添加到GitHub

详细的百度~

git config --global user.name "yourname"
git config --global user.email "youremail"

安装一些插件

上传到GitHub上需要的插件

npm install hexo-deployer-git --save

matery主题需要的插件

npm i -S hexo-prism-plugin
npm install hexo-generator-search --save
npm i hexo-permalink-pinyin --save
npm i --save hexo-wordcount
npm install hexo-filter-github-emojis --save
npm install hexo-generator-feed --save

SpringCloud 2.0.0版本以前,只要加入下面依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

并且在类上,变量上打上@RefreshScope的注解,在启动的时候,都会看到

RequestMappingHandlerMapping : Mapped "{/refresh,methods=[post]}" 

也就是SpringCloud暴露了一个接口 /refresh 来给我们去刷新配置,但是SpringCloud 2.0.0以后,有了改变.
我们需要在bootstrap.yml里面加上需要暴露出来的地址

management:
  endpoints:
    web:
      exposure:
        include: refresh,health

现在的地址也不是/refresh了,而是/actuator/refresh

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment

命令 说明
CTRL +SHIFT + A 查找快捷键 –>HELP–>FIND ACTION move caret to,move caret to next world 快速到单词的末尾,ctrl+ →, 同时按住shift 就是选中这个单词
CTRL +SHIFT+ALT +J 选中一样的 –>EDIT –>FIND SELECT ALL OCCURRENCES
SHIFT + ALT + 鼠标左键 选中多行
END键 快速移到行尾
HOME键 快速移到行首
CTRL+ALT + L 格式化 –>code –>reformat code
Ctrl+alt+I 自动缩进
ctrl+ shift +U 字母大小写切换
ctrl+alt+t surround with ,if else, try catch,…
ctrl +shift + t 创建新的测试
alt + insert generate 生成getter and setter,constructor,toString…
ctrl+y / x 删除行
ctrl + D 复制行
ctrl + H 显示类结构图
ctrl+ shift + h 显示方法调用结构
Alt+7 显示类所有方法,快速定位
ctrl + E 显示最近打开的文件
ctrl +j 自动补全代码 fori psvm sout …
ctrl + w 选中代码,多次按,逐渐扩大选中范围
alt+f3 / ctrl+shift + f7 高亮显示文本
ctrl+/ / ctrl+shift+/ 注释// 或者注释/*
ctrl + Alt + o 优化导入的包
ctrl + p 显示方法参数提醒

注意有时候快捷键不生效,是不是和QQ钉钉等常用软件冲突导致。