微服务弹性框架 hystrix-javanica

码农软件 · 软件分类 · 微服务框架 · 2019-03-18 08:27:23

软件介绍

javanica 是 Hystrix 开源社区贡献的一个类库。

Java 语言相比其他语言有一些比较 great 的优点,那就是反射(refleaction)和注解(annotation)。在传统的使用 Hystrix 时,你需要编写大量的代码,这显然对开发者并不友好,也会制约 Hystrix 未来的发展。这种模式下,你需要花很长时间编写一些 Hystrix commands。Javanica 项目的想法就是想通过引入 annotation 让你更容易地使用 Hystrix。

使用

要使用 hystrix-javanica,首先要在项目中加入 hystrix-javanica 的依赖。

<dependency>
    <groupId>com.netflix.hystrix</groupId>
    <artifactId>hystrix-javanica</artifactId>
    <version>x.y.z</version>
</dependency>

为了实现 AOP 的功能,如果项目中已经使用了 AspectJ,那么还需要在 aop.xml 中添加 hystrix 的切面:

<aspects>
        ...
        <aspect name="com.netflix.hystrix.contrib.javanica.aop.
aspectj.HystrixCommandAspect"/>
        ...
</aspects>

更多 AspectJ 的配置你可以点击这里

如果使用 Spring AOP,那么需要通过使用 Spring AOP 的 namespace 来添加指定的配置,这样让 Spring 能够去管理切面,那些你使用 AspectJ 切面,需要像下面这样声明HystrixCommandAspect 作为 Spring 的 bean:

<aop:aspectj-autoproxy/>
    <bean id="hystrixAspect" class="com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect"></bean>

如果使用Spring的代码配置方式的话,则像下面这样:

@Configuration
public class HystrixConfiguration {  
  @Bean
  public HystrixCommandAspect hystrixAspect() {    
       return new HystrixCommandAspect();
  }

}

无论使用哪种方式来创建 proxy,javanica 都可以和 JDK 以及 CGLIB proxy 配合得很好。

本文地址:https://codercto.com/soft/d/1597.html

Remote

Remote

Jason Fried、David Heinemeier Hansson / Crown Business / 2013-10-29 / CAD 26.95

The “work from home” phenomenon is thoroughly explored in this illuminating new book from bestselling 37signals founders Fried and Hansson, who point to the surging trend of employees working from hom......一起来看看 《Remote》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具