spring cloud:gateway-eureka
gateway-server-eureka
1. File-->new spring starter project
2.add dependency
<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>
3.Edit application.yml
server:
port:
spring:
application:
name: gateway-server-eureka
cloud:
gateway:
# routes:
# - id: neo_route
# uri: https://www.cnblogs.com/alittlesmile/
# predicates:
# - Path=/alittlesmile
discovery:
locator:
enabled: true eureka:
client:
service-url:
defaultZone: http://localhost:8000/eureka/
配置说明:
spring.cloud.gateway.discovery.locator.enabled
:是否与服务注册于发现组件进行结合,通过 serviceId 转发到具体的服务实例。默认为 false,设为 true 便开启通过服务中心的自动根据 serviceId 创建路由的功能。eureka.client.service-url.defaultZone
指定注册中心的地址,以便使用服务发现功能
修改完成后启动 gateway-server-eureka 项目,访问注册中心地址 http://localhost:8000/
即可看到名为 GATEWAY-SERVER-EUREKA
的服务。
4.program
package com.smile; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
public class GatewayServerEurekaApplication { public static void main(String[] args) {
SpringApplication.run(GatewayServerEurekaApplication.class, args);
} }
5.Run
开启之后我们就可以通过地址去访问服务了,格式如下:
http://网关地址/服务名称(大写)/**
http://localhost:8084/FSH-HOUSE/house/1
这个大写的名称还是有很大的影响,如果我们从Zull升级到Spring Cloud Gateway的话意味着请求地址有改变,或者重新配置每个服务的路由地址,通过源码我发现可以做到兼容处理,再增加一个配置即可:
spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true
配置完成之后我们就可以通过小写的服务名称进行访问了,如下:
http://网关地址/服务名称(小写)/**
http://localhost:8084/fsh-house/house/1
启动producer,producer-1
在浏览器多次访问地址:http://localhost:8080/PRODUCER/getHello?name=xx
,页面交替返回以下信息:
hello xx
hello xx,this is producer 1
说明后端服务自动进行了均衡负载。
spring cloud:gateway-eureka的更多相关文章
- Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用
Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...
- Spring Cloud Gateway整合Eureka
Spring Cloud Gateway features: Built on Spring Framework 5, Project Reactor and Spring Boot 2.0 Able ...
- SpringCloud无废话入门05:Spring Cloud Gateway路由、filter、熔断
1.什么是路由网关 截至目前为止的例子中,我们创建了一个service,叫做:HelloService,然后我们把它部署到了两台服务器(即提供了两个provider),然后我们又使用ribbon将其做 ...
- 网关服务Spring Cloud Gateway(二)
上一篇文章服务网关 Spring Cloud GateWay 初级篇,介绍了 Spring Cloud Gateway 的相关术语.技术原理,以及如何快速使用 Spring Cloud Gateway ...
- API网关性能比较:NGINX vs. ZUUL vs. Spring Cloud Gateway vs. Linkerd API 网关出现的原因
API网关性能比较:NGINX vs. ZUUL vs. Spring Cloud Gateway vs. Linkerd http://www.infoq.com/cn/articles/compa ...
- Spring Cloud Gateway VS Zuul 比较,怎么选择?
Spring Cloud Gateway 是 Spring Cloud Finchley 版推出来的新组件,用来代替服务网关:Zuul. 那 Spring Cloud Gateway 和 Zuul 都 ...
- .net core下,Ocelot网关与Spring Cloud Gateway网关的对比测试
有感于 myzony 发布的 针对 Ocelot 网关的性能测试 ,并且公司下一步也需要对.net和java的应用做一定的整合,于是对Ocelot网关.Spring Cloud Gateway网关做个 ...
- Spring Cloud Gateway使用
简介 Spring Cloud Gateway是Spring Cloud官方推出的网关框架,网关作为流量入口,在微服务系统中有着十分重要的作用,常用功能包括:鉴权.路由转发.熔断.限流等. Sprin ...
- 微服务网关 Spring Cloud Gateway
1. 为什么是Spring Cloud Gateway 一句话,Spring Cloud已经放弃Netflix Zuul了.现在Spring Cloud中引用的还是Zuul 1.x版本,而这个版本是 ...
- 跟我学SpringCloud | 第十三篇:Spring Cloud Gateway服务化和过滤器
SpringCloud系列教程 | 第十三篇:Spring Cloud Gateway服务化和过滤器 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich. ...
随机推荐
- 第一次参赛经历:ecfinal总结
刚接到要去参加ec的消息时,还是非常激动的,毕竟第一次参赛就参加如此高水平的编程竞赛(更高水平的比赛就是wf). 教练临时组队,把三个从没在一起打过比赛的三个人组成一队,当时有点担心默契和配合上的问题 ...
- c语言中宏定义#和 ##的作用:
转载:http://www.cnblogs.com/cyttina/archive/2013/05/11/3072969.html 看了这篇文章后了解了,但是文章中的例子比较特别,我在这里加个注释好了 ...
- 3-app应用操作——Models.py和字段类型
Models.py定义 每一个数据表对应一个model定义,model之间和java一样可以相互之间继承.所有的model都必须继承 from django.db import models#或间接继 ...
- python-day1(学前了解)
Markdown基本语法 各级标题 # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 加粗 **加粗文本** 斜体 *我斜了* 高亮 ==我高亮了== 上标 2 ...
- springboot项目抓数据后优化配置及四个补充
昨天搞了一个抓取某某平台信息的抓取功能,其中有一个地址url,昨天是写死的,之前也进行配置过,印象有些模糊,今天想配置一下,在properties文件中,由此引发了下面的一系列总结操作: 1.原始模式 ...
- Eclipse 配置 tomcat
1.第一步 去官网下载 进入点击 Downloads 点击如图位置下载 我下载的是 apache-tomcat-7.0.82.zip(图片中不是,但都是一样的) 我解压到D:\tomcat\apach ...
- MySQL查询最近一周(最近7天)数据
参考:https://blog.csdn.net/ouyang111222/article/details/77638826 -表结构 - CREATE TABLE `zk_score` ( `id` ...
- python实现策略模式
python实现策略模式 原文地址 1.策略模式概述 策略模式:定义一系列算法,把它们一一封装起来,并且使它们之间可以相互替换.此模式让算法的变化不会影响到使用算法的客户. 电商领域有个使用“策略”模 ...
- SourceTree报错
1.SourceTree 拉取报错 Your local changes to the following files would be overwritten by merge:XXX 原因: 本 ...
- Apple历史应用以及开发工具版本(Xcode官方历史版本等等)
1.Xcode 官方历史版本下载:(需要登录开发者账号) https://developer.apple.com/download/more/