博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java spring cloud版b2b2c社交电商spring cloud分布式微服务-docker-feign-hystrix(六)
阅读量:6257 次
发布时间:2019-06-22

本文共 5959 字,大约阅读时间需要 19 分钟。

简介

springcloud电子商务社交平台源码请加企鹅求求:一零三八七七四六二六。上一节我们讨论feign的配置,这节我们讨论一下,feign+hystrix调用生产者时,进行容错处理。

一、创建模块(microservice-consumer-movie-feign-with-hystrix)

二、pom.xml文件

microservice-spring-cloud
com.jacky
1.0-SNAPSHOT
4.0.0
microservice-consumer-movie-feign-with-hystrix
jar
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-feign
org.springframework.cloud
spring-cloud-starter-hystrix
com.spotify
docker-maven-plugin
build-image
install
build
http://192.168.6.130:5678
true
${docker.repostory}/${docker.image.prefix}/${project.artifactId}:${project.version}
java:openjdk-8-jdk-alpine
["java", "-jar", "/${project.build.finalName}.jar"]
/
${project.build.directory}
${project.build.finalName}.jar

三、配置文件application.yml

spring:  application:    name: microservice-consumer-movie-feign-with-hystrixserver:  port: 7901eureka:  client:    healthcheck:      enabled: true    serviceUrl:      defaultZone: http://jacky:admin@peer1:8761/eureka/,http://jacky:admin@peer2:8762/eureka/,http://jacky:admin@peer3:8763/eureka/  instance:    prefer-ip-address: true    instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}

四、实体类User.java

package com.jacky.cloud.entity; import java.math.BigDecimal; public class User {  private Long id;   private String username;   private String name;   private Short age;   private BigDecimal balance;   public Long getId() {    return this.id;  }   public void setId(Long id) {    this.id = id;  }   public String getUsername() {    return this.username;  }   public void setUsername(String username) {    this.username = username;  }   public String getName() {    return this.name;  }   public void setName(String name) {    this.name = name;  }   public Short getAge() {    return this.age;  }   public void setAge(Short age) {    this.age = age;  }   public BigDecimal getBalance() {    return this.balance;  }   public void setBalance(BigDecimal balance) {    this.balance = balance;  } }

五、生产者发生错误时使用的类(HystrixClientFallback.java)

package com.jacky.cloud.feign; import org.springframework.stereotype.Component; import com.jacky.cloud.entity.User; @Componentpublic class HystrixClientFallback implements UserFeignClient {   @Override  public User findById(Long id) {    User user = new User();    user.setId(0L);    return user;   }}

六、feign客户端UserFeignClient.java

package com.jacky.cloud.feign; import com.jacky.cloud.entity.User;import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod; @FeignClient(name = "microservice-provider-user", fallback = HystrixClientFallback.class)public interface UserFeignClient {  @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)  public User findById(@PathVariable("id") Long id);}

七、MovieController.java

package com.jacky.cloud.controller; import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RestController; import com.jacky.cloud.entity.User;import com.jacky.cloud.feign.UserFeignClient; @RestControllerpublic class MovieController {   @Autowired  private UserFeignClient userFeignClient;   @GetMapping("/movie/{id}")  public User findById(@PathVariable Long id) {    return this.userFeignClient.findById(id);  }}

八、启动类

package com.jacky.cloud; import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.cloud.netflix.feign.EnableFeignClients; @SpringBootApplication@EnableEurekaClient@EnableFeignClients@EnableCircuitBreakerpublic class ConsumerMovieFeignApplication {  public static void main(String[] args) {    SpringApplication.run(ConsumerMovieFeignApplication.class, args);  }}

需要JAVASpring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六

 

标签:b2b2c,o2o电子商务,java多用户商城系统,spring cloud,java版社交电子商务

转载于:https://www.cnblogs.com/sunnysunny/p/10892704.html

你可能感兴趣的文章
导出一个数据库中的表中的某一条数据
查看>>
IOS开发工程师欢迎你加入宏略信息
查看>>
hdu1503
查看>>
js 获取两个日期相差的天数--自定义方法
查看>>
应用程序实现关闭屏幕
查看>>
责任链模式
查看>>
(转)Unity中protobuf的使用方法
查看>>
**PHP转义Json里的特殊字符的函数
查看>>
数据扩展性探讨和总结--转
查看>>
C# 导出资源文件到硬盘
查看>>
更改MySQL数据库的编码为utf8mb4
查看>>
TeamCity : .NET Core 插件
查看>>
由数量众多照片拼贴而成的马赛克图片
查看>>
andoid电阻触摸移植
查看>>
BootStrap 专题
查看>>
文件上传限制文件类型
查看>>
Netty线程模型
查看>>
判断一个变量是否为空的方法
查看>>
使用PS保存PDF为图片(JPG)
查看>>
Es对于日期处理
查看>>