技术标签: SpringClound
上一篇,讲了SpringClound中的消费者采用织带+休息来实现,这回我们用组件Feign来实现服务的消费者,Fegin中也是默认集成了Ribbon的;和Eureka结合也能实现负载均衡;
概括来说,Fegin的区别就是基于注解来实现,具备可插拔的特性;
一,项目准备
这回我们要用的项目工程依然用Eureka,service-hello(一个项目,注册两个实例)
二,创建Fegin项目;
同样的我们创建一个SpringBoot的Model,命名service-fegin;
pom依赖如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.RC1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
properties配置如下;
#服务端口 server.port=8885 #注册服务中心地址 eureka.client.service-url.defaultZone=http://localhost:8880/eureka/ #注册服务名 spring.application.name=service-feign
启动类如下:
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients //开启Feign的功能: public class FeginApplication { public static void main(String[] args) { SpringApplication.run(FeginApplication.class, args); } }
然后我们定义一个fegin的接口,在这个接口中我们通过@ FeignClient(“服务名”)来实现消费服务提供者;
//代表改接口用费"service-hello"的服务 提供 @FeignClient(value = "service-hello") public interface FeginService { @RequestMapping(value = "/hello") String sayHelloFromService(); }
我们再在fegin项目中暴露一个访问接口,controller;
@RestController public class FeginController { @Autowired private FeginService feginService; @RequestMapping("hello") public String helloFegin(){ return feginService.sayHelloFromService(); } }
代码基本编写完成,下面我们来启动项目;Eureka,service-hello(两个实例),最后启动service-fegin;
然后后我们访问service-fegin的接口,结果如下;刷新页面;
看到我们访问fegin的接口,会去轮询调用service-hello的两个不同实例;来实现服务的消费者;
@pytest.fixture 装饰器被 @pytest.fixture 装饰器装饰的方法名可以作为一个参数传入测试方法中作用① 使用此方法可以完成测试之前的初始化② 此方法可以返回数据给测试函数@pytest.mark.parametrize 装饰器pytest 中使用此装饰器进行参数化@pytest.fixture 与@pytest.mark.parametrize 结合实现参数化如果测试数据需要在 fixture 方法中使用,同事也需要在用例中使用,可以让 parametrize 的 [email protected][email protected]
function printsum(a) # summary generates a summary of an object println(summary(a), ": ", repr(a))end# repeat can be useful to expand a gridm1 = hcat(repeat([1,2], inner=[1], outer=[3*2])...
effective花了大概两周的时间通读了一下《effective stl》这本书,总结一下,对于经常用STL容器的人来说,这本书还是值得一读,特别是常用STL,但确没全面了解过STL的人来讲。具体来讲,同一种功能可能有很多种实现,比如最简单使有for_each替代手写循环,很简单的经验之淡,但是对stl不熟的人可能会惊讶,C++也有for_each函数吗?(哈哈,我就是这种)下面着重讲几条个..._effective stl
随着大数据时代,人工智能时代的到来,深度学习的应用越来越广,场景识别、目标检测、人脸识别、图像识别等等广泛应用。在人工智能方面。深度学习框架主要运用于python,c++等资源。而易语言使用深度学习框架的资料,源码缺十分稀少。于是我决定给大家录制一套易语言深度学习的教程。本套教程基于我自己开发的CC框架,下面这些图片案例,就是深度学习做的效果,非常棒:人脸识
目录1. 题目描述2. 解题思路3. 代码实现3.1 遍历两次3.2 遍历一次(数组记忆)3.3 遍历一次(双指针)3.4 对比1. 题目描述2. 解题思路好久没有碰到过这么简单的中等题了,本渣渣大喜!!!言归正传,这道题的常规思路应该是很简单的,遍历两次,第一次算出链表长度,第二次遍历到目标节点的前驱节点即可完成删除操作了。但是嘛,题目叫我尝试用一次遍历,那就试一下吧!既然我要省掉一次那显然是省第二遍了,怎么省呢?用一个带下标的数组存储所有的节点,那样在计算找到目标节点时候就可以直接从数组中取出_leetcode19 java
什么叫自动化测试? 答:自动化测试可以让测试人员从枯燥无味的手工重复性测试中解放出来,并且提高工作效率,通过自动化测试结果分析功能和性能上的缺陷。描述一个测试结束的准则。 答:一个测试结束的标准可以查看已提交的bug是否已经全部解决并已验证关闭,一般来说,bug验证率在95%以上,并且没有大的影响功能的bug处于未解决状态,就可以测试通过。在一个测试计划中能包含哪些内容,如可用的人力资源?
最近在做angular1的项目,angular中可以用directive使得代码模块化,便于统一的修改维护,整个代码结构也瞬间清晰起来。在开发的过程中模块化的代码也会有不同的属性需求。好在在网上发现一位前辈总结的关于directive的总结,感觉写的不错,故转载之。一,angularjs directive的常用格式,以及参数说明1.直接return var p
http://sigechuizi.cn/article/133_c# datagridview合并单元格
一、前言最近几天都在搞Lyx相关的事情,都快把我搞烦了,终于差不多搞好了。二、配置texLive环境参见本人的另一篇博文: http://blog.csdn.net/qq_33429968/article/details/62928742三、安装Lyx安装版本要求为2.2.x,即2.2版本以上的版本。 安装方法一: 使用命令: sudo apt-get install lyx安装方法二:
{写在前面:按照这个方法,基本可以成功在linux系统下交叉编译Qt5.12.3,其他版本的源码也编译}我的环境:Linux Mint 19.1;树莓派 3;Qt源码5.12.3步骤1:安装linux Mint,具体网址https://www.linuxmint.com/download.php 安装树莓派系统 ,具体网址https://www.raspberr..._sysroot-relativelinks.py
过渡1定义:css3过渡是元素从一种样式逐渐改变为另一种样式的效果过渡必须有触发事件 eg:鼠标悬停、鼠标点击等(过渡后什么样写在这里)2语法:过渡transition是一个复合属性,包括(1)transition-property: ;(规定应用过渡的属性的名称) 必须有 可以简写为all可以过渡的属性:①取值为颜色 如背景颜色 字体颜色 阴影颜色②取值为数值③转换 transform④阴影 box-shadow:; text-shadow:;⑤背景渐变(2)t..._雪碧图序列帧
今天在Ubuntu20.04系统中配置ROS的时候一直提示E:无法定位软件包,后来发现是ROS的版本不对应导致的,每个不同的ubuntu系统对应着不同的ROS版本,如果装错了就会出现上述问题,安装教程可以参考官网安装教程,ROS有Melodic、Lunar、Kinetic不同的种类对应着不同的ubuntu版本,Melodic 主要对应:Ubuntu Artful (17.10), Bionic (18.04 LTS) 以及Debian StretchKinetic 主要对应:Ubuntu Wily (1