概述
通过Zuul上传文件
通过Zuul上传文件
在microservice-file-upload工程中添加static/index_zuul.html页面
File to upload:
说明:
1)action默认指向/microservice-file-upload/upload;
上传异常
异常com.netflix.zuul.exception.ZuulException-TIMEOUT
处理方法:
spring:application:name: microservice-gateway-zuul
server:port: 8040
eureka:client:service-url:defaultZone: http://user:password123@localhost:8761/eurekainstance:prefer-ip-address: true#zuul:
# prefix: /simple
# strip-prefix: false# 上传大文件得将超时时间设置长一些,否则会报超时异常。以下几行超时设置来自http://cloud.spring.io/spring-cloud-static/Camden.SR3/#_uploading_files_through_zuul
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
logging:level:com.netflix: DEBUG
说明:
1)修改zuul配置,hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000;
2)上面的值也可以按需设置;
异常com.netflix.zuul.exception.ZuulException-GENERAL
处理方式
spring:application:name: microservice-gateway-zuul
server:port: 8040
eureka:client:service-url:defaultZone: http://user:password123@localhost:8761/eurekainstance:prefer-ip-address: true#zuul:
# prefix: /simple
# strip-prefix: falsezuul:host:connect-timeout-millis: 120000socket-timeout-millis: 120000
# 上传大文件得将超时时间设置长一些,否则会报超时异常。以下几行超时设置来自http://cloud.spring.io/spring-cloud-static/Camden.SR3/#_uploading_files_through_zuul
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 120000ribbon:ReadTimeout: 120000ConnectTimeout: 120000logging:level:com.netflix: DEBUG
说明:
加上配置
ribbon:ReadTimeout: 120000ConnectTimeout: 120000
和
zuul:host:connect-timeout-millis: 120000socket-timeout-millis: 120000
测试
1)查看注册的服务
2)通过Zuul访问上传面
http://192.168.1.102:8040/microservice-file-upload/index_zuul.html
3)上传后的结果
http://192.168.1.102:8040/microservice-file-upload/upload
说明:
1)上面测试小文件都没有问题,可以正常上传;
2)大文件,上传就报错;
4)大文件上传测试
需要将action默认指向/zuul/microservice-file-upload/upload,再上传即可;
5)通过postman测试
==============================
QQ群:143522604
群里有相关资源
欢迎和大家一起学习、交流、提升!
==============================