内容简介:Feign集成了Ribbon,让客户端具有负载均衡的能力,同时简化了开发github地址:https://github.com/erlieStar/spring-cloud-learning1.项目配置如下
Feign集成了Ribbon,让客户端具有负载均衡的能力,同时简化了开发
github地址:https://github.com/erlieStar/spring-cloud-learning
1.项目配置如下
pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
application.yaml
server:
port: 9001
spring:
application:
name: consumer-feign
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
2.启动类加上@EnableFeignClients注解开启Feign的功能
3.定义接口,通过@FeignClient(服务名)来指定调用哪个服务
@RestController
@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
public class ConsumerFeign {
public static void main(String[] args) {
SpringApplication.run(ConsumerFeign.class);
}
@Autowired
private SimpleClient simpleClient;
@FeignClient(value = "producer-simple")
public interface SimpleClient {
@RequestMapping("hello")
String hello(@RequestParam String name);
}
@RequestMapping("hello")
public String hello(@RequestParam String name) {
return simpleClient.hello(name);
}
}
启动eureka-service(spring-cloud-eureka)
接着启动2个producer-simple(spring-cloud-ribbon)
初始端口为8001,启动一个实例后,修改端口为8002,再启动一个实例
访问http://localhost:9001/hello?name=xiaoshi
交替显示
hello xiaoshi, I am from port: 8001 hello xiaoshi, I am from port: 8002
欢迎关注
参考博客
[1]https://www.fangzhipeng.com/springcloud/2018/08/03/sc-f3-feign.html
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Spring Cloud实战系列(三) - 声明式客户端调用Feign
- Oracle报存储过程中调用DBLink同义词出现错误:PLS-00201: 必须声明标识符
- JS变量声明和函数声明提升
- JavaScript声明变量详解
- javascript的变量声明
- Go - 变量声明
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
高分辨率遥感卫星应用
张永 / 科学分社 / 2004-1 / 48.00元
高分辨率遥感卫星应用(成像模型处理算法及应用技术),ISBN:9787030128249,作者:张永生等著一起来看看 《高分辨率遥感卫星应用》 这本书的介绍吧!