本文共 2441 字,大约阅读时间需要 8 分钟。
pom.xml 配置依赖
org.springframework.cloud spring-cloud-starter-zuul org.springframework.cloud spring-cloud-starter-eureka
配置应用路口 EnableZuulProxy 是组合注解 已经包含 euraka客户端。
@SpringBootApplication@EnableZuulProxypublic class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); }}
配置文件
eureka: client: service-url: defaultZone: http://user:password123@localhost:8761/eureka instance: prefer-ip-address: truehystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000ribbon: ConnectTimeout: 3000 ReadTimeout: 60000
访问注册的应用
http://localhost:8040/microservice-consumer-movie-feign-with-hystrix/movie/1
zuul: routes: microservice-consumer-movie-feign-with-hystrix: /user/**
以下配置表示只代理配置的微服务
zuul: ignoredServices: '*' routes: microservice-consumer-movie-feign-with-hystrix: /user/**
zuul: routes: abc: path: /user-path/** serviceId: microservice-provider-user
不实用euraka 实现负载均衡
ribbon: eureka: enabled: falsemicroservice-provider-user: # 这边是ribbon要请求的微服务的serviceId ribbon: listOfServers: http://localhost:7900,http://localhost:7901
实现安装版本号代理
- zuul入口类中注入 serviceRouteMapper bean
@SpringBootApplication@EnableZuulProxypublic class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); } @Bean public PatternServiceRouteMapper serviceRouteMapper() { return new PatternServiceRouteMapper("(? ^.+)-(? v.+$)", "${version}/${name}"); }}
- 微服服务提供者的appname 中加入版本信息
server: application: name: microservice-provider-user-v1
- 通过zuul访问微服务 localhost:8048/v1/movie/1
zuul: prefix: /api
zuul: prefix: /api strip-prefix: false
解决zuul上传文件超时
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000ribbon: ConnectTimeout: 3000 ReadTimeout: 60000
增加jvm的堆内存
-Xms512M -Xmx1024M
- 使用curl 上传文件
curl -F "file=@test.txt" localhost:8085/upload
转载地址:http://daonn.baihongyu.com/