spring cloud 入门实践系列
来源:互联网 发布:linux编译链接 编辑:程序博客网 时间:2024/06/05 22:30
Zuul is the front door for all requests from devices and web sites to the backend of the Netflix streaming application. As an edge service application, Zuul is built to enable dynamic routing, monitoring, resiliency and security. It also has the ability to route requests to multiple Amazon Auto Scaling Groups as appropriate.
Zuul是从设备和网站到Netflix流应用的后端的所有请求的前门。 作为边缘服务应用程序,Zuul旨在实现动态路由,监控,弹性和安全性。 它还可以根据需要将请求路由到多个Amazon Auto Scaling Groups。
启动eureka注册中心
可参见之前文章
创建两个eureka服务
service-first 暴露在8961端口
@RestController@RequestMapping("firstapi")public class FirstApiController { @RequestMapping("speak") public String doSpeak(@RequestParam String words){ return "port:8961,woooooo,I am speaking of ["+words+"]"; }}
service-second 暴露在8962端口
@RestController@RequestMapping("secondApi")public class SecondApiController { @RequestMapping("sing") public String sing(@RequestParam String song){ return "port:8962,hoooooooo,I am singing of ["+song+"]"; }}
创建zuul服务
项目结构
zuul启动类
@EnableZuulProxy@EnableEurekaClient@SpringBootApplicationpublic class ZuulwareApplication { public static void main(String[] args) { SpringApplication.run(ZuulwareApplication.class, args); }}
@EnableZuulServer - 普通网关,只支持基本的route与filter.
@EnableZuulProxy - 配合上服务发现与熔断开关的上面这位增强版,具有反向代理功能.
zuul配置文件application.yml,zuul服务暴露在8963端口
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/server: port: 8963spring: application: name: service-zuulzuul: routes: firstapi: path: /firstapi/** serviceId: service-first secondapi: path: /secondapi/** serviceId: service-second
上面配置的含义是请求路径uri为/firstapi开头的转发至service-first服务
请求路径uri为/firstapi开头的转发至service-second服务
特别注意:1. routes节点下的元素要与path的前缀一致
2. path 后面的/**是指服务对应的全路径,比如我在service-first中定义的FirstApiController,访问的路径是http://172.16.153.1:8961/firstapi/speak?words=zxl,如果我们想通过zuul服务转发出去,则访问路径应该是http://172.16.153.1:8961/firstapi/firstapi/speak?words=zxl 第一个firstapi代表zuul配置文件中配置的route地址,第二个firstapi代表FirstApiController类的访问路径配置,这点一定要注意。千万不要使用http://172.16.153.1:8961/firstapi/speak?words=zxl 这种方式去访问,因为zuul将该路径请求转发给service-first后,是使用/speak去匹配,这样是找不到对应处理类的。
启动2个eureka服务和zuul服务
http://172.16.153.1:8963/firstapi/firstapi/speak?words=zxlhgggggggg
http://172.16.153.1:8963/secondapi/secondApi/sing?song=zxl
可见我们通过zuul的8693端口访问出去的请求,最终被zuul转发到8691和8692对应的服务上去了。
- spring cloud 入门实践系列
- spring cloud 入门实践系列
- spring cloud 入门实践系列
- spring cloud 入门实践系列
- spring cloud 入门实践系列
- spring cloud 入门实践系列
- Spring Cloud 入门系列总结
- SpringBoot系列—Spring Cloud快速入门
- Spring Cloud Security系列教程一:入门
- Spring Cloud Config 实践
- spring cloud系列
- spring cloud 系列文章
- spring-cloud系列-Eureka
- spring cloud入门基础
- Spring cloud入门
- spring cloud入门学习
- Spring Cloud 入门
- Spring Cloud Eureka 入门 (一)服务注册中心详解 「Spring Cloud Eureka 入门系列」 Spring Cloud Eureka 入门 (一)服务注册中心详解 Spr
- 捕捉home键,点击home键的时候隐藏软键盘、关闭正在播放等需求
- BeanFactory管理Bean的生命周期
- numpy.transpose对三维数组的转置
- 不同版本的Oracle数据库的用户密码加密算法
- C#多线程学习笔记
- spring cloud 入门实践系列
- oracle data guard broker配置与使用(下)
- 华硕ASUS 笔记本 改WIN7 BIOS 设置详解
- 如何在面试过程中提升实力
- 杭电第一次多校赛_1001_Add_More_Zero_2017_7_25
- 武汉大学国际软件学院夏令营笔试和面试简介
- 用户资源访问
- Java多线程(一)——实现多线程的两种方式
- 河工APP文档