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的更多相关文章

  1. Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用

    Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...

  2. Spring Cloud Gateway整合Eureka

    Spring Cloud Gateway features: Built on Spring Framework 5, Project Reactor and Spring Boot 2.0 Able ...

  3. SpringCloud无废话入门05:Spring Cloud Gateway路由、filter、熔断

    1.什么是路由网关 截至目前为止的例子中,我们创建了一个service,叫做:HelloService,然后我们把它部署到了两台服务器(即提供了两个provider),然后我们又使用ribbon将其做 ...

  4. 网关服务Spring Cloud Gateway(二)

    上一篇文章服务网关 Spring Cloud GateWay 初级篇,介绍了 Spring Cloud Gateway 的相关术语.技术原理,以及如何快速使用 Spring Cloud Gateway ...

  5. 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 ...

  6. Spring Cloud Gateway VS Zuul 比较,怎么选择?

    Spring Cloud Gateway 是 Spring Cloud Finchley 版推出来的新组件,用来代替服务网关:Zuul. 那 Spring Cloud Gateway 和 Zuul 都 ...

  7. .net core下,Ocelot网关与Spring Cloud Gateway网关的对比测试

    有感于 myzony 发布的 针对 Ocelot 网关的性能测试 ,并且公司下一步也需要对.net和java的应用做一定的整合,于是对Ocelot网关.Spring Cloud Gateway网关做个 ...

  8. Spring Cloud Gateway使用

    简介 Spring Cloud Gateway是Spring Cloud官方推出的网关框架,网关作为流量入口,在微服务系统中有着十分重要的作用,常用功能包括:鉴权.路由转发.熔断.限流等. Sprin ...

  9. 微服务网关 Spring Cloud Gateway

    1.  为什么是Spring Cloud Gateway 一句话,Spring Cloud已经放弃Netflix Zuul了.现在Spring Cloud中引用的还是Zuul 1.x版本,而这个版本是 ...

  10. 跟我学SpringCloud | 第十三篇:Spring Cloud Gateway服务化和过滤器

    SpringCloud系列教程 | 第十三篇:Spring Cloud Gateway服务化和过滤器 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich. ...

随机推荐

  1. 搜索专题:问题 E: 挑战ACM迷宫

    这是往年校赛的一道题,最开始做这道题的时候还没有系统的学习过搜索,用了C语言学的回溯法尝试,毫无疑问的TLE: 学习了DFS之后,自己的剪枝功力不够,又是TLE,最后学了BFS之后,哇,终于做出来了, ...

  2. 双连通分量(点-双连通分量&边-双连通分量)

    概念: 双连通分量有点双连通分量和边双连通分量两种.若一个无向图中的去掉任意一个节点(一条边)都不会改变此图的连通性,即不存在割点(桥),则称作点(边)双连通图. 一个无向图中的每一个极大点(边)双连 ...

  3. python 3 :list

    2 List List中支持混合类型 number_list=[1,2,3,4,5] str_list = ["a","b","c",&qu ...

  4. 机器学习python常用模块

    .Pickle模块 打包,解压训练模型 .pysnooper 调试打印日志

  5. Electron 5.0 发布

    Electron 5.0的主要变化 打包应用程序现在的行为与默认应用程序相同.将创建一个默认的应用程序菜单(除非应用程序有一个),并且将自动处理全部关闭窗口的事件. (除非应用程序处理事件) 现在默认 ...

  6. 【转】Linux iptables 详解

    转自:https://www.cnblogs.com/qwertwwwe/p/9452370.html 最近搭一个框架需要用到iptables做映射,学习了下iptables的原理,总结下方便以后查~ ...

  7. 最简单的Android项目(添加jar文件)

    如果项目需要引用第三方jar文件,需要对编译命令做一些改动. 首先在项目根目录创建libs目录,将需要的jar文件拷贝到里面. 编译过程中有两步需要改动. 编译java源文件时,需要添加class p ...

  8. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  9. SpringBoot之模板引擎

    一.Thymeleaf 1.1 集成 templates 在 pom.xml 文件中添加依赖 <dependencies> ...... <dependency> <gr ...

  10. ps雨滴效果制作

    雨滴效果制作 尽量选择比较暗或者有人打伞的照片,方便制作雨天的效果 新建图层,设置前景色为黑色,并填充新建的图层为黑色 选择滤镜->杂色->添加杂色,数量设置为150左右(设置得越大后面的 ...