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. Luogu P4602 [CTSC2018]混合果汁

    题目 把果汁按美味度降序排序,以单价为下标插入主席树,记录每个节点的\(sum\)果汁升数和\(val\)果汁总价. 每次询问二分最小美味度,查询美味度大于等于\(mid\)的总体积为\(L\)的最低 ...

  2. Codeforces 1215F. Radio Stations

    传送门 题目看一半:"woc 裸的 $2-sat$ 白给??" 看完以后:"...???" 如果没有 $f$ 的限制,那就是个白给的 $2-sat$ 问题,但是 ...

  3. java集合之 ConcurrentHashMap的产生

    ConcurrentHashMap:  在java集合中 最常用的是ArrayList 效率最高的还是HashMap 但是线程不安全   HashTable是线程安全的(里面的方法是同步方法) 但相比 ...

  4. 一、JS基本基础

    一.主流编辑器 早期 atom    前几年sublime    小巧,轻量,功能插件较多:  webstorm 集成开发环境 vscode 免费开源的. 运行环境  : 浏览器端  谷歌,IE,fi ...

  5. openapi

    https://www.breakyizhan.com/swagger/2810.html https://www.cnblogs.com/serious1529/p/9318115.html htt ...

  6. 银联支付SDK集成

    下载地址 https://open.unionpay.com/upload/download/Development_kit85427986.rar其实我找了半个小时 也不知道怎么就下载好了 这个我在 ...

  7. zencart产品批量采集伪原创方法,再也不用担心与别人的数据重复了

    首先,请你提供与产品相关的关键词一份,至于关键词如何来,相信做SEO的你很清楚了,SEO关键词搜索工具应该很多,比如谷歌相关关键词搜索,用记事本的形式保存为每行一个关键词.采集产品的时候,我会帮你将关 ...

  8. AD使用adsi 组件 获取域信息

    // testadsi.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include "windows.h"#inclu ...

  9. ng-model 和ng-bind的区别

    也就是说 ng-model是绑定html输入的值-->到控制器的变量,输入值变了,控制器对应的变量message的值页变了,这样,在其他地方就可以使用这个变化后的值 ng-bind 是绑定控制器 ...

  10. Python 函数Ⅲ

    默认参数 调用函数时,默认参数的值如果没有传入,则被认为是默认值.下例会打印默认的age,如果age没有被传入: 以上实例输出结果: 不定长参数 你可能需要一个函数能处理比当初声明时更多的参数.这些参 ...