安装GitBook环境

1、安装

# npm install gitbook
# npm install ebook-convert
npm install gitbook-cli -g 
gitbook install

2、设置国内源

npm config set registry https://registry.npmjs.org/
npm config set registry https://registry.npm.taobao.org

3、增加转PDF支持

# windows
https://calibre-ebook.com/download_windows64

#linux
sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
sudo apt-get install libfontconfig1 libxcomposite1 libxdamage1 libxfixes3 libgl1

#linux字体安装
#将需要的字体拷贝到这个文件夹
#/usr/share/fonts/truetype/winfonts
#刷新
sudo fc-cache -fv
#确保ubuntu认到字体
fc-list :lang=zh-cn

4、基本操作

# 新建一本书的目录结构
gitbook init

# 开启网站查看书的内容
gitbook serve .

# 图书生成pdf
gitbook pdf .

Win10无法启动VirtualBox

在Win10上遇到了一个问题:

Failed to open a session for the virtual machine ubuntu.

Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT).

Result Code: E_FAIL (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

最后发现是前几天安装了Win10的Hyper-V模块,卸载后就好了。

Win10隐私设置

1、隐藏explorer的快速访问功能

#1.1、打开注册表编辑器
regedit
#1.2、定位到下面的路径
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
#1.3、新建一个DWORD (32-bit) Value的键值对
HubMode=1

2、关闭Cortana

#2.1、打开组策略编辑器
gepedit.msc
#2.2、定位路径
计算机配置/管理模板/Windows组件/搜索
#2.3、禁用Cortana
允许使用Cortana=已禁用

3、关闭搜索历史记录

开始/设置/Search/Permissions&History
My device history = off

4、关闭TaskView历史记录

开始/设置/Privacy/Activity history
去掉Store my activity history on this device
去掉Send my activity to Microsoft
点击Clear activity history

Spring Cloud Netflix入门(Feign)

Feign是一个很好用的REST通讯包,十分强大。

1、MyFeignClient

package com.neohope.springcloud.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import feign.hystrix.FallbackFactory;


import org.springframework.stereotype.Component;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(clients = {MyFeignClient.IServiceClient.class})
@RestController
public class MyFeignClient 
{
	@Value("${spring.application.name}")
	private String appName;
	
	@RequestMapping("/appName")
	public String appName() {
		return appName;
	}
	
	public static void main(String[] args)
	{
		new SpringApplicationBuilder(MyFeignClient.class).web(true).run(args);
	}
	
	@RequestMapping("/")
	public String hello() {
		return "It works";
	}
	
	@Autowired
	private IServiceClient aClient;
	
	@RequestMapping("/invokeC")
	public String invokeC() {
		return aClient.invokeA();
	}
	
	@RequestMapping("/invokeC/{clientName}")
    String invokeC(@PathVariable("clientName") String clientName)
    {
		if(aClient==null)
		{
			return "aClient is null";
		}
		else
		{
			//return aClient.invokeA(clientName);
			return aClient.invokeA();
		}
    }
	
	//primary = false
	@FeignClient(name="netflix-feign-server", configuration = MyFeignClientConfiguration.class, fallbackFactory=HystrixClientFallbackFactory.class)
	public interface IServiceClient {
	    @RequestMapping(method = RequestMethod.GET, value = "/invokeA")
	    String invokeA();

	    //@RequestMapping(method = RequestMethod.GET, value = "/invokeA/{clientName}", consumes = "application/json")
	    //String invokeA(@PathVariable("clientName") String clientName);
	}
	
	@Component
    public static class HystrixClientFallbackFactory implements FallbackFactory<IServiceClient>{
    	@Override
    	public IServiceClient create(final Throwable cause) {
    		return new IServiceClient() {
    			@Override
    		    public String invokeA()
    		    {
    				return "invokeA failed: "+cause.getMessage();
    		    }

    			//@Override
    			//public String invokeA(String clientName)
    		    //{
    			//	return "invokeA with clientName "+clientName+" failed: "+cause.getMessage();
    		    //}
    		};
    	}
    }
}

2、MyFeignClientConfiguration

package com.neohope.springcloud.test;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;

@Configuration
public class MyFeignClientConfiguration {
	@Bean
	public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
		return new BasicAuthRequestInterceptor("user", "hystrix");
	}

	/*
	@Bean
	Logger.Level feignLoggerLevel() {
		return Logger.Level.FULL;
	}
	*/
}

3、pom.xml

<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>org.springframework.cloud.stream.app</groupId>
		<artifactId>app-starters-build</artifactId>
		<version>1.1.3.M1</version>
	</parent>

	<groupId>com.neohope.springcloud.test</groupId>
	<artifactId>netflix-feign-client</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>netflix-feign-client</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>com.netflix.hystrix</groupId>
			<artifactId>hystrix-javanica</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-feign</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
			<version>1.3.0.M1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
</project>

4、application.properties

spring.application.name=feign-client
server.port=7002
security.user.name=user
security.user.password=hystrix
eureka.client.serviceUrl.defaultZone=http://user:hystrix@localhost:7000/eureka/
eureka.client.preferSameZoneEureka=true
eureka.client.healthcheck.enabled=true
eureka.instance.metadataMap.zone = zone1
eureka.instance.statusPageUrlPath=${management.context-path}/info
eureka.instance.healthCheckUrlPath=${management.context-path}/health
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.lease-expiration-duration-in-seconds=10
feign.hystrix.enabled=true
#feign.compression.request.enabled=true
#feign.compression.response.enabled=true
#feign.compression.request.enabled=true
#feign.compression.request.mime-types=text/xml,application/xml,application/json
#feign.compression.request.min-request-size=2048
#NONE,BASIC,HEADERS,FULL
logging.level.com.neohope.springcloud.test.MyFeignClient.IServiceClient=BASIC

Spring Cloud Netflix入门(Sidecar)

SideCar主要是用于将非JVM语言的服务,代理为Netflix服务

1、SideCarApp

package com.neohope.springcloud.test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.sidecar.EnableSidecar;
import org.springframework.web.bind.annotation.RequestMapping;

//作用一、注册到eureka并提供服务健康状态
//其他语言的服务,首先服务封装为REST或JSON通信,并提供一个health路径,反馈服务是否正常
//sidecar会将这个服务注册到eureka
//其他服务,可以通过eureka查询并调用该服务

//作用二、从sidecar获取服务地址,并调用
//访问sidecar,获取服务地址  http://localhost:port/hosts/{serviceId}.
//分析返回结果,得到服务地址
//调用需要的服务
@EnableSidecar
public class SideCarApp 
{
	@Value("${spring.application.name}")
	private String appName;
	
	@RequestMapping("/appName")
	public String appName() {
		return appName;
	}
	
	@RequestMapping("/")
	public String hello() {
		return "It works";
	}
	
    public static void main( String[] args )
    {
    	new SpringApplicationBuilder(SideCarApp.class).web(true).run(args);
    }
}

2、pom.xml

<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>org.springframework.cloud.stream.app</groupId>
		<artifactId>app-starters-build</artifactId>
		<version>1.1.3.M1</version>
	</parent>

	<groupId>com.neohope.springcloud.test</groupId>
	<artifactId>netflix-sidecar-test</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>netflix-sidecar-test</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-netflix-sidecar</artifactId>
			<version>1.3.0.M1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
</project>

3、application.properties

spring.application.name=zuul-gateway-app
server.port=7001
security.user.name=user
security.user.password=hystrix

eureka.client.serviceUrl.defaultZone=http://user:hystrix@localhost:7000/eureka/
eureka.client.preferSameZoneEureka=true
eureka.client.healthcheck.enabled=true
eureka.instance.metadataMap.zone = zone1
eureka.instance.statusPageUrlPath=${management.context-path}/info
eureka.instance.healthCheckUrlPath=${management.context-path}/health
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.lease-expiration-duration-in-seconds=10

sidecar.port=9999
sidecar.health-uri=http://localhost:9999/health.json

Spring Cloud Netflix入门(Zuul)

Zuul就是一个API网关。

1、ZuulGatewayApp.java

package com.neohope.springcloud.test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEurekaClient
@RestController
@EnableZuulProxy
//@EnableZuulServer
public class ZuulGatewayApp 
{
	@Value("${spring.application.name}")
	private String appName;
	
	@RequestMapping("/appName")
	public String appName() {
		return appName;
	}
	
	public static void main(String[] args)
	{
		new SpringApplicationBuilder(ZuulGatewayApp.class).web(true).run(args);
	}
	
	@RequestMapping("/")
	public String hello() {
		return "It works";
	}
}

2、pom.xml

<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>org.springframework.cloud.stream.app</groupId>
		<artifactId>app-starters-build</artifactId>
		<version>1.1.3.M1</version>
	</parent>

	<groupId>com.neohope.springcloud.test</groupId>
	<artifactId>netflix-zuul-gateway</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>netflix-zuul-gateway</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>com.netflix.hystrix</groupId>
			<artifactId>hystrix-javanica</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>
		<dependency>
			<groupId>com.netflix.feign</groupId>
			<artifactId>feign-okhttp</artifactId>
			<version>8.18.0</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
</project>

3、application.properties

spring.application.name=zuul-gateway-app
server.port=7001
security.user.name=user
security.user.password=hystrix

eureka.client.serviceUrl.defaultZone=http://user:hystrix@localhost:7000/eureka/
eureka.client.preferSameZoneEureka=true
eureka.client.healthcheck.enabled=true
eureka.instance.metadataMap.zone = zone1
eureka.instance.statusPageUrlPath=${management.context-path}/info
eureka.instance.healthCheckUrlPath=${management.context-path}/health
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.lease-expiration-duration-in-seconds=10

zuul.host.maxTotalConnections=200
zuul.host.maxPerRouteConnections=20
#zuul.ignoredServices='*'
zuul.routes.netflix-feign-server.sensitiveHeaders
zuul.routes.netflix-feign-server.path=/invokeA/**
zuul.routes.netflix-feign-server.serviceId=netflix-feign-server
#zuul.routes.netflix-feign-server.url=
#zuul.ribbonIsolationStrategy=THREAD
#zuul.prefix=api
zuul.stripPrefix=false
#zuul.addProxyHeaders=false
#zuul.ignoredHeaders=
#zuul.forceOriginalQueryStringEncoding=true
#zuul.SendResponseFilter.post.disable=true.

#ribbon.eureka.enabled=false
#ribbon.restclient.enabled=true
#ribbon.okhttp.enabled=true
#ribbon.ConnectTimeout=3000
#ribbon.ReadTimeout=60000
#users.ribbon.listOfServers=172.16.172.63

#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000

Spring Cloud Netflix入门(Turbine)

Turbine是一个日志收集器,用于聚合Hystrix中的日志。

1、TurbineServer

package com.neohope.springcloud.test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream;
import org.springframework.web.bind.annotation.RequestMapping;

@SpringBootApplication
@EnableCircuitBreaker
@EnableEurekaServer
@EnableHystrixDashboard
@EnableTurbineStream
public class TurbineServer 
{
	@Value("${spring.application.name}")
	private String appName;
	
	@RequestMapping("/appName")
	public String appName() {
		return appName;
	}
	
	public static void main(String[] args) {
        new SpringApplicationBuilder(TurbineServer.class).web(true).run(args);
    }
}

2、pom.xml

<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>org.springframework.cloud.stream.app</groupId>
		<artifactId>app-starters-build</artifactId>
		<version>1.1.3.M1</version>
	</parent>

	<groupId>com.neohope.springcloud.test</groupId>
	<artifactId>netflix-turbine-server</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>netflix-turbine-server</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-turbine-stream</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-stream-kafka</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
			<version>1.3.0.M1</version>
		</dependency>
		<dependency>
			<groupId>com.netflix.hystrix</groupId>
			<artifactId>hystrix-javanica</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
</project>

3、application.properties

spring.application.name=turbine-server
server.port=7000
security.user.name=user
security.user.password=hystrix
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.metadataMap.zone = zone1
eureka.server.enable-self-preservation=false
eureka.server.eviction-interval-timer-in-ms=5000
eureka.client.serviceUrl.defaultZone=http://user:hystrix@localhost:7000/eureka/
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.preferSameZoneEureka=true
manager.port=7000
turbine.stream.port=8989

4、TurbineClient

package com.neohope.springcloud.test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@SpringBootApplication
@EnableEurekaClient
@RestController
@EnableCircuitBreaker
public class TurbineClient 
{
	@Value("${spring.application.name}")
	private String appName;
	
	@RequestMapping("/appName")
	public String appName() {
		return appName;
	}
	
	@RequestMapping("/")
	public String hello() {
		return "It works";
	}
	
	@RequestMapping("/invokeA")
	@HystrixCommand(fallbackMethod = "invoekD")
	public String invokeA() {
		if(Math.random()>0.2)
		{
			throw new RuntimeException("Hystrix Test A thrown");
		}
		else
		{
			return "Hystrix Test A";
		}
	}
	
	@RequestMapping("/invokeB")
	@HystrixCommand(fallbackMethod = "invoekD")
	public String invokeB() {
		if(Math.random()>0.5)
		{
			throw new RuntimeException("Hystrix Test A thrown");
		}
		else
		{
			return "Hystrix Test A";
		}
	}
	
	@RequestMapping("/invokeD")
	public String invoekD() {
		return "Hystrix Test D";
	}
	
	public static void main(String[] args)
	{
		new SpringApplicationBuilder(TurbineClient.class).web(true).run(args);
	}
}

5、pom.xml

<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>org.springframework.cloud.stream.app</groupId>
		<artifactId>app-starters-build</artifactId>
		<version>1.1.3.M1</version>
	</parent>

	<groupId>com.neohope.springcloud.test</groupId>
	<artifactId>netflix-turbine-client</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>netflix-turbine-client</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.3.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-stream-kafka</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>com.netflix.hystrix</groupId>
			<artifactId>hystrix-javanica</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
			<version>1.3.0.M1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
			<version>1.5.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
</project>

6、application.properties

spring.application.name=turbine-client
server.port=7001
security.user.name=user
security.user.password=hystrix
eureka.client.serviceUrl.defaultZone=http://user:hystrix@localhost:7000/eureka/
eureka.client.preferSameZoneEureka=true
eureka.client.healthcheck.enabled=true
eureka.instance.metadataMap.zone = zone1
eureka.instance.statusPageUrlPath=${management.context-path}/info
eureka.instance.healthCheckUrlPath=${management.context-path}/health
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.lease-expiration-duration-in-seconds=10
#eureka.instance.metadata-map.management.port=7001
#management.port=7002
turbine.aggregator.clusterConfig=default
turbine.appConfig=turbine-client
turbine.stream.port=8989

7、在以下地址可以访问
http://172.16.172.63:7001/hystrix.stream
http://user:hystrix@172.16.172.63:7002/turbine.stream