当前位置: 首页>>代码示例>>Java>>正文


Java CircuitBreakerOptions类代码示例

本文整理汇总了Java中io.vertx.circuitbreaker.CircuitBreakerOptions的典型用法代码示例。如果您正苦于以下问题:Java CircuitBreakerOptions类的具体用法?Java CircuitBreakerOptions怎么用?Java CircuitBreakerOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CircuitBreakerOptions类属于io.vertx.circuitbreaker包,在下文中一共展示了CircuitBreakerOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: example2

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public void example2(Vertx vertx) {
  CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
      new CircuitBreakerOptions().setMaxFailures(5).setTimeout(2000)
  );

  breaker.<String>execute(future -> {
    vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {
      if (response.statusCode() != 200) {
        future.fail("HTTP error");
      } else {
        response
            .exceptionHandler(future::fail)
            .bodyHandler(buffer -> {
              future.complete(buffer.toString());
            });
      }
    });
  }).setHandler(ar -> {
    // Do something with the result
  });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:22,代码来源:Examples.java

示例2: visit

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Override
public CircuitBreakerOptions visit(final String... key)
        throws ZeroException {
    // 1. Must be the first line, fixed position.
    Ensurer.eqLength(getClass(), 0, (Object[]) key);
    // 2. Read data
    final JsonObject data = this.node.read();
    // 3. CircuitBreakerOptions building.
    final JsonObject config =
            Fn.getSemi(data.containsKey(CIRCUIT) &&
                            null != data.getValue(CIRCUIT), LOGGER,
                    () -> data.getJsonObject(CIRCUIT),
                    JsonObject::new);
    // 4. Verify the configuration data
    return visit(config);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:CircuitVisitor.java

示例3: start

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get().handler(this::convertPortfolioToEuro);
    router.post().handler(BodyHandler.create());
    router.post().handler(this::delegateWithCircuitBreaker);

    circuit = CircuitBreaker.create("circuit-breaker", vertx,
        new CircuitBreakerOptions()
            .setFallbackOnFailure(true)
            .setMaxFailures(3)
            .setResetTimeout(5000)
            .setTimeout(1000)
    );

    discovery = ServiceDiscovery.create(vertx);


    vertx.createHttpServer()
        .requestHandler(router::accept)
        .listen(8080);
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:23,代码来源:CurrencyServiceProxy.java

示例4: example1

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public void example1(Vertx vertx) {
  CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
      new CircuitBreakerOptions()
          .setMaxFailures(5) // number of failure before opening the circuit
          .setTimeout(2000) // consider a failure if the operation does not succeed in time
          .setFallbackOnFailure(true) // do we call the fallback on failure
          .setResetTimeout(10000) // time spent in open state before attempting to re-try
  );

  breaker.execute(future -> {
    // some code executing with the breaker
    // the code reports failures or success on the given future.
    // if this future is marked as failed, the breaker increased the
    // number of failures
  }).setHandler(ar -> {
    // Get the operation result.
  });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:19,代码来源:Examples.java

示例5: example3

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public void example3(Vertx vertx) {
  CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
      new CircuitBreakerOptions().setMaxFailures(5).setTimeout(2000)
  );

  breaker.executeWithFallback(
      future -> {
        vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {
          if (response.statusCode() != 200) {
            future.fail("HTTP error");
          } else {
            response
                .exceptionHandler(future::fail)
                .bodyHandler(buffer -> {
                  future.complete(buffer.toString());
                });
          }
        });
      }, v -> {
        // Executed when the circuit is opened
        return "Hello";
      })
      .setHandler(ar -> {
        // Do something with the result
      });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:27,代码来源:Examples.java

示例6: example4

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public void example4(Vertx vertx) {
  CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
      new CircuitBreakerOptions().setMaxFailures(5).setTimeout(2000)
  ).fallback(v -> {
    // Executed when the circuit is opened.
    return "hello";
  });

  breaker.execute(
      future -> {
        vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {
          if (response.statusCode() != 200) {
            future.fail("HTTP error");
          } else {
            response
                .exceptionHandler(future::fail)
                .bodyHandler(buffer -> {
                  future.complete(buffer.toString());
                });
          }
        });
      });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:24,代码来源:Examples.java

示例7: example5

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public void example5(Vertx vertx) {
  CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
      new CircuitBreakerOptions().setMaxFailures(5).setTimeout(2000)
  ).openHandler(v -> {
    System.out.println("Circuit opened");
  }).closeHandler(v -> {
    System.out.println("Circuit closed");
  });

  breaker.execute(
      future -> {
        vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {
          if (response.statusCode() != 200) {
            future.fail("HTTP error");
          } else {
            // Do something with the response
            future.complete();
          }
        });
      });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:22,代码来源:Examples.java

示例8: CircuitBreakerImpl

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public CircuitBreakerImpl(String name, Vertx vertx, CircuitBreakerOptions options) {
  Objects.requireNonNull(name);
  Objects.requireNonNull(vertx);
  this.vertx = vertx;
  this.name = name;

  if (options == null) {
    this.options = new CircuitBreakerOptions();
  } else {
    this.options = new CircuitBreakerOptions(options);
  }

  this.metrics = new CircuitBreakerMetrics(vertx, this, options);

  sendUpdateOnEventBus();

  if (this.options.getNotificationPeriod() > 0) {
    this.periodicUpdateTask = vertx.setPeriodic(this.options.getNotificationPeriod(), l -> sendUpdateOnEventBus());
  } else {
    this.periodicUpdateTask = -1;
  }
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:23,代码来源:CircuitBreakerImpl.java

示例9: main

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
public static void main(String[] args) {
  Vertx vertx = Vertx.vertx();
  CircuitBreakerOptions options = new CircuitBreakerOptions()
    .setFallbackOnFailure(true)
    .setMaxFailures(10)
    .setResetTimeout(5000)
    .setTimeout(1000)
    .setMetricsRollingWindow(10000);

  CircuitBreaker cba = CircuitBreaker.create("A", vertx, options);
  CircuitBreaker cbb = CircuitBreaker.create("B", vertx, options);
  CircuitBreaker cbc = CircuitBreaker.create("C", vertx, options);

  Router router = Router.router(vertx);
  router.get("/metrics").handler(HystrixMetricHandler.create(vertx));


  router.get("/A").handler(rc -> a(rc, cba));
  router.get("/B").handler(rc -> b(rc, cbb));
  router.get("/C").handler(rc -> c(rc, cbc));

  vertx.createHttpServer()
    .requestHandler(router::accept)
    .listen(8080);
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:26,代码来源:DashboardExample.java

示例10: testOk

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Test
@Repeat(5)
public void testOk() {
  breaker = CircuitBreaker.create("test", vertx, new CircuitBreakerOptions());
  assertThat(breaker.state()).isEqualTo(CircuitBreakerState.CLOSED);

  AtomicBoolean operationCalled = new AtomicBoolean();
  AtomicReference<String> completionCalled = new AtomicReference<>();
  breaker.<String>execute(fut -> {
    operationCalled.set(true);
    fut.complete("hello");
  }).setHandler(ar -> completionCalled.set(ar.result()));

  await().until(operationCalled::get);
  await().until(() -> completionCalled.get().equalsIgnoreCase("hello"));
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:17,代码来源:CircuitBreakerImplTest.java

示例11: testWithUserFutureOk

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Test
@Repeat(5)
public void testWithUserFutureOk() {
  breaker = CircuitBreaker.create("test", vertx, new CircuitBreakerOptions());
  assertThat(breaker.state()).isEqualTo(CircuitBreakerState.CLOSED);

  AtomicBoolean operationCalled = new AtomicBoolean();
  AtomicReference<String> completionCalled = new AtomicReference<>();

  Future<String> userFuture = Future.future();
  userFuture.setHandler(ar ->
    completionCalled.set(ar.result()));

  breaker.executeAndReport(userFuture, fut -> {
    operationCalled.set(true);
    fut.complete("hello");
  });

  await().until(operationCalled::get);
  await().until(() ->  completionCalled.get().equalsIgnoreCase("hello"));
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:22,代码来源:CircuitBreakerImplTest.java

示例12: testAsynchronousOk

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Test
public void testAsynchronousOk() {
  breaker = CircuitBreaker.create("test", vertx, new CircuitBreakerOptions());
  assertThat(breaker.state()).isEqualTo(CircuitBreakerState.CLOSED);

  AtomicBoolean called = new AtomicBoolean();
  AtomicReference<String> result = new AtomicReference<>();
  breaker.<String>execute(future ->
    vertx.setTimer(100, l -> {
      called.set(true);
      future.complete("hello");
    })
  ).setHandler(ar -> result.set(ar.result()));

  await().until(called::get);
  await().untilAtomic(result, is("hello"));
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:18,代码来源:CircuitBreakerImplTest.java

示例13: testAsynchronousWithUserFutureOk

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Test
public void testAsynchronousWithUserFutureOk() {
  breaker = CircuitBreaker.create("test", vertx, new CircuitBreakerOptions());
  assertThat(breaker.state()).isEqualTo(CircuitBreakerState.CLOSED);

  AtomicBoolean called = new AtomicBoolean();
  AtomicReference<String> result = new AtomicReference<>();

  Future<String> userFuture = Future.future();
  userFuture.setHandler(ar -> result.set(ar.result()));

  breaker.executeAndReport(userFuture, future ->
    vertx.setTimer(100, l -> {
      called.set(true);
      future.complete("hello");
    })
  );

  await().until(called::get);
  await().untilAtomic(result, is("hello"));
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:22,代码来源:CircuitBreakerImplTest.java

示例14: setUp

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Before
public void setUp() {
  vertx = Vertx.vertx();
  items.clear();
  cb = CircuitBreaker.create("circuit-breaker", vertx, new CircuitBreakerOptions()
      .setFallbackOnFailure(true)
      .setTimeout(500)
      .setResetTimeout(1000));

  vertx.eventBus().consumer("ok", message -> message.reply("OK"));

  vertx.eventBus().consumer("fail", message -> message.fail(100, "Bad bad bad"));

  vertx.eventBus().consumer("exception", message -> {
    throw new RuntimeException("RT - Bad bad bad");
  });

  vertx.eventBus().consumer("timeout", message -> vertx.setTimer(2000, x -> message.reply("Too late")));
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:20,代码来源:UsageTest.java

示例15: testEviction

import io.vertx.circuitbreaker.CircuitBreakerOptions; //导入依赖的package包/类
@Test
public void testEviction(TestContext tc) {
  breaker = CircuitBreaker.create("some-circuit-breaker", vertx,
    new CircuitBreakerOptions().setMetricsRollingWindow(10));
  Async async = tc.async();


  int count = 1000;

  List<Future> list = new ArrayList<>();
  for (int i = 0; i < count; i++) {
    list.add(breaker.execute(commandThatWorks()));
  }

  CompositeFuture.all(list)
    .setHandler(ar -> {
      assertThat(ar).succeeded();
      assertThat(metrics().getInteger("totalOperationCount")).isEqualTo(1000);
      assertThat(metrics().getInteger("rollingOperationCount")).isLessThan(1000);
      async.complete();
    });
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:23,代码来源:CircuitBreakerMetricsTest.java


注:本文中的io.vertx.circuitbreaker.CircuitBreakerOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。