美文网首页
@HystrixCommand属性动态修改

@HystrixCommand属性动态修改

作者: 老周识途 | 来源:发表于2018-01-26 18:39 被阅读1255次

@HystrixCommand的使用对于应用开发来说非常方便,但也有个限制就是像动态修改注解的属性就很麻烦。

因为被该注解标注的方法在执行前是被com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect实时地读取注解元数据的,同时Hystrix内部只提供了Archaius动态配置,但也是有不小的使用限制。

另类解决方式:

`@Aspect

@Component

public class MyHystrixCommandAspect {

public static BooleantimeoutInMilliseconds = Boolean.FALSE;

    @Pointcut("@annotation(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)")

public void hystrixCommandAnnotationPointcut() {

}

@Around("hystrixCommandAnnotationPointcut()")

public ObjectmethodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinPoint)throws Throwable {

if(timeoutInMilliseconds){

System.out.print("%%%%%%%%%%%%%%%%%%%%%");

            Method method =getMethodFromTarget(joinPoint);

            HystrixCommand hystrixCommand = method.getAnnotation(HystrixCommand.class);

            HystrixProperty[] hystrixProperties = hystrixCommand.commandProperties();

            for (HystrixProperty hystrixProperty : hystrixProperties){

if("execution.isolation.thread.timeoutInMilliseconds".equals(hystrixProperty.name())){

InvocationHandler h = Proxy.getInvocationHandler(hystrixProperty);

                    Field hField = h.getClass().getDeclaredField("memberValues");

                    hField.setAccessible(true);

                    Map memberValues = (Map) hField.get(h);

                    memberValues.put("value", "6000");

                }

}

}

Object obj =  joinPoint.proceed();

        return obj;

    }

}`

相关文章

  • @HystrixCommand属性动态修改

    @HystrixCommand的使用对于应用开发来说非常方便,但也有个限制就是像动态修改注解的属性就很麻烦。 因为...

  • HystrixCommand 动态配置

    需求: @HystrixCommand 的commandProperties 属性需要动态的配置,比如根据传递的参...

  • iOS RunTime 理解

    可以遍历对象的属性 可以动态的添加、修改属性,动态添加、修改、替换方法,动态添加、修改、替换协议 可以动态创建类、...

  • 访问节点和组件

    你可以在属性检查器里修改节点和组件,也能在脚本中动态修改。动态修改的好处是能够在一段时间内连续地修改属性、过渡属性...

  • runtime相关

    修改系统方法 动态添加方法 动态给系统类添加属性(给分类添加属性) runtime+kvc 转换模型

  • 动态修改link的href属性

    为什么要动态修改link的href属性? 1.可能需要动态插入css样式表。 2.可能需要动态修改css样...

  • H5动态修改input的placeholder属性

    动态修改input占位内容颜色、字号、透明度等等属性 { ` ...

  • jQuery的属性与样式之样式操作.css() 慕课网笔记

    通过js获取dom元素上的style属性,我们可以动态的给元素赋予样式属性。在jQuery中我们要动态的修改sty...

  • JS动态修改属性

    新手入坑,俗话说得好一如前端深似海,今天我来简单介绍一下如何通过js动态修改属性 HTML: 高度: 宽度: 颜...

  • 动态修改property ro属性

网友评论

      本文标题:@HystrixCommand属性动态修改

      本文链接:https://www.haomeiwen.com/subject/rnmwaxtx.html