日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

通过Zuul上传文件,禁用Zuul的Filters

發(fā)布時間:2024/4/13 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过Zuul上传文件,禁用Zuul的Filters 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
microservice-file-uploadspring:application:name: microservice-file-uploadhttp:multipart:max-file-size: 2000Mb (默認(rèn)1M)max-request-size: 2500Mb (默認(rèn)10M)https://www.cnblogs.com/gqymy/p/11195794.htmlhttps://blog.csdn.net/starskyboy/article/details/83217251spring.application.http.multipart.max-file-size=2000Mb spring.application.http.multipart.max-request-size=2000Mb/*** Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or* kilobytes respectively.*/ private String maxFileSize = "1MB";localhost:8050/index.htmlhttps://blog.csdn.net/shenzhen_zsw/article/details/81009235zuul有一個端點是/zuul/*https://cloud.spring.io/spring-cloud-netflix/reference/html/#_strangulation_patterns_and_local_forwardsUploading Files through Zuul我們上傳都是用的SpringMVC的,SpringMVC默認(rèn)是/**,所以它使用的是Spring DispatcherServlet,當(dāng)Zuul在你的classpath下面呢,他就會繞過這個東西上傳大文件得將超時時間設(shè)置長一些,否則會報超時異常。以下幾行超時設(shè)置來自https://cloud.spring.io/spring-cloud-netflix/reference/html/#_uploading_files_through_zuulhystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 ribbon:ConnectTimeout: 3000ReadTimeout: 60000hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000 ribbon.ConnectTimeout=3000 ribbon.ReadTimeout=6000經(jīng)過zuul的請求,他都會用hystrix進(jìn)行包裹,所以我需要配一下hystrix的超時時間,然后zuul還是用了ribbon做負(fù)載均衡,所以我也要設(shè)置一下ribbon的ConnectTimeout,和ReadTimeout microservice-file-uploadspring:application:name: microservice-file-uploadhttp:multipart:max-file-size: 2000Mb (默認(rèn)1M)max-request-size: 2500Mb (默認(rèn)10M)https://www.cnblogs.com/gqymy/p/11195794.htmlhttps://blog.csdn.net/starskyboy/article/details/83217251spring.application.http.multipart.max-file-size=2000Mb spring.application.http.multipart.max-request-size=2000Mb/*** Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or* kilobytes respectively.*/ private String maxFileSize = "1MB";localhost:8050/index.htmlhttps://blog.csdn.net/shenzhen_zsw/article/details/81009235zuul有一個端點是/zuul/*https://cloud.spring.io/spring-cloud-netflix/reference/html/#_strangulation_patterns_and_local_forwardsUploading Files through Zuul我們上傳都是用的SpringMVC的,SpringMVC默認(rèn)是/**,所以它使用的是Spring DispatcherServlet,當(dāng)Zuul在你的classpath下面呢,他就會繞過這個東西上傳大文件得將超時時間設(shè)置長一些,否則會報超時異常。以下幾行超時設(shè)置來自https://cloud.spring.io/spring-cloud-netflix/reference/html/#_uploading_files_through_zuulhystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 ribbon:ConnectTimeout: 3000ReadTimeout: 60000hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000 ribbon.ConnectTimeout=3000 ribbon.ReadTimeout=6000經(jīng)過zuul的請求,他都會用hystrix進(jìn)行包裹,所以我需要配一下hystrix的超時時間,然后zuul還是用了ribbon做負(fù)載均衡,所以我也要設(shè)置一下ribbon的ConnectTimeout,和ReadTimeout,使用Zuul上傳文件是可以上傳文件的,上傳大文件可以加/zuul/前綴,上傳大文件要設(shè)置一個超時,這邊給了一個Demo,也是基于curl的$ curl -v -H "Transfer-Encoding: chunked" \-F "file=@mylarge.iso" localhost:9999/zuul/simple/file我們發(fā)現(xiàn)這里有一個chunked看一下chunked是什么意思HTTP響應(yīng)chunked格式分析https://blog.csdn.net/zztfj/article/details/5906168Plain Embedded Zuulhttps://cloud.spring.io/spring-cloud-netflix/reference/html/#_plain_embedded_zuul我們知道@EnableZuulProx,整合了Eureka,做了反向代理,我們有的時候并不想讓Zuul做太多的事情,用@EnableZuulServer,這個是更輕量的Zuul,它是一個空的Zuulorg.springframework.cloud.netflix.zuul.EnableZuulServer/*** Set up the application to act as a generic Zuul server without any built-in reverse* proxy features. The routes into the Zuul server can be configured through* {@link ZuulProperties} (by default there are none).** @see EnableZuulProxy to see how to get reverse proxy out of the box** @author Spencer Gibb*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Import(ZuulConfiguration.class) public @interface EnableZuulServer {}構(gòu)建了一個Zuul,但是不包含任何內(nèi)建的反向代理的特性org.springframework.cloud.netflix.zuul.filters.ZuulProperties你可以使用這個自己去配https://github.com/spring-cloud/spring-cloud-netflix/issues/1447I cannot figure outhttps://github.com/spring-cloud/spring-cloud-netflix/issues/1477When should I use @EnableZuulServer? #1477@spencergibb I know it, but I cannot figure out when to use a blank zuul.It is blank zuul with no filters installed.Disable Zuul Filtershttps://cloud.spring.io/spring-cloud-netflix/reference/html/#_disable_zuul_filters你可以指定某個filter,Zuul大部分功能都是基于filter的,這個filter不是servlet的filter,public class DebugFilter extends ZuulFilter {filter type有pre,post,root <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.learn.cloud</groupId><artifactId>microservice-file-upload</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><parent><groupId>cn.learn</groupId><artifactId>microcloud02</artifactId><version>0.0.1</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties> <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies><!-- 這個插件,可以將應(yīng)用打包成一個可執(zhí)行的jar包 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project> server.port=8050 eureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eureka eureka.instance.prefer-ip-address=true spring.application.name=microservice-file-upload eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}} spring.application.http.multipart.max-file-size=2000Mb spring.application.http.multipart.max-request-size=2000Mbmanagement.security.enabled=falselogging.level.com.learn=trace logging.file=springboot.log logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%n package com.learn.cloud.controller;import java.io.File; import java.io.IOException;import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile;@RestController public class FileUploadController {/*** 上傳文件* 測試方法:* 有界面的測試:http://localhost:8024/index.html* 使用命令:curl -F "file=@文件全名" localhost:8050/upload* ps.該示例比較簡單,沒有做IO異常、文件大小、文件非空等處理** @param file 待上傳的文件* @return 文件在服務(wù)器上的絕對路徑* @throws IOException IO異常*/@PostMapping("/upload")String handleFileUpload(@RequestParam(value = "file", required = true) MultipartFile file) throws IOException {byte[] bytes = file.getBytes();File fileToSave = new File(file.getOriginalFilename());FileCopyUtils.copy(bytes, fileToSave);return fileToSave.getAbsolutePath();} } <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body><!--<form method="POST" enctype="multipart/form-data" action="http://localhost:8040/microservice-file-upload/upload">--><form method="POST" enctype="multipart/form-data" action="/upload">File to upload:<input type="file" name="file"><input type="submit" value="Upload"></form> </body> </html> package com.learn.cloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@EnableEurekaClient @SpringBootApplication public class RegisterFileUploadZuulApplication {public static void main(String[] args) {SpringApplication.run(RegisterFileUploadZuulApplication.class, args);} }

?

總結(jié)

以上是生活随笔為你收集整理的通过Zuul上传文件,禁用Zuul的Filters的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。