spring zuul routes path serviceId 配置方式
1.如果你用的是eclips 切没有安装yml文件缩进提示时,请注意缩进。
2.如果你按照下面方式配置了,并且启动成功之后,请勿立刻进行调用,稍微等待30秒。
立刻调用会报错:
com.netflix.zuul.exception.ZuulException: Forwarding error
Caused by: com.netflix.client.ClientException: null
Caused by: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out..
出现这个错误原因:各个实例在zuul首次注册并不会立刻生效,而是在进行了几次心跳之后才默认为服务器是可调用的,如失败,则需要30s左右, eureka要在service有几次成功的heart beat后才正式服务. warming-up
基本路由配置方式:
1.测试服务
测试接口
@RestController
@RequestMapping("/test")
public class TestController {
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public void hello(){
System.out.println("Hello Word!");
}
}
测试服务yml文件配置
spring:
application:
name: test-cloud-a
profiles:
active: mysql
server:
port: 9000
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8081/eureka
fetch-registry: true
zuul服务配置:
spring:
application:
name: romp-zuul
server:
port: 80
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8081/eureka
fetch-registry: true
zuul:
sensitiveHeaders: "abcd-test"
routes:
romp:
path: /testA/**
serviceId: test-cloud-a
sensitiveHeaders: "abcd-test"
#多个的时候,就直接配置多个,切记缩进
# rompSchedule:
# path: /testB/**
# serviceId: test-cloud-b
# sensitiveHeaders: "abcd-test"
max:
host:
connections: 1000000
host:
maxTotalConnections: 6000000
maxPerRouteConnections: 600000
启动完成,根据配置前端访问路径为:http://localhost:80/testA/test/hello.do