1.Feign声明式服务调用(负载均衡+熔断器)

  a.概念:Feign是一个声明式的Web Service客户端,它的目的就是让Web Service调用更加简单。Feign整合了Ribbon和Hystrix。

  b.新建springboot项目,依赖选择 Eureka Discovery 、Web 以及 Feign

  c.pom文件关键依赖

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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> ...... </dependencies> ......

  d.application.yml文件

spring:
application:
name: eureka-client-feign
server:
port: 8086 eureka:
client:
service-url:
defaultZone: http://localhost:8081/eureka/

  c.启动类添加注解 @EnableDiscoveryClient 和 @EnableFeignClients

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class EurekaClientFeignApplication { public static void main(String[] args) {
SpringApplication.run(EurekaClientFeignApplication.class, args);
} }

  d.创建接口调用服务

@FeignClient(value = "EUREKA-CLIENT-PRODUCER",fallback = FeignFallBack.class)
public interface FeignService { @RequestMapping(value = "/printProducer")
public String printProducer(@RequestParam("param") String param); }

  c.创建熔断器实现接口

@Component
public class FeignFallBack implements FeignService { @Override
public String printProducer(String param) {
return "连接消费服务失败,请求参数:" + param;
}
}

  d.具体使用

@RestController
public class CommonController { @Resource
FeignService feignService; @RequestMapping(value = "/print")
public String print(String param){
return feignService.printProducer(param);
} }

微服务框架——SpringCloud(二)的更多相关文章

  1. 微服务框架——SpringCloud

    1.SpringCloud微服务框架 a.概念:SpringCloud是基于SpringBoot的微服务框架 b.五大神兽:Eureka(服务发现).Ribbon(客服端负载均衡).Hystrix(断 ...

  2. 微服务框架SpringCloud(Dalston版)学习 (一):Eureka服务注册与发现

    eureka-server eureka服务端,提供服务的注册与发现,类似于zookeeper 新建spring-boot工程,pom依赖: <dependency> <groupI ...

  3. 微服务框架SpringCloud与Dubbo

    #v1.0.0# 1.背景 Dubbo,是阿里巴巴服务化治理的核心框架,并被广泛应用于阿里巴巴集团的各成员站点.阿里巴巴近几年对开源社区的贡献不论在国内还是国外都是引人注目的,比如:JStorm捐赠给 ...

  4. 微服务框架——SpringCloud(三)

    1.Zuul服务网关 作用:路由转发和过滤,将请求转发到微服务或拦截请求.Zuul默认集成了负载均衡功能. 2.Zuul实现路由 a.新建springboot项目,依赖选择 Eureka Discov ...

  5. 微服务框架学习二:Http调用

    1. HTTP接口的意义 二进制接口使用的是java/hessian序列化协议,不能很好的与其他语言通信,虽然hessian也是一种跨语言的通用协议,但很多语言没有很好的实现该协议的产品.所以为了能够 ...

  6. 微服务框架——SpringCloud(四)

    1.Spring Cloud Config 分布式配置 a.Config服务器 ①新建springboot项目,依赖选择Config Server ②pom文件关键依赖 <parent> ...

  7. springcolud 的学习(二).SpringCloud微服务框架

    为什么选择SpringCloud因为SpringCloud出现,对微服务技术提供了非常大的帮助,因为SpringCloud 提供了一套完整的微服务解决方案,不像其他框架只是解决了微服务中某个问题. 服 ...

  8. java框架之SpringCloud(1)-微服务及SpringCloud介绍

    微服务概述 是什么 业界大牛 Martin Fowler 这样描述微服务: 参考[微服务(Microservices)-微服务原作者Martin Flower博客翻译]. 下面是关于上述博客中的部分重 ...

  9. 【微服务】之二:从零开始,轻松搞定SpringCloud微服务系列--注册中心(一)

    微服务体系,有效解决项目庞大.互相依赖的问题.目前SpringCloud体系有强大的一整套针对微服务的解决方案.本文中,重点对微服务体系中的服务发现注册中心进行详细说明.本篇中的注册中心,采用Netf ...

随机推荐

  1. CentOS7_防火墙

    1.查看防火墙状态 firewall-cmd --state 2.启动防火墙 systemctl start firewalld.service 3.关闭防火墙 systemctl stop fire ...

  2. 一封来自恶魔的挑战邀请函,那些你见过或者没见过的C语言指针都在这里了

    前言 相信大多数的同学都是第一门能接触到语言是C/C++,其中的指针也是比较让人头疼的部分了,因为光是指针都能专门出一本叫<C和指针>的书籍,足见指针的强大.但如果不慎误用指针,这些指针很 ...

  3. NCE损失(Noise-Constrastive Estimation Loss)

    1.算法概述 假设X是从真实的数据(或语料库)中抽取的样本,其服从一个相对可参考的概率密度函数P(d),噪音样本Y服从概率密度函数为P(n),噪音对比估计(NCE)就是通过学习一个分类器把这两类样本区 ...

  4. JS 获取图片的base64编码

    获取图片的base64编码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  5. springboot springmvc拦截器 拦截POST、PUT、DELETE请求参数和响应数据,并记录操作日志

    1.操作日志实体类 @Document(collection = "operation_log") @Getter @Setter @ToString public class O ...

  6. 一些C++的语法

    一.类的析构函数 类的析构函数是类的一种特殊的成员函数,它会在每次删除所创建的对象时执行. 析构函数的名称与类的名称是完全相同的,只是在前面加了个波浪号(~)作为前缀,它不会返回任何值,也不能带有任何 ...

  7. PHP 【六】

    命名空间 教学网站的内容不知道再怎么“笔记化”,用之即可 面向对象 类定义 创建对象  $xxx = new 类名: 调用成员方法  $xxx->方法名(参数): 举例: <?php cl ...

  8. Linux启动activemq失败

    第一种情况: 在网上查找错误,通过./activemq console命令可以查看到activemq启动的错误信息,另外在data/activemq.log文件中可以查看到错误日志. java.io. ...

  9. npm vue ivew vue-cli3

    2019-4-10 10:56:20 星期三 学习iview时需要搭建一套node环境, 这里记录下来 1. 下载安装nodejs  //自带了npm包管理器 2. 设置npm的全局配置: 全局包默认 ...

  10. SQLAlchemy使用(三)搭配Flask框架使用

    前言 本章应该是SQLAlchemy使用系列的最后一篇了,本章简单讲一下如何搭配Flask使用.下一篇应该是写Flask_restful相关内容了 正文 我们简单使用前两章的model,两张表 # - ...