how2j.cn

-->
下载区
文件名 文件大小
请先登录 343k
增值内容 343k
343k

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21

2分41秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 第三方不可用时   
步骤 4 : pom.xml   
步骤 5 : IndexGatherStoreApplication   
步骤 6 : IndexService 上使用断路器   
步骤 7 : 测试   

步骤 1 :

先运行,看到效果,再学习

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
先运行,看到效果,再学习
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
步骤 3 :

第三方不可用时

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
第三方不可用时
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<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>cn.how2j.trend</groupId> <artifactId>trendParentProject</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>cn.how2j.trend</groupId> <artifactId>index-gather-store-service</artifactId> <dependencies> <!-- springboot web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- eureka-client --> <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-netflix-hystrix</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
步骤 5 :

IndexGatherStoreApplication

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.NetUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @SpringBootApplication @EnableEurekaClient @EnableHystrix public class IndexGatherStoreApplication { public static void main(String[] args) { int defaultPort = 8001; int port =defaultPort; int eurekaServerPort = 8761; if(NetUtil.isUsableLocalPort(eurekaServerPort)) { System.err.printf("检查到端口%d 未启用,判断 eureka 服务器没有启动,本服务无法使用,故退出%n", eurekaServerPort ); System.exit(1); } if(null!=args && 0!=args.length) { for (String arg : args) { if(arg.startsWith("port=")) { String strPort= StrUtil.subAfter(arg, "port=", true); if(NumberUtil.isNumber(strPort)) { port = Convert.toInt(strPort); } } } } if(!NetUtil.isUsableLocalPort(port)) { System.err.printf("端口%d被占用了,无法启动%n", port ); System.exit(1); } new SpringApplicationBuilder(IndexGatherStoreApplication.class).properties("server.port=" + port).run(args); } @Bean RestTemplate restTemplate() { return new RestTemplate(); } }
步骤 6 :

IndexService 上使用断路器

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.service; import cn.how2j.trend.pojo.Index; import cn.hutool.core.collection.CollectionUtil; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.List; import java.util.Map; @Service public class IndexService { private List<Index> indexes; @Autowired RestTemplate restTemplate; @HystrixCommand(fallbackMethod = "third_part_not_connected") public List<Index> fetch_indexes_from_third_part(){ List<Map> temp= restTemplate.getForObject("http://127.0.0.1:8090/indexes/codes.json",List.class); return map2Index(temp); } public List<Index> third_part_not_connected(){ System.out.println("third_part_not_connected()"); Index index= new Index(); index.setCode("000000"); index.setName("无效指数代码"); return CollectionUtil.toList(index); } private List<Index> map2Index(List<Map> temp) { List<Index> indexes = new ArrayList<>(); for (Map map : temp) { String code = map.get("code").toString(); String name = map.get("name").toString(); Index index= new Index(); index.setCode(code); index.setName(name); indexes.add(index); } return indexes; } }
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
测试


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2020-02-21 断路器无法使用
这个昵称可以用




我用的eclipse跟站长一样,下载站长的程序包后,导入eclipse,三个工程全部启动后,http://127.0.0.1:8001/getCodes无法访问(去掉断路器的代码即可正常访问),浏览器报错和后台报错如下,麻烦帮忙看一下(百度说是包版本不对,但是试了试仍然不行)

							
浏览器报错
Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Feb 21 14:52:14 CST 2020
There was an unexpected error (type=Internal Server Error, status=500).
Could not initialize class com.netflix.hystrix.metric.consumer.RollingCommandLatencyDistributionStream
后台报错:
java.lang.NoClassDefFoundError: Could not initialize class com.netflix.hystrix.metric.consumer.RollingCommandLatencyDistributionStream
	at com.netflix.hystrix.HystrixCommandMetrics.<init>(HystrixCommandMetrics.java:196) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.HystrixCommandMetrics.getInstance(HystrixCommandMetrics.java:134) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.AbstractCommand.initMetrics(AbstractCommand.java:240) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.AbstractCommand.<init>(AbstractCommand.java:166) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.HystrixCommand.<init>(HystrixCommand.java:148) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.HystrixCommand.<init>(HystrixCommand.java:134) ~[hystrix-core-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.<init>(AbstractHystrixCommand.java:51) ~[hystrix-javanica-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.<init>(GenericCommand.java:36) ~[hystrix-javanica-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.contrib.javanica.command.HystrixCommandFactory.create(HystrixCommandFactory.java:43) ~[hystrix-javanica-1.5.12.jar:1.5.12]
	at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:96) ~[hystrix-javanica-1.5.12.jar:1.5.12]
	at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_131]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_131]
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at cn.how2j.trend.service.IndexService$$EnhancerBySpringCGLIB$$9fdaf7b7.fetch_indexes_from_third_part(<generated>) ~[classes/:na]
	at cn.how2j.trend.web.IndexController.get(IndexController.java:18) ~[classes/:na]
	at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_131]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_131]
。。。。。。


2 个答案

how2j
答案时间:2020-02-22
嗯? 为什么我能用呢? 你有做了其他改动吗?

这个昵称可以用
答案时间:2020-02-21
增加了一个依赖,解决了问题 <dependency> <groupId>org.hdrhistogram</groupId> <artifactId>HdrHistogram</artifactId> <version>2.1.10</version> </dependency>
<dependency>
	<groupId>org.hdrhistogram</groupId>
	<artifactId>HdrHistogram</artifactId>
    	<version>2.1.10</version>
</dependency>



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2019-08-22 站长是用什么方法关这些Application的
wuchangkun

我都是整个IDE都关了,有什么简单方便一点的方法吗




3 个答案

jeffreyfinn
答案时间:2019-11-30
用IDEA有一个统一的管理中心,所有微服务都会列在下面,这样就可以直接右键启动和关闭了

香格里拉飞龙
答案时间:2019-11-21
。。。我是把一个微服务的页面刷新一下,然后从IDE关一个,再刷下一个,再关。。。。

how2j
答案时间:2019-08-23
分布式就是这么麻烦,/摊手



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2019-08-18 给后来者一个提醒




提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-趋势投资SpringCloud-采集和储存微服务-断路器 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图