springcloud学习笔记(八)SpringCloud集成zuul路由(一)
2018-02-24 10:44
806 查看
在微服务架构中,需要几个基础的服务治理组件,包括服务注册与发现、服务消费、负载均衡、断路器、智能路由、配置管理等,由这几个基础组件相互协作,共同组建了一个简单的微服务系统。一个简答的微服务系统如下图:
注意:A服务和B服务是可以相互调用的,作图的时候忘记了。并且配置服务也是注册到服务注册中心的。在Spring Cloud微服务系统中,一种常见的负载均衡方式是,客户端的请求首先经过负载均衡(zuul、Ngnix),再到达服务网关(zuul集群),然后再到具体的服。,服务统一注册到高可用的服务注册中心集群,服务的所有的配置文件由配置服务管理(下一篇文章讲述),配置服务的配置文件放在git仓库,方便开发人员随时改配置。
Insights
Stress Testing
Canary Testing
Dynamic Routing
Service Migration
Load Shedding
Security
Static Response handling
Active/Active traffic management
不多说,上面是复制的,下面开始代码测试:
项目结构如下图
首先,启动类加入注解@EnablezuulProxy:package com.xc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class App_zuul {
public static void main(String[] args){
SpringApplication.run(App_zuul.class,args);
}
}资源文件application.yml:eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://xc:123@localhost:8761/eureka server:
port: 6543
spring:
application:
name: service-zuul
zuul:
routes:
api-a:
path: /api-a/**
serviceId: cloud-test
api-b:
path: /api-b/**
serviceId: cloud-test2其中serviceId:cloud-test为微服务,并且有个服务为hello:
其中serviceId:cloud-test2为微服务,并且也有个服务为hello:
下面我们启动注册中心,以及路由微服务和两个测试微服务。
如下:
我们访问 http://localhost:6543/api-a/hello 成功访问到sercice1
http://localhost:6543/api-b/hello 成功访问到sercice2
ok,一个简单的路由就搭建起来了
注意:A服务和B服务是可以相互调用的,作图的时候忘记了。并且配置服务也是注册到服务注册中心的。在Spring Cloud微服务系统中,一种常见的负载均衡方式是,客户端的请求首先经过负载均衡(zuul、Ngnix),再到达服务网关(zuul集群),然后再到具体的服。,服务统一注册到高可用的服务注册中心集群,服务的所有的配置文件由配置服务管理(下一篇文章讲述),配置服务的配置文件放在git仓库,方便开发人员随时改配置。
一、Zuul简介
Zuul的主要功能是路由转发和过滤器。路由功能是微服务的一部分,比如/api/user转发到到user服务,/api/shop转发到到shop服务。zuul默认和Ribbon结合实现了负载均衡的功能。zuul有以下功能:AuthenticationInsights
Stress Testing
Canary Testing
Dynamic Routing
Service Migration
Load Shedding
Security
Static Response handling
Active/Active traffic management
不多说,上面是复制的,下面开始代码测试:
项目结构如下图
首先,启动类加入注解@EnablezuulProxy:package com.xc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class App_zuul {
public static void main(String[] args){
SpringApplication.run(App_zuul.class,args);
}
}资源文件application.yml:eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://xc:123@localhost:8761/eureka server:
port: 6543
spring:
application:
name: service-zuul
zuul:
routes:
api-a:
path: /api-a/**
serviceId: cloud-test
api-b:
path: /api-b/**
serviceId: cloud-test2其中serviceId:cloud-test为微服务,并且有个服务为hello:
其中serviceId:cloud-test2为微服务,并且也有个服务为hello:
下面我们启动注册中心,以及路由微服务和两个测试微服务。
如下:
我们访问 http://localhost:6543/api-a/hello 成功访问到sercice1
http://localhost:6543/api-b/hello 成功访问到sercice2
ok,一个简单的路由就搭建起来了
相关文章推荐
- Zuul (SpringCloud学习笔记一) 转
- Zuul(SpringCloud学习笔记一)
- Spring Cloud微服务断路由Hystrix与服务网关学习笔记
- Spring Cloud学习:04路由网关(Zuul)
- Zuul(SpringCloud学习笔记一)
- spring-cloud-zuul之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- Spring Cloud微服务断路由Hystrix与服务网关学习笔记
- SpringCloud学习笔记-zuul网关
- spring cloud笔记 - zuul路由和拦截篇
- Spring Cloud 学习笔记——入门、特征、配置
- redis 学习笔记(5)-Spring与Jedis的集成
- Spring Cloud 学习笔记-Eureka 服务注册与发现
- SpringCloud学习笔记 - 服务治理
- SpringCloud与构建微服务学习笔记整理
- SpringCloud 学习 | 第七篇: 路由(zuul)
- SpringCloud教程十:Zuul+Mysql实现动态路由
- SpringCloud学习之SpringCloudStream&集成kafka
- spring cloud微服务权限认证学习笔记
- 一起来学SpringCloud之 - 路由网关(Zuul)
- 疯狂Spring Cloud连载(24)Zuul路由配置