springcloud入门基础搭建之zuul

这篇博客介绍了如何在Spring Cloud中搭建Zuul网关,从单机使用到集群配置,包括依赖、配置文件设置、自定义过滤器,并通过Nginx实现了负载均衡。
摘要由CSDN通过智能技术生成

目录

1.工程目录

 2.单机使用

2.1依赖

2.2配置文件

2.3主启动类添加@EnableZuulProxy

2.4测试

 3.集群配置

3.1nginx配置

 3.2新建第二个zuul服务

3.3测试

 4.自定义过滤器

传送门


1.工程目录

 2.单机使用

2.1依赖

        zuul网关本身也是一个微服务,需要注册到eureka中,完整依赖如下。

        版本在父项目中统一定义

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
			<exclusions>
				<exclusion>
					<groupId>javax.servlet</groupId>
					<artifactId>servlet-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
		</dependency>
	</dependencies>

2.2配置文件

proxy-1为代理名称

/proxy-1/**为代理请求路径(此类型路径会被代理)

serviceId为代理服务名称,注册在eureka中的服务名称

spring:
  application:
    name: springcloud-zuul
        
server:
  port: 9410

eureka:
  instance:
    instance-id: springcloud-zuul1
    appname: ${spring.application.name}
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 5
  client:
    service-url:
      defaultZone: http://test1:9110/eureka/,http://test2:9120/eureka/

  
zuul:
  routes:
    proxy-1: 
      path: /proxy-1/**
      serviceId: springcloud-common      

    
    

2.3主启动类添加@EnableZuulProxy

@SpringBootApplication
@EnableEurekaClie
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值