版权声明:本文为博主原创文章,未经博主允许不得转载。否则切鸡鸡~~ https://blog.csdn.net/kang5789/article/details/83024427
传统项目我们使用nginx做负载均衡,在springcloud里zuul相当于nginx,网上一些文章说zuul的原始性能接近nginx。
maven依赖:
修改启动类,增加注解@EnableZuulProxy
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@EnableZuulProxy
@SpringBootApplication
public class ApiZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ApiZuulApplication.class, args);
}
}
配置
spring.application.name=api-zuul
server.port=4001
eureka.client.serviceUrl.defaultZone=http://www.eureka1.com:1001/eureka,http://www.eureka2.com:1002/eureka
启动
比如通过路由访问之前的hello方法:http://localhost:4001/eureka-feign/hello (之前:http://localhost:3001/hello)
相当于 : 路由url + eureka服务名称 +方法名
观察postman
扫描二维码关注公众号,回复:
4958537 查看本文章
可以看到通过zuul发起的请求已经做了负载均衡