spring cloud -->zuul(2) 简单路由和跳转路由

一 简单路由

1 使用的类

  SimpleHostRoutingFilter

2 配置连接池

  • zuul.host.maxTotalConnections:目标主机的最大连接数,默认值为200。配置该项,相当于调用了PoolingHttpClientConnectionManager的setMaxTotal方法。
  • zuul.host.maxPerRouteConnections:每个主机的初始连接数,默认值为20。配置该项,相当于调用了PoolingHttpClientConnectionManager的setDefaultMaxPerRoute方法。

3 简单路径配置

server:
  port: 9000
spring:
  application:
    name: spring-zuul-gateway
zuul:
  routes:
    routeTest:
      path: /routeTest/163
      url: http://www.163.com/
    #route163相对于path
    route163:
      url: http://www.163.com/

  

4 测试

  输入:localhost:9000/routeTest/163,进入163网站

5 测试

  输入:localhost:9000/route163,进入163网站

二 跳转路由

1 使用的类

  SendForwardFilter

2 跳转路由配置

zuul:
  routes:
 
    helloRoute:
      path: /test/**
      url: forward:/source/hello
#注意url中的关键字forward

3 新建控制器类

package org.crazyit.cloud;
 
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class TestController {
 
    @RequestMapping(value = "/source/hello/{name}", method = RequestMethod.GET)
    public String hello(@PathVariable("name") String name) {
        return "hello " + name;
    }
}  

4 测试

  浏览器输入:localhost:9000/test/cakin

 原文连接:

  https://blog.csdn.net/chengqiuming/article/details/81264061

原文地址:https://www.cnblogs.com/little-tech/p/13691545.html