spring-cloud 学习四 服务网关
API Gateway
服务网关在微服务中是一个很重要的组成部分,通过服务网关可以统一向外提供REST API,例如 / 映射到后端应用 /api/user 映射到 user service, /api/comment 映射到comment service,在spring cloud中通过集成zuul来实现这个 gateway,他提供一下功能
- Authentication
- Insights
- Stress Testing
- Canary Testing
- Dynamic Routing
- Service Migration
- Load Shedding
- Security
- Static Response handling
- Active/Active traffic management
我们使用两个服务,我们以user-provider-service来进行测试
我们访问http://localhost:8081/users 可以看到如下输出,8081 就是user-provider-service服务的端口
[{"id":"1","name":"陈七","tel":null},{"id":"2","name":"王六","tel":null}]
建一个api-gateway module
pom文件
<parent>
<groupId>com.dh.cloud</groupId>
<artifactId>spring-cloud-demo</artifactId>
<version>1.0-SNAPSHOT</version>
</parent> <dependencies> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-sidecar</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency> </dependencies>
启动类
@SpringBootApplication
@EnableSidecar
public class AppGatewayApplication { public static void main(String[] args) {
SpringApplication.run(AppGatewayApplication.class, args);
} }
application.yml
server:
port: 10000 sidecar:
port: 8000 endpoints:
restart:
enabled: true
shutdown:
enabled: true
health:
sensitive: false eureka:
instance:
hostname: gateway
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
bootstrap.yml
spring:
application:
name: api-gateway
cloud:
config:
uri: http://localhost:8888
encrypt:
failOnError: false
这里使用的都是默认配置,运行代码
访问http://localhost:10000/user-provider-service/users,10000为gateway的端口
看到输出
[{"id":"1","name":"陈七","tel":null},{"id":"2","name":"王六","tel":null}]
和直接访问服务一致,到此zuul一个简单的演示就完成了
spring-cloud 学习四 服务网关的更多相关文章
- spring cloud学习笔记五 网关服务zuul
网关服务是指,客户端发送的请求不用直接访问特定的微服务接口,而且是经过网关服务的接口进行交互,网关服务再去到特定的微服务中进行调用. 网关服务的路由功能和Nginx的反向代理一样,所有的服务都先会 ...
- spring cloud 学习之路由网关(zuul)
学习自方志朋的博客 http://blog.csdn.net/forezp/article/details/69939114 在微服务架构中,需要几个基础的服务治理组件,包括服务注册与发现.服务消费. ...
- spring cloud 学习之服务消费者(rest+ribbon)
学习自 http://blog.csdn.net/forezp/article/details/81040946 方志朋的博客 在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于h ...
- Spring Cloud Zuul API服务网关之请求路由
目录 一.Zuul 介绍 二.构建Spring Cloud Zuul网关 构建网关 请求路由 请求过滤 三.路由详解 一.Zuul 介绍 通过前几篇文章的介绍,我们了解了Spring Cloud ...
- spring cloud学习(一) 服务注册
首先spring-cloud相关的简介可以去百度搜索,这里就不多说了,这里分享一个翻译spring cloud官网的中文网站spring cloud中文网 这个学习项目的代码放在 https://gi ...
- Spring Cloud(十):服务网关zuul(转)
前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...
- spring cloud学习(四) Fegin 的使用
Feign 的使用 什么是Feign? Feign : Declarative REST clients. Feign 是一个声明web服务客户端,这便得编写web服务客户端更容易,使用Feign 创 ...
- SpringCloud学习笔记(20)----Spring Cloud Netflix之服务网关Zuul的各种姿势
1. 禁用过滤器 # zuul.<SimpleClassName>.<filterType>.disable=true # 例如禁用 自定义的过滤器 zuul.MyFilter ...
- SpringCloud学习笔记(18)----Spring Cloud Netflix之服务网关Zuul原理
1. Zuul的工作机制 Zuul提供了一个框架,可以对过滤器进行动态的加载,编译,运行.过滤器之间没有直接的相互通信,他们是通过一个RequestContext的静态类来进行数据传递的.Requet ...
随机推荐
- Ubuntu18.04初始的systemd service
Ubuntu18.04初始的systemd service 两个位置 /etc/systemd/system root@dev2:~# ls /etc/systemd/system aliyun.se ...
- SpringBoot2.0 Actuator 监控参数说明
主要内容更 监控参数说明 Maven坐标 <dependency> <groupId>org.springframework.boot</groupId> < ...
- fastjson序列化和反序列化报com.alibaba.fastjson.JSONException: autoType is not support异常问题,解决方案整合
1.问题起因 2017年3月15日,fastjson官方发布安全升级公告,该公告介绍fastjson在1.2.24及之前的版本存在代码执行漏洞,当恶意攻击者提交一个精心构造的序列化数据到服务端时,由于 ...
- JNI调用C和C++存在的区别
JNI调用C和C++存在的区别 JNI是由C语言定义接口的,JNI通过函数名找函数入口,执行函数里的内容.这和函数用什么语言生成的并没有关系.只要保证函数名称符合JNI的协议.而使用C++要注意的 ...
- MySQL中tinytext、text、mediumtext和longtext等各个类型详解
转: MySQL中tinytext.text.mediumtext和longtext等各个类型详解 2018年06月13日 08:55:24 youcijibi 阅读数 26900更多 个人分类: 每 ...
- C++ transform for_each
#include<iostream>#include<vector>#include <list>#include <algorithm>#includ ...
- 目标检测-Cascade-RCNN
转载:https://zhuanlan.zhihu.com/p/36095768 Cascade R-CNN: Delving into High Quality Object Detection 论 ...
- 模型压缩-L1-norm based channel pruning(Pruning Filters for Efficient ConvNets)
论文笔记——PRUNING FILTERS FOR EFFICIENT CONVNETS 转载:https://www.cnblogs.com/zhonghuasong/p/7642000.html ...
- 处理HTTP请求
处理HTTP请求 当客户端浏览器通过URL访问web应用时,首先要做的就是获取用户提交的信息,也就是从HTTP请求数据中获得的信息.HTTP请求数据分为HTTP请求头和Body HTTP请求头包含了一 ...
- Response.setContentType()参数说明
response.setContentType()的参数说明 <meta http-equiv="Content-Type" content="text/html; ...