博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring cloud Zuul 服务网关
阅读量:7000 次
发布时间:2019-06-27

本文共 3864 字,大约阅读时间需要 12 分钟。

上面的是一个最基本的微服务架构

1:Eureka Server注册中心

2:服务集群里面的应用ServiceA,ServiceB向注册中心进行注册和订阅服务

3:Open ServiceA 和Open ServiceB是RestFullAPI服务,通过负载均衡等,对外提供接口的调用

基本功能都能实现,但实际上还是有很多缺陷

1:运维:系统的路由等配置需要运维人员手工配置,易出错

2:开发:每个服务都要有相应的权限控制,当接口数量比较大的时候,权限控制会产生很大的代码量

3:接口无法实现复用

springCloud的服务网关可以解决上面的问题SpringCloud Zuul

 @SpringCloudApplication 注解在zuul依赖包下面 可以完美代替@SpringBootApplication,@EnableDiscoveryClient,@EnableCircuitBreaker三个注解

1:创建项目添加pom.xml依赖

4.0.0
com.smart
zuul
0.0.1-SNAPSHOT
jar
zuul
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.3.5.RELEASE
UTF-8
UTF-8
1.8
Finchley.RC1
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-starter-zuul
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
Brixton.RELEASE
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false

2:springCloud主程序部分

package com.smart;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.SpringCloudApplication;import org.springframework.cloud.netflix.zuul.EnableZuulProxy;//@SpringBootApplication@EnableZuulProxy@SpringCloudApplicationpublic class ZuulApplication {    public static void main(String[] args) {        SpringApplication.run(ZuulApplication.class, args);    }}

3:配置文件

spring.application.name=api-gatewayserver.port=5555# routes to serviceIdzuul.routes.api-a.path=/api-a/**zuul.routes.api-a.serviceId=service-Azuul.routes.spi-a.name=service-Azuul.routes.api-b.path=/api-b/**zuul.routes.api-b.serviceId=service-B# routes to urlzuul.routes.api-a-url.path=/api-a-url/**zuul.routes.api-a-url.url=http://localhost:2222/eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/

配置文件这里映射两个服务,service-A  service-B,

4:启动eureka,service-A ,service-B,zuul

访问http://localhost:5555/api-a-url/add?a=1&b=2,

 

 

映射方式url映射,serviceId映射,这里发现serviceId映射方式并不能实现,报错,然而我并不清楚发生了什么

 

 

 注:关于映射

这里就说下url映射吧

# routes to url

zuul.routes.api-a-url.path=/api-a-url/**

zuul.routes.api-a-url.url=http://localhost:2222/

当访问http://localhost:5555/api-a-url/add?a=1&b=2会涉及到一个转发,实际访问的是http://localhost:2222/add?a=1&b=2

 

 

 

 

转载于:https://www.cnblogs.com/shuzhongruyu/p/8968766.html

你可能感兴趣的文章
1126 code plan
查看>>
JavaScript正则表达式基础知识汇总
查看>>
用LINQ获取XML节点数据
查看>>
在类中使用Response.Redirect()方法
查看>>
谷歌修复了 FFmpeg 中上千个 bug
查看>>
CSS3 用户界面
查看>>
SET TEXTSIZE number
查看>>
实现一个简单的视频聊天室(源码)
查看>>
白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连续7-电话问卷调查...
查看>>
Oracle 时间相减得出毫秒、秒、分、时、天,,【转】
查看>>
关于消息队列的使用
查看>>
IOS-Storyboard全解析-第二部分
查看>>
WEKA,一个开源java的数据挖掘工具
查看>>
Linux 查看设置系统语言
查看>>
阿里云物联网平台体验(NetGadgeteer+C#篇)
查看>>
mongdb开始标记
查看>>
linux内核源码结构
查看>>
CCM加密学习
查看>>
ZigBee profile
查看>>
127.0.0.1\SQLEXPRESS连接异常
查看>>