zoukankan      html  css  js  c++  java
  • hystrix文档翻译之开始使用

    获取包

      使用maven获取包。

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

      使用lvy获取包

    <dependency org="com.netflix.hystrix" name="hystrix-core" rev="x.y.z" />

      如果希望使用maven下载包

    <?xml version="1.0"?>
    <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>
        <groupId>com.netflix.hystrix.download</groupId>
        <artifactId>hystrix-download</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>Simple POM to download hystrix-core and dependencies</name>
        <url>http://github.com/Netflix/Hystrix</url>
        <dependencies>
            <dependency>
                <groupId>com.netflix.hystrix</groupId>
                <artifactId>hystrix-core</artifactId>
                <version>x.y.z</version>
                <scope/>
            </dependency>
        </dependencies>
    </project>

      然后执行

    mvn -f download-hystrix-pom.xml dependency:copy-dependencies

      它将会下载hystrix-core-*.jar和他的依赖包。

      使用hystrix的一个简单例子:

    public class CommandHelloWorld extends HystrixCommand<String> {
    
        private final String name;
    
        public CommandHelloWorld(String name) {
            super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
            this.name = name;
        }
    
        @Override
        protected String run() {
            // a real example would do work like a network call here
            return "Hello " + name + "!";
        }
    }

      有一下三种方式调用命令

    String s = new CommandHelloWorld("Bob").execute();
    Future<String> s = new CommandHelloWorld("Bob").queue();
    Observable<String> s = new CommandHelloWorld("Bob").observe();

    编译hystrix

      checkout源码并编译

    $ git clone git@github.com:Netflix/Hystrix.git
    $ cd Hystrix/
    $ ./gradlew build

      执行 clean build

    $ ./gradlew clean build
  • 相关阅读:
    随机性的控制
    856. 括号的分数
    376. 摆动序列(贪心算法)
    XGBoost 安装方法
    1405. 最长快乐字符串(贪心算法)
    1296. 划分数组为连续数字的集合(贪心算法)
    1353. 最多可以参加的会议数目(贪心算法)
    435. 无重叠区间(贪心算法)
    Array-数组-数据结构
    认识Redis和安装
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8036855.html
Copyright © 2011-2022 走看看