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 ...
随机推荐
- 攻防世界Hello,CTF writeup
解题过程 首先在ida中进行反汇编,查看main函数的代码: 代码的的36行处进行了一个字符串比较,如果v10的值等于v13的值会反馈一个success的输出.v13的值在第15行给出,因此需要知道v ...
- EntityFramework Core Code First 已有数据库
问题场景:我已经有一个数据库,想用 EF core Code First,怎么办? 首先,可以参考微软的API文档:通过现有数据库在 ASP.NET Core 上开始使用 EF Core, 这一步可以 ...
- tp5 回滚事务记录,其中一条语句报错,全部回滚
#################################### 测试事务 // 启动事务 Db::startTrans(); try { //插入行为表 $data = [ 'userId' ...
- Everything 的高级用法
文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论
- 调用subprocess 使用logging打印日志
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Henry 17607168727@163.com import sys import lo ...
- 交互式绘图工具gunplot
Gnuplot是一个命令行的交互式绘图工具(command-driven interactive function plotting program).用户通过输入命令,可以逐步设置或修改绘图环境,并 ...
- 【402】Twitter Data Collection
参考:Python判断文件是否存在的三种方法 参考:在python文件中执行另一个python文件 参考:How can I make a time delay in Python? 参考:Twili ...
- PAT 甲级 1013 Battle Over Cities (25 分)(图的遍历,统计强连通分量个数,bfs,一遍就ac啦)
1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highway ...
- 用python画函数图像
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 1, 50) # 从0到1,等分50分 y = 210*(x ...
- CockroachDB学习笔记——[译]如何优化Go语言中的垃圾回收
原文链接:https://www.cockroachlabs.com/blog/how-to-optimize-garbage-collection-in-go/ 原作者:Jessica Edward ...