<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>技术、投资、生活</title>
    <description>技术、投资、生活</description>
    <link>https://scnuwang.github.io/</link>
    <atom:link href="https://scnuwang.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 30 Jun 2019 11:20:58 +0000</pubDate>
    <lastBuildDate>Sun, 30 Jun 2019 11:20:58 +0000</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>财报那些事之货币资金</title>
        <description>&lt;p&gt;文章内容是微信公众号【搬砖小组】（以前的摸鱼小组）的财报那些事的笔记。&lt;/p&gt;

&lt;p&gt;财务分析三张表：资产负债表、利润表、现金流量表。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;资产软，负债硬，现金为王。&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;定义&quot;&gt;定义&lt;/h3&gt;

&lt;p&gt;货币资金：简单理解就是上市公司&lt;strong&gt;账面&lt;/strong&gt;上的&lt;strong&gt;钱&lt;/strong&gt;。具体来说，货币资金包括了库存现金、银行存款和其他货币资金。其中其他货币资金是个大坑，它就像水中月，镜中花，看得见，可惜用不了。&lt;/p&gt;

&lt;h3 id=&quot;火眼金睛&quot;&gt;火眼金睛&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;观察资产端和负债端是否存在&lt;strong&gt;大存大贷&lt;/strong&gt;的情况。一边有很多存款，一边又在大量贷款。如果一家公司同时有大量存款，和大量贷款，但是利息收入远小于利息支出，那么存款里面的资金就有可能有问题。&lt;/li&gt;
  &lt;li&gt;股权质押、所有权或者使用权受限的资产情况。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;注：国资控股的上司公司，他们的利息收入低，主要是受体制约束，账上即便有大量现金也不能随便动用，所以投资行为比较少，资金使用率低。&lt;/p&gt;

&lt;h3 id=&quot;避雷针&quot;&gt;避雷针&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;钱少的公司存在强烈的虚增资金的风险。&lt;/li&gt;
  &lt;li&gt;永久拉黑货币资金造假的公司。&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Sun, 30 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E8%B4%A7%E5%B8%81%E8%B5%84%E9%87%91.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E8%B4%A7%E5%B8%81%E8%B5%84%E9%87%91.html</guid>
        
        <category>财务分析</category>
        
        <category>货币资金</category>
        
        
        <category>财务分析</category>
        
      </item>
    
      <item>
        <title>财报那些事之应收款项</title>
        <description>&lt;p&gt;文章内容是微信公众号【搬砖小组】（以前的摸鱼小组）的财报那些事的笔记。&lt;/p&gt;

&lt;p&gt;财务分析三张表：资产负债表、利润表、现金流量表。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;资产软，负债硬，现金为王。&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;基础知识&quot;&gt;基础知识&lt;/h3&gt;

&lt;p&gt;学名：贷款与应收款项。记录的是当期已经产生，但是还没收到的收入，是赊销产生的债权。&lt;/p&gt;

&lt;p&gt;是一项资产，也有可能是坏账，看得见，不一定摸得着，因为不排除说没就没的可能性，要是收不回来就计提坏账。&lt;/p&gt;

&lt;p&gt;常见的三个科目：应收账款、应收利息、其他应收款。&lt;/p&gt;

&lt;p&gt;财务上的每一个科目背后都有商业上的意义，应收款项也不例外。&lt;/p&gt;

&lt;h3 id=&quot;特点&quot;&gt;特点&lt;/h3&gt;

&lt;p&gt;资产软&lt;/p&gt;

&lt;h3 id=&quot;火眼金睛&quot;&gt;火眼金睛&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;应收账款高，说明公司的高业绩，大多由未到账的收入构成，存在风险&lt;/li&gt;
  &lt;li&gt;股权质押、所有权或者使用权受限的资产情况。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;注：国资控股的上司公司，他们的利息收入低，主要是受体制约束，账上即便有大量现金也不能随便动用，所以投资行为比较少，资金使用率低。&lt;/p&gt;

&lt;h3 id=&quot;避雷针&quot;&gt;避雷针&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;资产软，负债硬，现金为王&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Sun, 30 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E5%BA%94%E6%94%B6%E6%AC%BE%E9%A1%B9.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E5%BA%94%E6%94%B6%E6%AC%BE%E9%A1%B9.html</guid>
        
        <category>财务分析</category>
        
        <category>应收款项</category>
        
        
        <category>财务分析</category>
        
      </item>
    
      <item>
        <title>财报那些事之存货</title>
        <description>&lt;p&gt;文章内容是微信公众号【搬砖小组】（以前的摸鱼小组）的财报那些事的笔记。&lt;/p&gt;

&lt;p&gt;财务分析三张表：资产负债表、利润表、现金流量表。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;资产软，负债硬，现金为王。&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;基础知识&quot;&gt;基础知识&lt;/h3&gt;

&lt;p&gt;存货属于资产，大致可以分成原材料，在产品，产成品。&lt;/p&gt;

&lt;p&gt;原材料：仓库里的铜，钢铁。&lt;/p&gt;

&lt;p&gt;在产品：造了一半的冰箱。&lt;/p&gt;

&lt;p&gt;产成品：仓库里还没有卖出去的冰箱。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;存货要考虑资产的跌价减值&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;是一项资产，也有可能是坏账，看得见，不一定摸得着，因为不排除说没就没的可能性，要是收不回来就计提坏账。&lt;/p&gt;

&lt;p&gt;常见的三个科目：应收账款、应收利息、其他应收款。&lt;/p&gt;

&lt;p&gt;财务上的每一个科目背后都有商业上的意义，应收款项也不例外。&lt;/p&gt;

&lt;h3 id=&quot;特点&quot;&gt;特点&lt;/h3&gt;

&lt;p&gt;属于资产，，但是现在还没有给上市公司挣到钱。&lt;/p&gt;

&lt;p&gt;重点是：它将来可能会给公司挣到钱。&lt;/p&gt;

&lt;h3 id=&quot;火眼金睛&quot;&gt;火眼金睛&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;存货的属性是什么，随着时间的消逝存货会怎样变化。如：钢铁生锈，中药材药性降低，罐头过期等等。&lt;/li&gt;
  &lt;li&gt;存货经常不翼而飞，獐子岛的扇贝，康美的中药材。&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;避雷针&quot;&gt;避雷针&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;资产软，负债硬，现金为王&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Sun, 30 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E5%AD%98%E8%B4%A7.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/2019/06/30/%E5%AD%98%E8%B4%A7.html</guid>
        
        <category>财务分析</category>
        
        <category>存货</category>
        
        
        <category>财务分析</category>
        
      </item>
    
      <item>
        <title>Nacos初体验</title>
        <description>&lt;p&gt;本文主要根据官方示例，初步了解Nacos，再思考一下，与Eureka的不同点和相同点。&lt;/p&gt;

&lt;h3 id=&quot;下载&quot;&gt;下载&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/alibaba/nacos/releases&quot;&gt;Nacos Server下载地址&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/nacos-group/nacos-examples&quot;&gt;官方示例地址&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;启动nacos-server&quot;&gt;启动Nacos Server&lt;/h3&gt;

&lt;p&gt;Windows环境：解压之后，&lt;code class=&quot;highlighter-rouge&quot;&gt;D:\nacos\bin&lt;/code&gt;目录下，双击&lt;code class=&quot;highlighter-rouge&quot;&gt;startup.cmd&lt;/code&gt;运行文件&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：环境变量里面一定要配置MAVEN_HOME和JAVA_HOME，否则双击之后，一闪而过。&lt;/p&gt;

&lt;p&gt;正常启动：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561736503901.png&quot; alt=&quot;1561736503901&quot; /&gt;&lt;/p&gt;

&lt;p&gt;访问&lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost:8848/nacos/index.html&lt;/code&gt;,即可看到如下界面：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../../assets/images/1561737919628.png&quot; alt=&quot;1561737919628&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;发布配置&quot;&gt;发布配置&lt;/h3&gt;

&lt;p&gt;使用PostMan工具发送请求&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561737071374.png&quot; alt=&quot;1561737071374&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;验证配置是否发布成功&quot;&gt;验证配置是否发布成功&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;启动nacos-spring-cloud-config-example&lt;/li&gt;
  &lt;li&gt;获取配置：&lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost:8080/config/get&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561736937484.png&quot; alt=&quot;1561736937484&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;再次修改配置：&lt;code class=&quot;highlighter-rouge&quot;&gt;curl -X POST &quot;http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=example.properties&amp;amp;group=DEFAULT_GROUP&amp;amp;content=useLocalCache=false&quot;&lt;/code&gt;将useLocalCache的值修改为false&lt;/li&gt;
  &lt;li&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561737006341.png&quot; alt=&quot;1561737006341&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;再次获取配置：&lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost:8080/config/get&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561737141987.png&quot; alt=&quot;1561737141987&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;返回false说明设置的值，动态生效了。&lt;/p&gt;

&lt;p&gt;也可以直接去nacos的控制台查看：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561738023067.png&quot; alt=&quot;1561738023067&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;服务注册与发现&quot;&gt;服务注册与发现&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;下载示例消费者和生成者代码&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;示例代码已配置好注册中心的地址：&lt;code class=&quot;highlighter-rouge&quot;&gt;spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;启动消费者和生产者，可以在控制台看到已经注册到注册中心了。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561738486576.png&quot; alt=&quot;1561738486576&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;服务调用&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/1561738659879.png&quot; alt=&quot;1561738659879&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;可以看到，通过&lt;code class=&quot;highlighter-rouge&quot;&gt;@LoadBalanced&lt;/code&gt;注解，结合Ribbon实现负载均衡，通过生产者的服务名调用接口。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;与eureka对比&quot;&gt;与Eureka对比&lt;/h3&gt;

&lt;p&gt;初次使用，总结肯定不够完善，后面慢慢的做更加详细的对比。&lt;/p&gt;

&lt;h4 id=&quot;相同点&quot;&gt;相同点&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;支持Ribbon结合&lt;code class=&quot;highlighter-rouge&quot;&gt;@LoadBalanced&lt;/code&gt;注解，实现负载均衡&lt;/li&gt;
  &lt;li&gt;都有一个控制台&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;不同点&quot;&gt;不同点&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;官方的下载包可直接启动，不需要自己再创建项目启动。&lt;/li&gt;
  &lt;li&gt;Nacos的控制台，功能更加完善丰富，可直接动态配置，Eureka的控制台只能算是一个看板。&lt;/li&gt;
  &lt;li&gt;Nacos支持通过OPENAPI的方式，动态注册，这种有点类似ZK的注册方式&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Fri, 28 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/nacos/2019/06/28/Nacos%E5%88%9D%E4%BD%93%E9%AA%8C.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/nacos/2019/06/28/Nacos%E5%88%9D%E4%BD%93%E9%AA%8C.html</guid>
        
        <category>Nacos</category>
        
        <category>注册中心</category>
        
        
        <category>Nacos</category>
        
      </item>
    
      <item>
        <title>Sentinel默认限流方式？</title>
        <description>&lt;p&gt;与SpringCloudGateway整合后，明明没有进行热点参数限流，为什么返回的是&lt;code class=&quot;highlighter-rouge&quot;&gt;Blocked by Sentinel: ParamFlowException&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;花了几个小时，一直以为应该返回的是&lt;code class=&quot;highlighter-rouge&quot;&gt;Blocked by Sentinel: FlowException&lt;/code&gt;，结果看到&lt;a href=&quot;https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81&quot;&gt;网关限流&lt;/a&gt;的最后，才看到官方文档如下描述：&lt;/p&gt;

&lt;blockquote&gt;
  &lt;h2 id=&quot;网关流控实现原理&quot;&gt;网关流控实现原理&lt;/h2&gt;

  &lt;p&gt;当通过 &lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayRuleManager&lt;/code&gt; 加载网关流控规则（&lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayFlowRule&lt;/code&gt;）时，无论是否针对请求属性进行限流，Sentinel 底层都会将网关流控规则转化为热点参数规则（&lt;code class=&quot;highlighter-rouge&quot;&gt;ParamFlowRule&lt;/code&gt;），存储在 &lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayRuleManager&lt;/code&gt; 中，与正常的热点参数规则相隔离。转换时 Sentinel 会根据请求属性配置，为网关流控规则设置参数索引（&lt;code class=&quot;highlighter-rouge&quot;&gt;idx&lt;/code&gt;），并同步到生成的热点参数规则中。&lt;/p&gt;

  &lt;p&gt;外部请求进入 API Gateway 时会经过 Sentinel 实现的 filter，其中会依次进行 &lt;strong&gt;路由/API 分组匹配&lt;/strong&gt;、&lt;strong&gt;请求属性解析&lt;/strong&gt;和&lt;strong&gt;参数组装&lt;/strong&gt;。Sentinel 会根据配置的网关流控规则来解析请求属性，并依照参数索引顺序组装参数数组，最终传入 &lt;code class=&quot;highlighter-rouge&quot;&gt;SphU.entry(res, args)&lt;/code&gt; 中。Sentinel API Gateway Adapter Common 模块向 Slot Chain 中添加了一个 &lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayFlowSlot&lt;/code&gt;，专门用来做网关规则的检查。&lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayFlowSlot&lt;/code&gt; 会从 &lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayRuleManager&lt;/code&gt; 中提取生成的热点参数规则，根据传入的参数依次进行规则检查。若某条规则不针对请求属性，则会在参数最后一个位置置入预设的常量，达到普通流控的效果。&lt;/p&gt;

  &lt;p&gt;&lt;img src=&quot;https://github.com/ScnuWang/ScnuWang.github.io/assets/images/58381786-5406f280-7ff4-11e9-9020-016ccaf7ab7d.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;为什么不在代码里面&lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayRuleManager.loadRules(rules);&lt;/code&gt;通过Sentinel控制台添加流控规则，返回的就是&lt;code class=&quot;highlighter-rouge&quot;&gt;{&quot;code&quot;:429,&quot;message&quot;:&quot;Blocked by Sentinel: FlowException&quot;}&lt;/code&gt;?&lt;/p&gt;
</description>
        <pubDate>Mon, 24 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/sentinel/2019/06/24/ParamBlockException.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/sentinel/2019/06/24/ParamBlockException.html</guid>
        
        <category>Sentinel</category>
        
        <category>降级限流</category>
        
        
        <category>Sentinel</category>
        
      </item>
    
      <item>
        <title>GatewayFlowRule类解析</title>
        <description>&lt;h3 id=&quot;字段属性&quot;&gt;字段属性&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 资源名，即限流规则的作用对象&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 默认值为路由Id，也可以是自定义API的名称&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resourceMode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SentinelGatewayConstants&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;RESOURCE_MODE_ROUTE_ID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 限流阈值类型（QPS或者并非线程数）,默认为QPS&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grade&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RuleConstant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;FLOW_GRADE_QPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 限流阈值&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 统计时间窗口，单位是秒，默认是 1 秒。&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intervalSec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 流量控制模式，默认为直接拒绝，还有Warm Up(预热/冷启动方式)、匀速器模式&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controlBehavior&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RuleConstant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CONTROL_BEHAVIOR_DEFAULT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 应对突发请求时额外允许的请求数目。&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;burst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 匀速排队模式下的最长排队时间，单位是毫秒，仅在匀速排队模式下生效。&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxQueueingTimeoutMs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 用于参数流量控制。如果未设置，网关规则将转换为正常流规则。&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GatewayParamFlowItem&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;paramItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;构造方法&quot;&gt;构造方法&lt;/h3&gt;

&lt;p&gt;包含一个无参构造方法和一个包含资源名称的构造方法。&lt;/p&gt;

&lt;h3 id=&quot;普通方法&quot;&gt;普通方法&lt;/h3&gt;

&lt;p&gt;只有getter,setter,equal,toString等&lt;/p&gt;

&lt;h3 id=&quot;综上&quot;&gt;综上&lt;/h3&gt;

&lt;p&gt;一个普通的类，主要是封装限流的属性，方便使用。&lt;/p&gt;

&lt;p&gt;网关默认限流规则：默认是对以路由Id作为资源名称,通过统计QPS的阈值，采取直接拒绝的方式进行限流。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：如果需要对参数进行限流的时候，才为GatewayParamFlowItem赋值。&lt;/p&gt;
</description>
        <pubDate>Mon, 24 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/24/GatewayFlowRule.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/24/GatewayFlowRule.html</guid>
        
        <category>Spring Cloud Gateway</category>
        
        <category>网关</category>
        
        
        <category>Spring Cloud Gateway</category>
        
      </item>
    
      <item>
        <title>Spring Cloud Gateway官方文档笔记(二)</title>
        <description>&lt;p&gt;继续上一篇：本篇笔记主要是Predicate相关的内容&lt;/p&gt;

&lt;h3 id=&quot;四路由断言工厂&quot;&gt;四、路由断言工厂&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;将路由作为&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring WebFlux HandlerMapping&lt;/code&gt;基础结构的一部分进行匹配。 &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;包含许多内置的&lt;code class=&quot;highlighter-rouge&quot;&gt;Route Predicate Factory&lt;/code&gt;。所有这些谓Predication都匹配HTTP请求的不同属性。多个Precation工厂可以组合并通过逻辑&lt;code class=&quot;highlighter-rouge&quot;&gt;and&lt;/code&gt;组合。&lt;/p&gt;

&lt;h4 id=&quot;1-after-route-predicate-factory&quot;&gt;1. After Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;可以构建在某个指定时间之后生效的路由。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;after_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;After=2017-01-20T17:42:47.789-07:00[America/Denver]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-before-route-predicate-factory&quot;&gt;2. Before Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;和上面的相反，可以构建在某个指定时间之前有效的路由。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;before_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Before=2017-01-20T17:42:47.789-07:00[America/Denver]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;3-between-route-predicate-factory&quot;&gt;3. Between Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;可以构建在某个指定的时间段内的路由&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;between_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;4-cookie-route-predicate-factory&quot;&gt;4. Cookie Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;根据Cookie里面是否包含指定的&lt;code class=&quot;highlighter-rouge&quot;&gt;Key--Value&lt;/code&gt;构建路由，支持正则表达式&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;cookie_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Cookie=chocolate, ch.p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;5-header-route-predicate-factory&quot;&gt;5. Header Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;根据请求头里是否包含指定的&lt;code class=&quot;highlighter-rouge&quot;&gt;Key--Value&lt;/code&gt;构建路由，支持正则表达式&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;header_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Header=X-Request-Id, \d+&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;6-host-route-predicate-factory&quot;&gt;6. Host Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;根据请求头里的Host构建路由，该模式是一种Ant样式模式&lt;code class=&quot;highlighter-rouge&quot;&gt;.&lt;/code&gt;作为分隔符，支持正则表达式，也支持URI模板变量，例如{sub} .myhost.org。 如果请求的主机头具有值&lt;code class=&quot;highlighter-rouge&quot;&gt;www.somehost.org&lt;/code&gt;或&lt;code class=&quot;highlighter-rouge&quot;&gt;beta.somehost.org&lt;/code&gt;或&lt;code class=&quot;highlighter-rouge&quot;&gt;www.anotherhost.org&lt;/code&gt;，则此路由将匹配。 此Predicate将URI模板变量（如上例中定义的sub）提取为名称和值的映射，并将其放在&lt;code class=&quot;highlighter-rouge&quot;&gt;ServerWebExchange.getAttributes（）&lt;/code&gt;中，并在&lt;code class=&quot;highlighter-rouge&quot;&gt;ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE&lt;/code&gt;中定义一个键。然后，这些值可供&lt;code class=&quot;highlighter-rouge&quot;&gt;GatewayFilter Factories&lt;/code&gt;使用。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;host_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Host=**.somehost.org,**.anotherhost.org&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;7-method-route-predicate-factory&quot;&gt;7. Method Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;根据请求方法构建路由。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;method_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Method=GET&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;8-path-route-predicate-factory&quot;&gt;8. Path Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;根据请求路径构建路由。路径里面可以取模板变量，其他的工厂也可以使用。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;host_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Path=/foo/{segment},/bar/{segment}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;此谓词将URI模板变量（如上例中定义的&lt;code class=&quot;highlighter-rouge&quot;&gt;segment&lt;/code&gt;）提取为name和value的map，并将其放在&lt;code class=&quot;highlighter-rouge&quot;&gt;ServerWebExchange.getAttributes（）&lt;/code&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;中，并在ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE中定义一个键。然后，这些值可供&lt;/code&gt;GatewayFilter Factories`使用.&lt;/p&gt;

&lt;h4 id=&quot;9-query-route-predicate-factory&quot;&gt;9. Query Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;如果配置一个参数，则可以构建根据请求体里面包含某个参数的路由；如果有两个参数则认为是一个键值对，即可以构建请求体中包含某个键值对的路由。&lt;/p&gt;

&lt;p&gt;示例：请求中包含参数&lt;code class=&quot;highlighter-rouge&quot;&gt;baz&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;query_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Query=baz&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;示例：请求体中包含&lt;code class=&quot;highlighter-rouge&quot;&gt;foo&lt;/code&gt;的值满足正则表达式&lt;code class=&quot;highlighter-rouge&quot;&gt;ba.&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;query_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Query=foo, ba.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;10-remoteaddr-route-predicate-factory&quot;&gt;10. RemoteAddr Route Predicate Factory&lt;/h4&gt;

&lt;p&gt;采用CIDR表示法（IPv4或IPv6）字符串的列表（最小值为1），例如， &lt;code class=&quot;highlighter-rouge&quot;&gt;192.168.0.1/16&lt;/code&gt;（其中&lt;code class=&quot;highlighter-rouge&quot;&gt;192.168.0.1&lt;/code&gt;是IP地址，16是子网掩码）。&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;remoteaddr_route&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.org&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;predicates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;RemoteAddr=192.168.1.1/24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：默认情况下，&lt;code class=&quot;highlighter-rouge&quot;&gt;RemoteAddr Route Predicate Factory&lt;/code&gt;使用传入请求中的远程地址。如果Spring Cloud Gateway位于代理层后面，则可能与实际客户端IP地址不匹配。&lt;/p&gt;

&lt;p&gt;您可以通过设置自定义&lt;code class=&quot;highlighter-rouge&quot;&gt;RemoteAddressResolver&lt;/code&gt;来自定义解析远程地址的方式。 &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;附带一个非默认远程地址解析器，它基于&lt;code class=&quot;highlighter-rouge&quot;&gt;X-Forwarded-For&lt;/code&gt;标头&lt;code class=&quot;highlighter-rouge&quot;&gt;XForwardedRemoteAddressResolver&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;XForwardedRemoteAddressResolver&lt;/code&gt;有两个静态构造函数方法，它们采用不同的安全方法：&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;XForwardedRemoteAddressResolver :: trustAll&lt;/code&gt;返回一个&lt;code class=&quot;highlighter-rouge&quot;&gt;RemoteAddressResolver&lt;/code&gt;，它始终采用&lt;code class=&quot;highlighter-rouge&quot;&gt;X-Forwarded-For&lt;/code&gt;标头中找到的第一个IP地址。这种方法容易受到欺骗，因为恶意客户端可以初始化一个可以解析器接受的&lt;code class=&quot;highlighter-rouge&quot;&gt;X-Forwarded-For&lt;/code&gt;的值。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;XForwardedRemoteAddressResolver :: maxTrustedIndex&lt;/code&gt;采用与&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;前运行的可信基础架构数相关的索引。例如，如果只能通过HAProxy访问&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;，则应使用值1。如果在可访问&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;之前需要两跳可信基础架构，则应使用值2。&lt;/p&gt;

&lt;p&gt;示例：&lt;/p&gt;

&lt;p&gt;请求头的方式：&lt;code class=&quot;highlighter-rouge&quot;&gt;X-Forwarded-For: 0.0.0.1, 0.0.0.2, 0.0.0.3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;下面的maxTrustedIndex值将产生以下远程地址。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;maxTrustedIndex&lt;/code&gt;&lt;/th&gt;
      &lt;th&gt;result&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;[&lt;code class=&quot;highlighter-rouge&quot;&gt;Integer.MIN_VALUE&lt;/code&gt;,0]&lt;/td&gt;
      &lt;td&gt;(invalid, &lt;code class=&quot;highlighter-rouge&quot;&gt;IllegalArgumentException&lt;/code&gt; during initialization)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;0.0.0.3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;0.0.0.2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;0.0.0.1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;[4, &lt;code class=&quot;highlighter-rouge&quot;&gt;Integer.MAX_VALUE&lt;/code&gt;]&lt;/td&gt;
      &lt;td&gt;0.0.0.1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;使用配置类的方式：&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RemoteAddressResolver resolver = XForwardedRemoteAddressResolver
    .maxTrustedIndex(1);

...

.route(&quot;direct-route&quot;,
    r -&amp;gt; r.remoteAddr(&quot;10.1.1.1&quot;, &quot;10.10.1.1/24&quot;)
        .uri(&quot;https://downstream1&quot;)
.route(&quot;proxied-route&quot;,
    r -&amp;gt; r.remoteAddr(resolver,  &quot;10.10.1.1&quot;, &quot;10.10.1.1/24&quot;)
        .uri(&quot;https://downstream2&quot;)
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Mon, 17 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/17/SpringCloudGateway%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A302.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/17/SpringCloudGateway%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A302.html</guid>
        
        <category>Spring Cloud Gateway</category>
        
        <category>网关</category>
        
        
        <category>Spring Cloud Gateway</category>
        
      </item>
    
      <item>
        <title>Spring Cloud Gateway官方文档笔记(一)</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.1.0.RELEASE/single/spring-cloud-gateway.html&quot;&gt;官方文档&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;官方文档的内容不算很多，花点时间应该很多可以看完。&lt;/p&gt;

&lt;h3 id=&quot;一引入依赖&quot;&gt;一、引入依赖&lt;/h3&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.cloud&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-cloud-starter-gateway&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果引入了包，但是又不想让Gateway生效，可以通过在application.properties中添加：&lt;code class=&quot;highlighter-rouge&quot;&gt;spring.cloud.gateway.enabled=false&lt;/code&gt;来禁用。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;需要&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Boot&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Webflux&lt;/code&gt;提供的Netty运行时。它不能在传统的Servlet容器中工作或构建为WAR。&lt;/p&gt;

&lt;h3 id=&quot;二关键词&quot;&gt;二、关键词&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Route&lt;/strong&gt;（路由）：Route是网关的基础。根据路由编号，目标地址（请求转发到哪里去），一系列的断言（Predicate）和一系列的过滤器（Filter）来最终确定一个路由。如果一系列的断言都为真，那么路由就匹配了。&lt;/p&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;&lt;strong&gt;疑问：过滤器不用考虑吗？&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Predicate&lt;/strong&gt;（断言）：这个是Java8 的一个新类。据我现在了解的，它的功能如下：&lt;/p&gt;

&lt;p&gt;第一：根据输入判断是否与既定的规则匹配，要是匹配就返回True,否则返回false。&lt;/p&gt;

&lt;p&gt;第二：对输入的规则进行操作：合并规则、规则取非、规则取并。&lt;/p&gt;

&lt;p&gt;第三：根据规则判断两个参数是否一致。&lt;/p&gt;

&lt;p&gt;以上表述应该不够准确，后续再来修改。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filter&lt;/strong&gt;（过滤器）：这里的过滤器都是指&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Framework GatewayFilter&lt;/code&gt;的实例，可以在发送下游请求之前或之后修改请求和响应。&lt;/p&gt;

&lt;h3 id=&quot;三工作流程&quot;&gt;三、工作流程&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://scnuWang.github.io/assets/images/1560700380417.png&quot; alt=&quot;1560700380417&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Gateway Handler Mapping&lt;/code&gt;根据Predicate确定要转发到哪里去，&lt;code class=&quot;highlighter-rouge&quot;&gt;Gateway Web Handler&lt;/code&gt;让请求通过过滤器链，根据执行结果判断是否要继续下发，已经对下发之前的请求和下发之后的响应进行处理。我个人觉得到了这一步，一句话概括就是&lt;strong&gt;再一次确认要不要转发，怎么转发，转发后怎么处理响应。&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：在没有端口的路由中定义的URI将分别为HTTP和HTTPS URI获取默认端口设置为80和443。&lt;/p&gt;
</description>
        <pubDate>Sun, 16 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/16/SpringCloudGateway%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A301.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/spring%20cloud%20gateway/2019/06/16/SpringCloudGateway%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A301.html</guid>
        
        <category>Spring Cloud Gateway</category>
        
        <category>网关</category>
        
        
        <category>Spring Cloud Gateway</category>
        
      </item>
    
      <item>
        <title>Java 响应式编程基础</title>
        <description>&lt;p&gt;最近在搭建一个内网网关的时候，使用到&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Cloud Gateway&lt;/code&gt;，之前没用过，了解之后才发现，这个底层依赖的&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring WebFlux&lt;/code&gt;，以&lt;code class=&quot;highlighter-rouge&quot;&gt;Project Reactor&lt;/code&gt;作为底层响应式框架，但是自己对响应式编程却很陌生，所以决定花点时间学习一下这块的内容。&lt;/p&gt;

&lt;p&gt;网上搜很久，发现这块的资料不是很多，没有找到系列的分享资料，可能是没有找到，所以还是决定使用官网的文档来进行学习。&lt;/p&gt;

&lt;p&gt;Java响应式编程基础&lt;/p&gt;

&lt;p&gt;涉及的关键字包含：Flow 、Predicate、Runnable 、Supplier&lt;/p&gt;

</description>
        <pubDate>Sat, 15 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/java%E5%9F%BA%E7%A1%80/2019/06/15/%E5%93%8D%E5%BA%94%E5%BC%8F%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/java%E5%9F%BA%E7%A1%80/2019/06/15/%E5%93%8D%E5%BA%94%E5%BC%8F%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80.html</guid>
        
        <category>响应式编程</category>
        
        
        <category>Java基础</category>
        
      </item>
    
      <item>
        <title>2019年中计划</title>
        <description>&lt;h3 id=&quot;技术&quot;&gt;技术&lt;/h3&gt;

&lt;h4 id=&quot;java基础&quot;&gt;Java基础&lt;/h4&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;响应式编程&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;基础算法与数据结构（尚硅谷视频）&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;源码分析&quot;&gt;源码分析&lt;/h4&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Spring源码分析&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Eureka源码分析&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Sentinel源码分析&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;系统结构&quot;&gt;系统结构&lt;/h4&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;网关系统架构&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;投资&quot;&gt;投资&lt;/h3&gt;
</description>
        <pubDate>Sun, 09 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://scnuwang.github.io/%E8%A7%84%E5%88%92/2019/06/09/%E5%B9%B4%E4%B8%AD%E8%AE%A1%E5%88%92.html</link>
        <guid isPermaLink="true">https://scnuwang.github.io/%E8%A7%84%E5%88%92/2019/06/09/%E5%B9%B4%E4%B8%AD%E8%AE%A1%E5%88%92.html</guid>
        
        <category>规划</category>
        
        
        <category>规划</category>
        
      </item>
    
  </channel>
</rss>
