springcloud14---zuul
package com.itmuch.cloud.study; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
public class FileUploadApplication {
public static void main(String[] args) {
SpringApplication.run(FileUploadApplication.class, args);
}
}
package com.itmuch.cloud.study.controller; import java.io.File;
import java.io.IOException; import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; @Controller
public class FileUploadController {
/**
有界面的测试:http://localhost:8050/index.html
使用cmd命令:curl -F "file=@文件全名" localhost:8050/upload
@return 文件在服务器上的绝对路径
*/ //把zuul启动起来(8040端口),通过http://localhost:8040/microservice-file-upload/upload访问
//也可以通过http://localhost:8040/zuul/microservice-file-upload/upload
//zuul上传小文件不加/zuul前缀,大文件加/zuul绕过spring的。
/*
zuul上传大文件要在zuul工程的配置文件设置超时:
#经过zuul的请求都会通过hysitrcs包裹,所以zuul会有断路器功能,配置hysitrcs的超时时间
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
#zuul还使用了ribbon做负载均衡,要设备ribbon的超时时间
ribbon:
ConnectTimeout: 3000
ReadTimeout: 60000
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody 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();
}
}
server:
port: 8050
#加入到eureka
eureka:
client:
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka/
instance:
prefer-ip-address: true
spring:
application:
name: microservice-file-upload
http:
multipart:
max-file-size: 2000Mb # Max file size,默认1M
max-request-size: 2500Mb # Max request size,默认10M
<?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.itmuch.cloud</groupId>
<artifactId>microservice-file-upload</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <!-- 引入spring boot的依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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> <!-- 引入spring cloud的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!-- 添加spring-boot的maven插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
springcloud14---zuul的更多相关文章
- Netflix Zuul 了解
Zuul 是提供动态路由,监控,弹性,安全等的边缘服务.Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门.Zuul 可以适当的对多个 Amazon Auto Scal ...
- netflix zuul 学习
netflix zuul 是netflix开发的一个EDGE SERVICE. 主要是作为一个API Gateway 服务器,可以实现安全,流量控制等功能. 我看的是1.x的版本,Zuul1.x的实现 ...
- SpringCloud网关ZUUL集成consul
最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码 pom文件 <project xmlns="http://mav ...
- springcloud(十):服务网关zuul
前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...
- Spring REST 与 Zuul 代理
http://www.baeldung.com/spring-rest-with-zuul-proxy 作者: Eugen Paraschiv 译者: http://oopsguy.com 1.概述 ...
- Zuul(SpringCloud学习笔记一)
路由是微服务架构中必须(integral )的一部分,比如,"/" 可能映射到你的WEB程序上,"/api/users "可能映射到你的用户服务上," ...
- zuul超时的解决方案
参考http://www.coolxuewang.com/view/10 在zuul的配置文件里增加如下配置: ribbon: ConnectTimeout: 6000 ReadTimeo ...
- Spring Cloud Zuul
新建Spring Boot工程,命名为zuul 1.pom.xml添加依赖 <?xml version="1.0" encoding="UTF-8"?&g ...
- Spring Cloud Zuul 添加 ZuulFilter
紧接着上篇随笔Spring Cloud Zuul写,添加过滤器,进行权限验证 1.添加过滤器 package com.dzpykj.filter; import java.io.IOException ...
- springCloud zuul网关服务
第一步:编写application.properties文件 spring.application.name=api-gateway server.port=5555 zuul.routes.user ...
随机推荐
- c++11——列表初始化
1. 使用列表初始化 在c++98/03中,对象的初始化方法有很多种,例如 int ar[3] = {1,2,3}; int arr[] = {1,2,3}; //普通数组 struct A{ int ...
- AVL 平衡树
AVL是一种平衡二叉树,它通过对二叉搜索树中的节点进行旋转使得二叉搜索树达到平衡.AVL在所有的平衡二叉搜索树中具有最高的平衡性. 定义 平衡二叉树或者为空树或者为满足如下性质的二叉搜索树: 左右子树 ...
- 【python系列】python2.x和python3.x的区别
刚接触python使用的是python2.x的书籍,但是发现python3.x和python2.x有不小的区别,以下做一些记录 性能 Py3.0运行 pystone benchmark的速度比Py2. ...
- LightOJ 1348(Aladdin and the Return Journey )
题目链接:传送门 题目大意:一棵无根树,每个点上有权值,两种操作,0 x y询问x~y路径上权值和 1 x y将 节点 x 权值变为y.对于询问操作输出答案. 题目思路:树链剖分 #include & ...
- nginx代理学习
一.windows下nginx代理ftp服务器 我所在的开发环境里,nginx和ftp在同一台服务器. ftp根目录: nginx的配置: 在nginx.conf中加入: server { liste ...
- 什么是真正的APM?
近年来APM行业被越来越多的企业所关注,尤其是在2014年末,NewRelic的成功上市,更加激发了人们对这个行业前景的无限遐想.那么究竟什么是APM?APM的目的是什么?要求我们做什么?有不少企业对 ...
- 基础概念 之 Hadoop Family
Hadoop家族的技术,网上资料多如牛毛,但是还是那句老话——好脑瓜不如烂笔头,看的再多也不如自己动手写一写. Hadoop是一个分布式系统,有两个关键组件——HDFS和MapReduce,HDFS负 ...
- SVN常见问题及解决方法(转载)
svn常见符号 黄色感叹号(有冲突):--这是有冲突了,冲突就是说你对某个文件进行了修改,别人也对这个文件进行了修改,别人抢在你提交之前先提交了,这时你再提交就会被提示发生冲突,而不允许你提交,防止你 ...
- Web界面的服务器监测工具(转载)
企业服务器对于企业业务持续性意义重大,系统管理员需要密切关注企业服务器以确保一切正常运行.当发现问题的时候,他们需要知道问题开始出现时的状况,因此调查可以重点放在问题出现的时候,这就意味着定期记录信息 ...
- stark - 增、删、改
一.效果图 二.增.删.改 知识点: 1.解决代码重用 {% include 'form.html' %} 2.自定制配置modelform 每张表,就可自定义配置 labels , widges.. ...