springboot12-zuul
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的更多相关文章
- Netflix Zuul 了解
Zuul 是提供动态路由,监控,弹性,安全等的边缘服务.Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门.Zuul 可以适当的对多个 Amazon Auto Scal ...
- netflix zuul 学习
netflix zuul 是netflix开发的一个EDGE SERVICE. 主要是作为一个API Gateway 服务器,可以实现安全,流量控制等功能. 我看的是1.x的版本,Zuul1.x的实现 ...
- SpringCloud网关ZUUL集成consul
最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码 pom文件 <project xmlns="http://mav ...
- springcloud(十):服务网关zuul
前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...
- Spring REST 与 Zuul 代理
http://www.baeldung.com/spring-rest-with-zuul-proxy 作者: Eugen Paraschiv 译者: http://oopsguy.com 1.概述 ...
- Zuul(SpringCloud学习笔记一)
路由是微服务架构中必须(integral )的一部分,比如,"/" 可能映射到你的WEB程序上,"/api/users "可能映射到你的用户服务上," ...
- zuul超时的解决方案
参考http://www.coolxuewang.com/view/10 在zuul的配置文件里增加如下配置: ribbon: ConnectTimeout: 6000 ReadTimeo ...
- Spring Cloud Zuul
新建Spring Boot工程,命名为zuul 1.pom.xml添加依赖 <?xml version="1.0" encoding="UTF-8"?&g ...
- Spring Cloud Zuul 添加 ZuulFilter
紧接着上篇随笔Spring Cloud Zuul写,添加过滤器,进行权限验证 1.添加过滤器 package com.dzpykj.filter; import java.io.IOException ...
- springCloud zuul网关服务
第一步:编写application.properties文件 spring.application.name=api-gateway server.port=5555 zuul.routes.user ...
随机推荐
- LVS+Keepalived搭建高可用负载均衡
应用环境: LVS负责多台WEB端的负载均衡(LB):Keepalived负责LVS的高可用(HA),这里介绍主备模型. 测试环境: 配置步骤: 1. 安装软件 在LVS-1和LVS-2两台主机上安装 ...
- poj 3666 Making the Grade(离散化+dp)
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- COGS 2392 2393 2395 有标号的二分图计数
有黑白关系: 枚举左部点(黑色点),然后$2^{i*(n-i)}$处理方法同:COGS 2353 2355 2356 2358 有标号的DAG计数 无关系: 发现,假设$f(i)$是一个连通块,对于一 ...
- TCHAR和CHAR类型的互转,string 转lpcwstr
https://www.cnblogs.com/yuguangyuan/p/5955959.html 没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时 ...
- 第一篇-Win10打开txt文件出现中文乱码
如果刚开始安装的是英文的Win10系统,那么打开txt文件时很容易出现乱码问题.包括打开cmd窗口,也是不能显示中文的.当然,麻烦的处理方法是: 在cmd中想要显示中文:先输入chcp 936,之后中 ...
- Educational Codeforces Round 53 (Rated for Div. 2)
http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...
- memset()函数及其作用(转)
1. memset()函数原型是extern void *memset(void *buffer, int c, int count) buffer:为指针或是数组, c:是赋给buffer的值, c ...
- IDEA或者WebStorm关闭JS文件的黄色提示
这个编译器虽然好用,但是友好的提醒(语法校验)太多啦 解决: 在右下角有个小人儿 然后更改提示级别
- java8 List<对象> 转 Set、Map(高级)
实体类 public class Student { private int id; private String name; private String score; private int cl ...
- c#大文件的拷贝
using System.IO; namespace 数据流 { class Demo2 { private string _strSourcePath = @"D:\httpd-2.4.3 ...