Spring Cloud Gateway整合Eureka
Spring Cloud Gateway features:
Built on Spring Framework 5, Project Reactor and Spring Boot 2.0
Able to match routes on any request attribute.
Predicates and filters are specific to routes.
Hystrix Circuit Breaker integration.
Spring Cloud DiscoveryClient integration
Easy to write Predicates and Filters
Request Rate Limiting
Path Rewriting
如果对于spring cloud gateway不太了解的同学可以看下这篇博客:http://www.spring4all.com/article/961
Eureka server配置:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
---------------------
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
---------------------
application.yaml配置
server.port: eureka.instance.hostname: localhost
eureka.client.registerWithEureka: false
eureka.client.fetchRegistry: false
eureka.client.serviceUrl.defaultZone: http://localhost:8888/eureka/
访问url:localhost:8080

注册中心配置完毕后,需要有服务提供者发布服务以及服务消费者订阅服务
服务发布端
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
@RequestMapping(value = "/info", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public Person findPerson(){
Person person=new Person();
person.setId();
person.setAge();
person.setName("mike");
return person;
}
application.yaml
server:
port:
spring:
application:
name: serviceProvider
eureka:
client:
service-url:
defaultZone: http://localhost:8888/eureka/
发布服务指定应用名称,名称中不要带"-"。

consumer配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<version>1.4..RELEASE</version>
</dependency>
@RequestMapping("index")
public String router() {
// 根据应用名称调用服务
String json = restTemplate.getForObject(
"http://serviceProvider/info", String.class);
return json;
}
application.yaml
server:
port:
servlet:
context-path: /
spring:
application:
name: serviceConsumer
eureka:
client:
instance:
hostname: localhost
service-url:
defaultZone: http://localhost:8888/eureka/

直接通过localhost:8080/index接口访问

gateway配置
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
server:
port:
spring:
cloud:
gateway:
routes:
- id: path_route
uri: lb://serviceConsumer
predicates:
- Path=/index/** application:
name: demogateway eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://localhost:8888/eureka/
指定注册中心地址;并进行路由配置 uri:lb表示从注册中心订阅服务。
github地址:https://github.com/HushAsy/ans_gateway
Spring Cloud Gateway整合Eureka的更多相关文章
- Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用
Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...
- Spring Cloud Gateway 整合阿里 Sentinel网关限流实战!
大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第八篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...
- spring cloud gateway整合sentinel作网关限流
说明: sentinel可以作为各微服务的限流,也可以作为gateway网关的限流组件. spring cloud gateway有限流功能,但此处用sentinel来作为替待. 说明:sentine ...
- Spring Cloud Gateway(一):认识Spring Cloud Gateway
1.Spring Cloud Gateway 简介 Spring Cloud Gateway 系列目录 Spring Cloud Gateway(一):认识Spring Cloud Gateway S ...
- Nacos整合Spring Cloud Gateway实践
Spring Cloud Gateway官网:http://spring.io/projects/spring-cloud-gateway Eureka1.0的问题和Nacos对比:https://w ...
- Spring Cloud gateway 五 Sentinel整合
微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...
- Spring Cloud Alibaba学习笔记(15) - 整合Spring Cloud Gateway
Spring Cloud Gateway 概述 Spring Cloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于Netty.Reactor以及WEbFlux构建,它 ...
- Dubbo想要个网关怎么办?试试整合Spring Cloud Gateway
一.背景 在微服务架构中 API网关 非常重要,网关作为全局流量入口并不单单是一个反向路由,更多的是把各个边缘服务(Web层)的各种共性需求抽取出来放在一个公共的"服务"(网关)中 ...
- Nacos整合Spring Cloud Gateway组件
一.什么是Spring Cloud Gateway Spring Cloud Gateway是Spring Cloud官方推出的网关框架,网关作为流量入口有着非常大的作用,常见的功能有路由转发.权限校 ...
随机推荐
- Linux系列(14)之工作管理
1.工作管理 说明:工作管理(job control)是用在bash环境下的,也就是说:“当我们登录系统取得bash shell之后,在单一终端机接口下同时进行多个工作的行为管理”.举例说明,我们在登 ...
- jQuery报错:Uncaught TypeError: _this.attr is not a function
问题:想通过延时把置灰的按钮再次复原,代码如下: $("#sendEmailCode").on("click", function() { var _this ...
- mysql 连接远程连接服务器 1130错误
今天在用sqlyog连接非本地的Mysql服务器的数据库,居然无法连接很奇怪,报1130错误, ERROR 1130: Host 192.168.3.100 is not allowed to con ...
- zookeeper集群搭建与升级
zookeeper 1.zookeeper功能 1-1.配置管理 集中管理配置文件实现服务治理 1-2.命名服务 如为了通过网络访问一个系统,我们得知道对方的IP地址,但是IP地址对人非常不友好,这个 ...
- python入门pk小游戏
import time import random flag = True while flag: player_win = 0 enemy_win = 0 for i in range(1, 4): ...
- LASSO回归与L1正则化 西瓜书
LASSO回归与L1正则化 西瓜书 2018年04月23日 19:29:57 BIT_666 阅读数 2968更多 分类专栏: 机器学习 机器学习数学原理 西瓜书 版权声明:本文为博主原创文章,遵 ...
- 巧妙记忆 ++i 和 i++ 的区别
区别在于: i++先做别的事,再自己加1, ++i先自己加1,再做别的事情, 形象的理解,你可以把 ++i比作自私的人,首先考虑自己的事, i++是无私的,先为别人照想,这样方便记忆. 示例: a = ...
- javascript定义一个list
JavaScript可以定义数组类型,在javascript语言中List叫Array,它有以下2种定义方式方式1:var array=new Array();方式2:var array=[];通常在 ...
- vue覆盖UI组件样式不生效
检查检查是不是加了scoped 在vue中,我们需要引用子组件,包括ui组件(element.iview). 但是在父组件中添加scoped之后,在父组件中书写子组件的样式是无效果的. 去掉scope ...
- 使用高德地图JS获取当前位置和经纬度
先看效果,我做的是这样的,可以按地图位置来返回当前你点的位置(图一,二),也可以根据输入框的自动搜索(图三,四) HTML的代码: <div> <input type="t ...