package com.example.demo.service.impl;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.example.demo.service.PushMessageService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
@Service
public class PushMessageServiceImpl implements PushMessageService {
private Logger logger = LoggerFactory.getLogger(PushMessageServiceImpl.class);
@Override
@HystrixCommand(fallbackMethod = "fallback_send",
commandProperties = {
//命令执行超时时间,默认1000ms
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000"),
//一个rolling window内最小的请求数。如果设为20,那么当一个rolling window的时间内(比如说1个rolling window是10秒)收到19个请求,即使19个请求都失败,也不会触发circuit break。默认20
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
//触发短路的时间值,当该值设为5000时,则当触发circuit break后的5000毫秒内都会拒绝request,也就是5000毫秒后才会关闭circuit。默认5000
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "60000")
})
public String send(String param) throws Exception{
logger.error("发送"+new Date().getTime());
try {
//double a =1/0;
Thread.sleep(3000);
}catch(Exception e) {
logger.error("发送 catch"+new Date().getTime());
throw e;
}finally {
logger.error("发送 finally"+new Date().getTime());
}
return "发送成功";
}
private String fallback_send(String param,Throwable throwble) {
//logger.error("异常",throwble);
return "Send超時"+new Date().getTime();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Hystrix.zip (21个子文件)
Hystrix
src
main
resources
application.properties 0B
java
com
example
demo
controller
TestHystrixController.java 1KB
DemoApplication.java 592B
service
PushMessageService.java 127B
impl
PushMessageServiceImpl.java 2KB
config
HystrixConfig.java 442B
test
resources
java
.classpath 1KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 191B
org.eclipse.jdt.core.prefs 243B
pom.xml 2KB
target
classes
META-INF
MANIFEST.MF 331B
maven
com.fang.test
Hystrix
pom.properties 227B
pom.xml 2KB
com
example
demo
controller
TestHystrixController.class 2KB
service
PushMessageService.class 246B
impl
PushMessageServiceImpl.class 2KB
config
HystrixConfig.class 705B
DemoApplication.class 942B
application.properties 0B
test-classes
.project 559B
共 21 条
- 1
资源评论
程序员1111
- 粉丝: 7
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功