前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Cloud:第五章:Zuul服务网关

Spring Cloud:第五章:Zuul服务网关

作者头像
马克社区
发布2022-10-05 17:55:32
1270
发布2022-10-05 17:55:32
举报
文章被收录于专栏:高端IT

快速入门

定义user,order,pay服务,定义zull服务网关服务都注册到eureka服务上,

通过一下接口访问user,order,pay的服务,

http://localhost:7070/pay/index http://localhost:8080/user/index http://localhost:9090/order/index

定义服务网关服务zuul,我们看看其相关配置,zuul-service加入依赖:

代码语言:javascript
复制
 <dependencies>
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-zuul</artifactId>
         </dependency>
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-eureka</artifactId>
          </dependency>
    </dependencies>

1234567891011

配置文件:

spring: application: name: zuul-service eureka: client: service-url: defaultZone: http://localhost:8761/eureka instance: instance-id: s p r i n g . a p p l i c a t i o n . n a m e : {spring.application.name}: spring.application.name:{spring.cloud.client.ipAddress}:KaTeX parse error: Expected '}', got 'EOF' at end of input: …on.instance_id:{server.port}} prefer-ip-address: true server: port: 6069

定义启动类:

package com.zhihao.miao;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

//使用@EnableZuulProxy注解开启zuul的api网关服务功能 @SpringBootApplication @EnableZuulProxy public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class,args); } }

然后可以通过服务网关进行访问上面的三个服务接口,

http://localhost:6069/pay-service/pay/index http://localhost:6069/user-service/user/index http://localhost:6069/order-service/order/index

注意: 默认的zuul结合eureka会将注册到eureka的服务名作为访问的ContextPath。

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120382551

本文系转载,前往查看

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

本文系转载前往查看

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档