基于SpringCloudAlibaba和Nacos微服务体系下的FeignClient客户端负载均衡入门实例


声明:本文转载自https://my.oschina.net/g4studio/blog/3125353,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

本文主要介绍在SpringCloudAlibaba和Nacos微服务框架下,使用openfeign的FeignClient实现客户端负载均衡的效果。关于服务提供者和服务消费者的程序请直接查阅这篇文章。基于SpringCloudAlibaba和Nacos构建微服务入门实例

OpenFeign简介

Feign is a Java to HTTP client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal was reducing the complexity of binding Denominator uniformly to HTTP APIs regardless of ReSTfulness.

打包服务提供者程序

基于SpringCloudAlibaba和Nacos构建微服务入门实例中的服务提供者程序打包输出:myclouds-nacos-discovery-provider-example-3.0.0.jar。

启动2个服务提供者实例

java -jar myclouds-nacos-discovery-provider-example-3.0.0.jar --server.port=18000
java -jar myclouds-nacos-discovery-provider-example-3.0.0.jar --server.port=18001

启动服务消费者程序

基于SpringCloudAlibaba和Nacos构建微服务入门实例中的服务提供者程序打包输出:myclouds-nacos-discovery-consumer-example-3.0.0.jar。

java -jar myclouds-nacos-discovery-consumer-example-3.0.0.jar --server.port=18000

查看Nacos服务状态

验证负载均衡效果

请求http://127.0.0.1:19000/bankcard/findCardInfo?cardNo=5301001,查看服务提供者控制台。

小结

springcloudalibaba下feignclient的负载均衡实现也是依赖netflix-ribbon。在spring-cloud-starter-alibaba-nacos-discovery pom中对其进行了依赖spring-cloud-starter-netflix-ribbon。

写在最后

完整实例代码请访问我的myclouds代码仓库。https://gitee.com/osworks/myclouds

本文发表于2019年11月04日 10:00
(c)注:本文转载自https://my.oschina.net/g4studio/blog/3125353,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2666 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1