首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >将网关注册到”服务中心”,实现服务转发

将网关注册到”服务中心”,实现服务转发

作者头像
星哥玩云
发布2022-09-15 14:21:22
发布2022-09-15 14:21:22
8730
举报
文章被收录于专栏:开源部署开源部署

1、将网关注册到"服务中心",实现服务转发

Spring Cloud Gateway提供了一种默认的转发功能,当网关被注册到"服务中心"后,网关会代理"服务中心"转发服务。

1.1、新建工程,添加依赖

代码语言:javascript
复制
        <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>

1.2、添加配置

代码语言:javascript
复制
spring.application.name=gateway-eureka
server.port=50024
#注册中心地址
eureka.client.register-with-eureka=false
#eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://eureka01:50025/eureka/,http://eureka02:50026//eureka/
#表示是否与"服务中心"的发现组件进行结合
spring.cloud.gateway.discovery.locator.enabled=true

1.3、测试配置

步骤:

1、启动"服务中心"

2、启动服务提供者

3、启动网关工程

4、访问http://localhost:50024/PROVIDER1/hello

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、将网关注册到"服务中心",实现服务转发
    • 1.1、新建工程,添加依赖
    • 1.2、添加配置
    • 1.3、测试配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档