关于雪崩效应:

默认情况下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. HDU-1165-Eddy&#39;s research II

    这个事实上是一个递归题.题目非常easy.m的数非常小.分三种情况.算一下.就能够直接把公式算出来. 当然,也能够用dp做: #include<iostream> #include< ...

  2. Python内置函数之range()

    range(stop)range(start,stop[,step]) 返回一个range对象,第三个参数的含义为:间隔的个数. range对象同时也是可迭代对象. >>> isin ...

  3. lua学习笔记(八)

      元表与元方法  基本概念         1.lua中每个值都有一个元表         2.table和userdata可以有各自独立的元表         3.其它类型的值共享其类型所属的单一 ...

  4. 基于java spring框架开发部标1078视频监控平台精华文章索引

    部标1078视频监控平台,是一个庞杂的工程,涵盖了多层协议,部标jt808,jt809,jt1078,苏标Adas协议等,多个平台功能标准,部标796标准,部标1077标准和苏标主动安全标准,视频方面 ...

  5. Crashing Robots - poj 2632

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8352   Accepted: 3613 Description In ...

  6. MIC中函数和变量的声明

    c++/c使用 __declspec(target(mic))函数或变量声明 或 __attribute__((target(mic)))函数或变量声明 举例如下: __attribute__((ta ...

  7. php编译参数选项 具体参数含义可以用./configure --help来查看

    php编译参数选项  PHP_INSTALL_PATH=/data/web/php MYSQL_INSTALL_PATH=/data/web/mysql ./configure --prefix=${ ...

  8. 旋转卡壳求两个凸包最近距离poj3608

    #include <iostream> #include <cmath> #include <vector> #include <string.h> # ...

  9. Spring 定时作业

    Spring定时任务的几种实现   近日项目开发中需要执行一些定时任务,比如需要在每天凌晨时候,分析一次前一天的日志信息,借此机会整理了一下定时任务的几种实现方式,由于项目采用spring框架,所以我 ...

  10. ubuntu14.04 desktop 32-bit kvm装windows xp

    经过这几天来的折腾,总算是在ubuntu14.04用kvm装上了xp, 看不少的的贴,也绕了不少的圈,总的来说,非常感谢CSDN上的"上善若水75",看着他写的一个分类" ...