Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloud-study
提交
ef45b284
S
SpringCloud-study
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringCloud-study
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringCloud-study
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ef45b284
编写于
1月 14, 2023
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:turbine
上级
e84c3b59
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
470 addition
and
5 deletion
+470
-5
pom.xml
pom.xml
+3
-1
springcloud-service-hystrix-turbine/pom.xml
springcloud-service-hystrix-turbine/pom.xml
+59
-0
springcloud-service-hystrix-turbine/src/main/java/com/kwan/springcloud/HystrixTurbineApplication.java
.../java/com/kwan/springcloud/HystrixTurbineApplication.java
+32
-0
springcloud-service-hystrix-turbine/src/main/resources/application.yaml
...rvice-hystrix-turbine/src/main/resources/application.yaml
+61
-0
springcloud-service-hystrix-turbine/src/test/java/com/kwan/springcloud/HystrixTurbineApplicationTests.java
.../com/kwan/springcloud/HystrixTurbineApplicationTests.java
+13
-0
springcloud-service-portal-8080/pom.xml
springcloud-service-portal-8080/pom.xml
+2
-2
springcloud-service-portal-8080/src/main/java/com/kwan/springcloud/PortalApplication8080.java
...main/java/com/kwan/springcloud/PortalApplication8080.java
+2
-2
springcloud-service-portal-8080/src/main/java/com/kwan/springcloud/controller/PortalController.java
...ava/com/kwan/springcloud/controller/PortalController.java
+0
-0
springcloud-service-portal-8080/src/main/java/com/kwan/springcloud/service/PortalService.java
...main/java/com/kwan/springcloud/service/PortalService.java
+0
-0
springcloud-service-portal-8080/src/main/resources/application.yaml
...d-service-portal-8080/src/main/resources/application.yaml
+5
-0
springcloud-service-portal-8080/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
...est/java/com/kwan/springcloud/PortalApplicationTests.java
+0
-0
springcloud-service-portal-8081/pom.xml
springcloud-service-portal-8081/pom.xml
+56
-0
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/PortalApplication8081.java
...main/java/com/kwan/springcloud/PortalApplication8081.java
+40
-0
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/controller/PortalController.java
...ava/com/kwan/springcloud/controller/PortalController.java
+66
-0
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/service/PortalService.java
...main/java/com/kwan/springcloud/service/PortalService.java
+72
-0
springcloud-service-portal-8081/src/main/resources/application.yaml
...d-service-portal-8081/src/main/resources/application.yaml
+46
-0
springcloud-service-portal-8081/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
...est/java/com/kwan/springcloud/PortalApplicationTests.java
+13
-0
未找到文件。
pom.xml
浏览文件 @
ef45b284
...
...
@@ -29,13 +29,15 @@
<module>
springcloud-service-goods-9200
</module>
<module>
springcloud-service-goods-9300
</module>
<module>
springcloud-service-common
</module>
<module>
springcloud-service-portal
</module>
<module>
springcloud-service-portal-8080
</module>
<module>
springcloud-service-portal-8081
</module>
<module>
springcloud-service-config
</module>
<module>
springcloud-service-config-client
</module>
<module>
springcloud-service-feign
</module>
<module>
springcloud-service-zuul
</module>
<module>
springcloud-service-consul
</module>
<module>
springcloud-service-hystrix-dashboard
</module>
<module>
springcloud-service-hystrix-turbine
</module>
<module>
springcloud-service-eureka
</module>
</modules>
...
...
springcloud-service-hystrix-turbine/pom.xml
0 → 100644
浏览文件 @
ef45b284
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-hystrix-turbine
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-hystrix-turbine
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!--spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-hystrix-dashboard
</artifactId>
</dependency>
<!--springboot开发自动热部署-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-hystrix
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-turbine
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
springcloud-service-hystrix-turbine/src/main/java/com/kwan/springcloud/HystrixTurbineApplication.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard
;
import
org.springframework.cloud.netflix.turbine.EnableTurbine
;
/**
* http://localhost:9999/hystrix
* <p>
* <p>
* <p>
* http://localhost:9999/turbine.stream
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/14 15:33
*/
@EnableTurbine
@EnableEurekaClient
@EnableHystrixDashboard
@SpringBootApplication
public
class
HystrixTurbineApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
HystrixTurbineApplication
.
class
,
args
);
}
}
springcloud-service-hystrix-turbine/src/main/resources/application.yaml
0 → 100644
浏览文件 @
ef45b284
#端口号
server
:
port
:
9999
spring
:
application
:
name
:
hystrix-turbine-service
#服务名称
#服务提供者
eureka
:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
instance
:
lease-renewal-interval-in-seconds
:
2
#每间隔2s,向服务端发送一次心跳,证明自己依然"存活”
lease-expiration-duration-in-seconds
:
10
#告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉
prefer-ip-address
:
true
#告诉服务端,服务实例以IP作为链接,而不是取机器名
instance-id
:
springcloud-service-turbine-9999
#告诉服务端,服务实例的id,id要是唯一的
# 开启Feign对Hystrix的支持
feign
:
hystrix
:
enabled
:
true
client
:
config
:
default
:
connectTimeout
:
5000
# 指定Feign连接提供者的超时时限
readTimeout
:
5000
# 指定Feign从请求到获取提供者响应的超时时限
# 开启actuator的所有web终端
management
:
endpoints
:
web
:
exposure
:
include
:
"
*"
# 设置服务熔断时限
hystrix
:
dashboard
:
proxy-stream-allow-list
:
"
localhost"
command
:
default
:
execution
:
isolation
:
thread
:
timeoutInMilliseconds
:
3000
turbine
:
app-config
:
portal-service
cluster-name-expression
:
new String("default")
combine-host-port
:
true
instanceUrlSuffix
:
/actuator/hystrix.stream
#turbine默认监控actuator/路径下的端点,修改直接监控hystrix.stream
#cluster-name-expression: metadata['cluster']
#aggregator:
# cluster-config: ribbon
#instanceUrlSuffix: /hystrix.stream #turbine默认监控actuator/路径下的端点,修改直接监控hystrix.stream
\ No newline at end of file
springcloud-service-hystrix-turbine/src/test/java/com/kwan/springcloud/HystrixTurbineApplicationTests.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
HystrixTurbineApplicationTests
{
@Test
void
contextLoads
()
{
}
}
springcloud-service-portal/pom.xml
→
springcloud-service-portal
-8080
/pom.xml
浏览文件 @
ef45b284
...
...
@@ -7,9 +7,9 @@
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-portal
</artifactId>
<artifactId>
springcloud-service-portal
-8080
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-portal
</name>
<name>
springcloud-service-portal
-8080
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
...
...
springcloud-service-portal
/src/main/java/com/kwan/springcloud/PortalApplication
.java
→
springcloud-service-portal
-8080/src/main/java/com/kwan/springcloud/PortalApplication8080
.java
浏览文件 @
ef45b284
...
...
@@ -20,11 +20,11 @@ import org.springframework.context.annotation.Bean;
@EnableHystrix
@EnableEurekaClient
@SpringBootApplication
public
class
PortalApplication
{
public
class
PortalApplication
8080
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
PortalApplication
.
class
,
args
);
SpringApplication
.
run
(
PortalApplication
8080
.
class
,
args
);
}
@Bean
...
...
springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java
→
springcloud-service-portal
-8080
/src/main/java/com/kwan/springcloud/controller/PortalController.java
浏览文件 @
ef45b284
文件已移动
springcloud-service-portal/src/main/java/com/kwan/springcloud/service/PortalService.java
→
springcloud-service-portal
-8080
/src/main/java/com/kwan/springcloud/service/PortalService.java
浏览文件 @
ef45b284
文件已移动
springcloud-service-portal/src/main/resources/application.yaml
→
springcloud-service-portal
-8080
/src/main/resources/application.yaml
浏览文件 @
ef45b284
...
...
@@ -11,6 +11,11 @@ eureka:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
instance
:
lease-renewal-interval-in-seconds
:
2
#每间隔2s,向服务端发送一次心跳,证明自己依然"存活”
lease-expiration-duration-in-seconds
:
10
#告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉
prefer-ip-address
:
true
#告诉服务端,服务实例以IP作为链接,而不是取机器名
instance-id
:
springcloud-service-portal-8080
#告诉服务端,服务实例的id,id要是唯一的
#开启feign开始hystrix的支持
feign
:
...
...
springcloud-service-portal/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
→
springcloud-service-portal
-8080
/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
浏览文件 @
ef45b284
文件已移动
springcloud-service-portal-8081/pom.xml
0 → 100644
浏览文件 @
ef45b284
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-portal-8081
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-portal-8081
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-common
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</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-openfeign-core
</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-netflix-hystrix
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/PortalApplication8081.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud
;
import
com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.hystrix.EnableHystrix
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
/**
*
* http://localhost:8081/portal/hystrix/1
*@version : 2.2.0
*@author : qinyingjie
*@date : 2023/1/14 16:07
*/
@EnableFeignClients
@EnableHystrix
@EnableEurekaClient
@SpringBootApplication
public
class
PortalApplication8081
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
PortalApplication8081
.
class
,
args
);
}
@Bean
public
ServletRegistrationBean
getServlet
()
{
HystrixMetricsStreamServlet
streamServlet
=
new
HystrixMetricsStreamServlet
();
ServletRegistrationBean
registrationBean
=
new
ServletRegistrationBean
(
streamServlet
);
registrationBean
.
setLoadOnStartup
(
1
);
registrationBean
.
addUrlMappings
(
"/hystrix.stream"
);
registrationBean
.
setName
(
"HystrixMetricsStreamServlet"
);
return
registrationBean
;
}
}
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/controller/PortalController.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud.controller
;
import
com.kwan.springcloud.response.Result
;
import
com.kwan.springcloud.service.PortalService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* portal控制器
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/8 11:12
*/
@RestController
@RequestMapping
(
"/portal"
)
public
class
PortalController
{
@Autowired
private
PortalService
portalService
;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping
(
value
=
"/hystrix/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
hystrix
(
@PathVariable
String
id
)
{
return
portalService
.
hystrix
(
id
);
}
@GetMapping
(
value
=
"/limit/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
limit
(
@PathVariable
String
id
)
{
return
portalService
.
limit
(
id
);
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping
(
value
=
"{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
selectOne
(
@PathVariable
String
id
)
{
return
portalService
.
addService
(
id
);
}
@GetMapping
(
value
=
"/test"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
test
()
{
return
Result
.
ok
(
"portal 访问成功"
);
}
}
\ No newline at end of file
springcloud-service-portal-8081/src/main/java/com/kwan/springcloud/service/PortalService.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud.service
;
import
com.kwan.springcloud.response.Result
;
import
com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand
;
import
com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
@Slf4j
@Service
public
class
PortalService
{
/**
* http直接访问
*/
private
static
final
String
GOODS_URL
=
"http://localhost:9100/kwanGoodsInfo/"
;
/**
* eureka访问
*/
private
static
final
String
GOODS_URL_2
=
"http://goods-service/kwanGoodsInfo/"
;
@Autowired
RestTemplate
restTemplate
;
public
Result
addService
(
String
id
)
{
//调用远程的controller
return
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
).
getBody
();
}
@HystrixCommand
(
fallbackMethod
=
"addServiceFallback"
,
commandProperties
=
{
@HystrixProperty
(
name
=
"execution.timeout.enabled"
,
value
=
"true"
),
@HystrixProperty
(
name
=
"execution.isolation.thread.timeoutInMilliseconds"
,
value
=
"6000"
)}
)
public
Result
hystrix
(
String
id
)
{
//1·服务超时,会降级
// try {
// Thread.sleep(6000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// //2.服务异常,会降级
// String str = null;
// if (str == null) {
// throw new RuntimeException("服务异常了.");
// }
return
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
).
getBody
();
}
public
Result
addServiceFallback
(
String
id
)
{
log
.
info
(
"失败id={}"
,
id
);
// return Result.error("请求超时 服务不可用 请求失败");
return
Result
.
error
(
"请求异常 服务不可用 请求失败"
);
}
@HystrixCommand
(
fallbackMethod
=
"addServiceFallback"
,
threadPoolKey
=
"goods"
,
threadPoolProperties
=
{
@HystrixProperty
(
name
=
"coreSize"
,
value
=
"2"
),
@HystrixProperty
(
name
=
"maxQueueSize"
,
value
=
"1"
),
@HystrixProperty
(
name
=
"keepAliveTimeMinutes"
,
value
=
"2"
),
@HystrixProperty
(
name
=
"queueSizeRejectionThreshold"
,
value
=
"100"
)
}
)
public
Result
limit
(
String
id
)
{
return
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
).
getBody
();
}
}
springcloud-service-portal-8081/src/main/resources/application.yaml
0 → 100644
浏览文件 @
ef45b284
#端口号
server
:
port
:
8081
spring
:
application
:
name
:
portal-service
#服务名称
#服务提供者
eureka
:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
instance
:
lease-renewal-interval-in-seconds
:
2
#每间隔2s,向服务端发送一次心跳,证明自己依然"存活”
lease-expiration-duration-in-seconds
:
10
#告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉
prefer-ip-address
:
true
#告诉服务端,服务实例以IP作为链接,而不是取机器名
instance-id
:
springcloud-service-portal-8081
#告诉服务端,服务实例的id,id要是唯一的
#开启feign开始hystrix的支持
feign
:
hystrix
:
enabled
:
true
hystrix
:
command
:
default
:
execution
:
isolation
:
thread
:
timeoutInMilliseconds
:
5000
#hystrix超时时间
timeout
:
enabled
:
true
#开启hystrix超时管理
ribbon
:
ReadTimeout
:
2000
#请求超时时间
http
:
client
:
enabled
:
true
#开启ribbon超时管理
ConnectTimeout
:
2000
#连接超时时间
management
:
endpoints
:
web
:
exposure
:
include
:
"
*"
\ No newline at end of file
springcloud-service-portal-8081/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
0 → 100644
浏览文件 @
ef45b284
package
com.kwan.springcloud
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
PortalApplicationTests
{
@Test
void
contextLoads
()
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录