Spring Cloud:第五章:Zuul服务网关
快速入门
定义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加入依赖:
<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
相关文章
- 防止内卷和被潜规则,Spring Cloud Alibaba微服务架构实战派(上下册)|35岁程序员那些事
- 深度剖析Spring Cloud Alibaba系列——适配Spring Cloud和Nacos的服务元数据
- spring cloud和dubbo的主要区别[通俗易懂]
- Spring Cloud核心组件详解
- 在Spring Cloud 中使用Zipkin
- Spring Cloud:第六章:Config分布式配置
- Spring Cloud 的微服务架构学习及实践(十七)
- Spring Cloud 的微服务架构学习及实践(十八)
- Spring Cloud Gateway微服务网关
- 微服务框架之Spring Cloud 学习
- 手把手教你,从零开始搭建Spring Cloud Alibaba!这份笔记太牛了
- 使用Spring Cloud Feign实现微服务的负载均衡(二)
- Spring Cloud Gateway路由规则的匹配和优先级(一)
- Spring Cloud Gateway 的调试
- Spring Cloud Stream 高级特性-消息桥接(二)
- Spring Cloud Stream 高级特性-消息拦截器
- Spring Cloud Security进行基于角色的访问控制
- Spring Cloud LoadBalancer 的高级特性-服务实例过滤器(二)
- 配置Spring Cloud Bus并集成消息代理
- Spring Cloud Bus在服务之间传递自定义事件(一)
- Spring Cloud Bus集成Spring Cloud Config Server实现全局配置的自动刷新(一)
- 整合spring cloud云服务架构 – 企业分布式微服务云架构构建详解架构师
- spring cloud 之 Feign 使用HTTP请求远程服务详解架构师
- Spring Cloud分布式微服务系统中利用redssion实现分布式锁详解编程语言