关于雪崩效应:

默认情况下tomcat只有一个线程去处理客户端发送的所有请求。高并发情况下,如果客户端请求都在同一接口,tomcat的所有线程池去处理,导致其他接口服务访问不了,等待。

Tomcat有个线程池,每个线程去处理客户端发送每次请求。

在parent项目里面再创建一个项目,common

Eureka server: 略

Member :

service

package com.toov5.api.entity;

import lombok.Data;

@Data
public class UserEntity {
private String name;
private Integer age; }
package com.toov5.api.service;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import com.toov5.api.entity.UserEntity;
import com.toov5.base.ResponseBase; @RestController
public interface IMemberService { @RequestMapping("/getMember") //接口加@RequestMapping 被其他项目调用时候 feign客户端可以继承
public UserEntity getMember(@RequestParam("name") String name); @RequestMapping("/getUserInfo")
public ResponseBase getUserInfo(); }

实现类:

package com.toov5.api.service.impl;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import com.toov5.api.entity.UserEntity;
import com.toov5.api.service.IMemberService;
import com.toov5.base.BaseApiService;
import com.toov5.base.ResponseBase; //注意加在实现类上面!!! 接口不能加 接口不能被实例化
@RestController
public class MemberServiceImpl extends BaseApiService implements IMemberService { @RequestMapping("/getMember")
public UserEntity getMember(@RequestParam("name") String name) {
UserEntity userEntity = new UserEntity();
userEntity.setName(name);
userEntity.setAge(10);
return userEntity;
} @RequestMapping("/getUserInfo")
public ResponseBase getUserInfo() {
try {
Thread.sleep(1500);
} catch (Exception e) { }
return setResultSuccess("订单服务接口调用会员服务接口成功....");
} }

启动类

package com.toov5.api.service.impl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication (scanBasePackages={"com.toov5.*"})
@EnableEurekaClient
@EnableFeignClients
public class AppMember {
public static void main(String[] args) {
SpringApplication.run(AppMember.class, args);
}
}

yml

###服务启动端口号
server:
port: 8000
###服务名称(服务注册到eureka名称)
spring:
application:
name: app-toov5-member
###服务注册到eureka地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka ###因为该应用为注册中心,不会注册自己
register-with-eureka: true
###是否需要从eureka上获取注册信息
fetch-registry: true

 pom:

<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>
<parent>
<groupId>com.toov5</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>toov5-api-member-service-impl</artifactId> <dependencies>
<dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5-api-member-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5-api-order-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies> </project>

Order:

service

pom:

<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>
<parent>
<groupId>com.toov5</groupId>
<artifactId>toov5-api-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>toov5-api-order-service</artifactId>
<dependencies>
<dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5.common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependencies>
</project>

 接口

package com.toov5.api.service;

import org.springframework.web.bind.annotation.RequestMapping;

import com.toov5.base.ResponseBase;

public interface IOrderService {
//订单服务带哦用会员服务接口信息fegin
@RequestMapping("/orderToMember")
public String orderToMember(String name); //订单服务接口调用会员服务接口
@RequestMapping("/orderToMemberUserInfo")
public ResponseBase orderToMemberUserInfo(); }

 

pom:

<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>
<parent>
<groupId>com.toov5</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>toov5-api-order-service-impl</artifactId> <dependencies>
<dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5-api-order-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5-api-member-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies> </project>

  

package com.toov5.api.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.toov5.api.entity.UserEntity;
import com.toov5.api.feign.MemberServiceFeign;
import com.toov5.api.service.IOrderService;
import com.toov5.base.ResponseBase; @RestController
public class OrderServiceImpl implements IOrderService {
@Autowired
private MemberServiceFeign memberServiceFeign; @RequestMapping("/orderToMmeber")
public String orderToMember(String name) {
UserEntity user = memberServiceFeign.getMember(name);
return user==null ? "没有找到用户先关信息" : user.toString();
} @RequestMapping("/orderToMemberUserInfo")
public ResponseBase orderToMemberUserInfo() {
return memberServiceFeign.getUserInfo();
}
}
package com.toov5.api.feign;

import org.springframework.cloud.openfeign.FeignClient;

import com.toov5.api.service.IMemberService;
//避免了冗余代码 直接过来就ok了
@FeignClient("app-toov5-member")
public interface MemberServiceFeign extends IMemberService {
//实体类是存放接口项目还是存放在实现项目 实体类存放在接口项目里面
//实体类和定义接口信息存放在接口项目
//代码实现放在接口实现类里面
}

yml:

###服务启动端口号
server:
port: 8001
###服务名称(服务注册到eureka名称)
spring:
application:
name: app-toov5-order
###服务注册到eureka地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka ###因为该应用为注册中心,不会注册自己
register-with-eureka: true
###是否需要从eureka上获取注册信息
fetch-registry: true ###设置feign客户端超时时间
ribbon:
###指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间。
ReadTimeout: 5000
###指的是建立连接后从服务器读取到可用资源所用的时间。
ConnectTimeout: 5000
#spring cloud 默认开启ribbon

  

 启动类

package com.toov5.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication(scanBasePackages={"com.toov5.*"})
@EnableEurekaClient
@EnableFeignClients
public class AppOrder {
public static void main(String[] args) {
SpringApplication.run(AppOrder.class, args);
}
}

 结果:

 

Spring Cloud之Feign客户端超时时间配置的更多相关文章

  1. Spring Cloud之Feign客户端调用工具

    feign介绍 Feign客户端是一个web声明式http远程调用工具,提供了接口和注解方式进行调用. Spring Cloud 支持 RestTemplate  Fetin Feign客户端实际开发 ...

  2. hystrix ,feign,ribbon的超时时间配置,以及原理分析

    背景,网上看到很多关于hystrix的配置都是没生效的,如: 一.先看测试环境搭建: order 服务通过feign 的方式调用了product 服务的getProductInfo 接口 //---- ...

  3. Spring Cloud(十四)Config 配置中心与客户端的使用与详细

    前言 在上一篇 文章 中我们直接用了本应在本文中配置的Config Server,对Config也有了一个基本的认识,即 Spring Cloud Config 是一种用来动态获取Git.SVN.本地 ...

  4. spring cloud 使用feign 遇到问题

    spring cloud 使用feign 项目的搭建 在这里就不写了,本文主要讲解在使用过程中遇到的问题以及解决办法 1:示例 @RequestMapping(value = "/gener ...

  5. Spring Cloud Alibaba基础教程:Nacos配置的加载规则详解

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式(Res ...

  6. Spring Cloud Config、Apollo、Nacos配置中心选型及对比

    Spring Cloud Config.Apollo.Nacos配置中心选型及对比 1.Nacos 1.1 Nacos主要提供以下四大功能 2.Spring Cloud Config 3.Apollo ...

  7. Spring Cloud 整合 Feign 的原理

    前言 在 上篇 介绍了 Feign 的核心实现原理,在文末也提到了会再介绍其和 Spring Cloud 的整合原理,Spring 具有很强的扩展性,会把一些常用的解决方案通过 starter 的方式 ...

  8. Spring Cloud Alibaba基础教程:Nacos配置的多环境管理

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...

  9. spring cloud(四) feign

    spring cloud 使用feign进行服务间调用 1. 新建boot工程 pom引入依赖 <dependency> <groupId>org.springframewor ...

随机推荐

  1. firewalld那些事

    FirewallD 提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具.它支持 IPv4, IPv6 防火墙设置以及以太网桥接,并且拥有运行时配置和永久配置选项.它 ...

  2. HTML css样式

    clear: both清除左侧和右侧浮动 status: 变量状态参数,该属性有5个常用值count 表示当前遍历集合的元素个数index 表示当前遍历到集合的第几个元素current 表示当前的集合 ...

  3. JS 正则 钱

    function ValidateIsDecial(sValue) { return (!sValue && !!!sValue && /^[0-9]{1,10}(\. ...

  4. docker与虚拟化的联系与区别

    虚拟化技术是一个总称,是一系列实现虚拟技术的统称.从广义上来说,虚拟化技术包括了虚拟机技术和容器技术, 所谓虚拟化技术最大的特点就是将一个真实的机器进行虚拟地分割,然后分割出来的部分可以独立使用   ...

  5. python在windows系统中打印中文乱码

    转自:http://www.111cn.net/phper/python/58920.htm 中文乱码对于程序开发人员来讲不是什么怪事情了,今天我在使用python打印中文时就出现乱码了,下面我们一起 ...

  6. 编写一个基于HBase的MR程序,结果遇到一个错:ERROR security.UserGroupInformation - PriviledgedActionException as ,求帮助

    环境说明:Ubuntu12.04,使用CDH4.5,伪分布式环境 Hadoop配置如下: core-site.xml: <configuration><property>    ...

  7. android开发中遇到的问题汇总【九】

    244.http请求的url含有中字符时.须要Uri编码.Uri.encoder() 245.使用androidstudio时,不知道什么原因svn不见了 Android Studio missing ...

  8. 第三篇:Logstash 安装配置

    Logstash 简介: Logstash 是一个实时数据收集引擎,可收集各类型数据并对其进行分析,过滤和归纳.按照自己条件分析过滤出符合数据导入到可视化界面.Logstash 建议使用java1.8 ...

  9. linux用一键安装包 禅道

    ----------------1.重启apache 和 mysql /opt/zbox/zbox restart -----------------2.问题1:发现端口被占用 apache启动报错( ...

  10. Ubuntu下VirtualBox虚拟机与主机机互相ping通的简单配置心得

    virtualbox 是个非常优秀的软件,通常与主机之间有3种方式,Bridged方式,NAT方式,host-only方式,安装的默认方式是NAT,可是这样的方式在virtualbox虚拟机下有个缺点 ...