Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门,提供动态路由,监控,弹性,安全等的边缘服务

所有请求都经过网关(API Gateway)zuul,然后转发到各个子服务上去

1.注册中心eureka

<!--eureka-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
@EnableEurekaServer//注解启动一个服务注册中心
@SpringBootApplication
public class EurekaApp { public static void main(String[] args) {
SpringApplication.run(EurekaApp.class, args);
}
}
#application配置
server.port=8888 #在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false #服务注册地址
eureka.instance.ip-address=localhost
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

启动app,访问http://localhost:8888/

2.service1

@EnableDiscoveryClient//激活Eureka中的DiscoveryClient实现
@SpringBootApplication
public class Service1App { public static void main(String[] args) {
SpringApplication.run(Service1App.class, args);
}
}
server.port=1111
server.address=localhost
spring.application.name=service1 #注册中心地址
eureka.instance.ip-address=localhost
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
public class UserController {

    private final static Logger LOGGER = LoggerFactory.getLogger(User2Controller.class);
@Autowired
private DiscoveryClient discoveryClient; @RequestMapping("/index")
public String index(HttpServletRequest request){
return "service1 被调用, 请求地址:" + request.getRequestURI();
} }

3.service2

@EnableDiscoveryClient//激活Eureka中的DiscoveryClient实现
@SpringBootApplication
public class Service2App { public static void main(String[] args) {
SpringApplication.run(Service2App.class, args);
}
}
server.port=2222
server.address=localhost
spring.application.name=service2 #注册中心地址
eureka.instance.ip-address=localhost
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
public class User2Controller {

    private final static Logger LOGGER = LoggerFactory.getLogger(User2Controller.class);
@Autowired
private DiscoveryClient discoveryClient; @RequestMapping("/index")
public String index(HttpServletRequest request){
return "service2 被调用, 请求地址:" + request.getRequestURI();
} }

4.zuul网关

<!--eureka-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
@EnableZuulProxy//声明zuul代理
@SpringBootApplication
public class ZuulMainApp { public static void main(String[] args) {
SpringApplication.run(ZuulMainApp.class, args);
}
}
#注册中心地址
eureka.instance.ip-address=localhost
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/ #路由配置
#url形式
zuul.routes.baidu.path=/baidu/**
zuul.routes.baidu.url=http://www.baidu.com
#注册服务
zuul.routes.service1.path=/service1/**
zuul.routes.service1.serviceId=service1
zuul.routes.service2.path=/service2/**
zuul.routes.service2.serviceId=service2

测试:启动sevice1,service2,zuul

查看注册中心:

通过网关+路由名称访问:

http://localhost:8080/baidu

http://localhost:8080/service1/index

http://localhost:8080/service2/index

项目地址:https://github.com/yangzhenlong/mySpringBootDemo/tree/master/springboot12-zuul

springboot12-zuul的更多相关文章

  1. Netflix Zuul 了解

    Zuul 是提供动态路由,监控,弹性,安全等的边缘服务.Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门.Zuul 可以适当的对多个 Amazon Auto Scal ...

  2. netflix zuul 学习

    netflix zuul 是netflix开发的一个EDGE SERVICE. 主要是作为一个API Gateway 服务器,可以实现安全,流量控制等功能. 我看的是1.x的版本,Zuul1.x的实现 ...

  3. SpringCloud网关ZUUL集成consul

    最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码 pom文件 <project xmlns="http://mav ...

  4. springcloud(十):服务网关zuul

    前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...

  5. Spring REST 与 Zuul 代理

    http://www.baeldung.com/spring-rest-with-zuul-proxy 作者: Eugen Paraschiv 译者: http://oopsguy.com 1.概述 ...

  6. Zuul(SpringCloud学习笔记一)

    路由是微服务架构中必须(integral )的一部分,比如,"/" 可能映射到你的WEB程序上,"/api/users "可能映射到你的用户服务上," ...

  7. zuul超时的解决方案

    参考http://www.coolxuewang.com/view/10 在zuul的配置文件里增加如下配置: ribbon:    ConnectTimeout: 6000    ReadTimeo ...

  8. Spring Cloud Zuul

    新建Spring Boot工程,命名为zuul 1.pom.xml添加依赖 <?xml version="1.0" encoding="UTF-8"?&g ...

  9. Spring Cloud Zuul 添加 ZuulFilter

    紧接着上篇随笔Spring Cloud Zuul写,添加过滤器,进行权限验证 1.添加过滤器 package com.dzpykj.filter; import java.io.IOException ...

  10. springCloud zuul网关服务

    第一步:编写application.properties文件 spring.application.name=api-gateway server.port=5555 zuul.routes.user ...

随机推荐

  1. [NOI2005]聪聪与可可(期望dp)

    题意:给一张无向图,有一只猫和一只老鼠,猫每秒会向老鼠的方向移动两个单位,若它们的距离为一,那么只会移动一个单位,老鼠会等概率向周围移动一步或不动,求猫抓到老鼠的期望时间. Solutionluogu ...

  2. MyBatis深入浅出--入门

    mybatis概述 mybatis简介 MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. ...

  3. SpringBoot构建大数据开发框架

    http://blog.51cto.com/yixianwei/2047886 为什么使用SpringBoot 1.web工程分层设计,表现层.业务逻辑层.持久层,按照技术职能分为这几个内聚的部分,从 ...

  4. 如何设计出优秀的Restful API?

    https://mp.weixin.qq.com/s?__biz=MzU0OTE4MzYzMw==&mid=2247485240&idx=1&sn=b5b9c8c41659d2 ...

  5. wildfly 10上使用最新的 Hibernate ORM OGM

    ORM是关系型数据库连接:ogm是No sql数据库连接,Mongo, redis等. 1,下载ogm zip包,解压到wildfly_home\modules\system\layers\base, ...

  6. js jquery 数组的合并 对象的合并

    转载自:http://www.cnblogs.com/xingxiangyi/p/6416468.html 1 数组合并 1.1 concat 方法 1 2 3 4 var a=[1,2,3],b=[ ...

  7. A1006. Sign In and Sign Out

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  8. 【洛谷P3455】ZAP-Queries

    题目大意:求 \[\sum\limits_{i=1}^a\sum\limits_{j=1}^b[gcd(i,j)=c]\] 题解:学会了狄利克雷卷积. \[\epsilon=\mu \ast 1\] ...

  9. matplotlib 将两张数据视图在一起显示

    import numpy as np import pandas as pd from matplotlib import pyplot as plt if __name__ == "__m ...

  10. 神经网络中w,b参数的作用(为何需要偏置b的解释)

    http://blog.csdn.net/xwd18280820053/article/details/70681750 可视图讲解神经元w,b参数的作用 在我们接触神经网络过程中,很容易看到就是这样 ...