Skip to content

Instantly share code, notes, and snippets.

@tuan3w
Created July 28, 2017 04:45
Show Gist options
  • Save tuan3w/de7cbc82572bbdf235bbb326becb21c8 to your computer and use it in GitHub Desktop.
Save tuan3w/de7cbc82572bbdf235bbb326becb21c8 to your computer and use it in GitHub Desktop.
sample circuit breaker with vertx
import com.soundcloud.prometheus.hystrix.HystrixPrometheusMetricsPublisher;
import com.vcc.bigdata.micro.cmd.FailCommand;
import io.vertx.circuitbreaker.CircuitBreaker;
import io.vertx.circuitbreaker.CircuitBreakerOptions;
import io.vertx.circuitbreaker.HystrixMetricHandler;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.web.Router;
public class VertxHystrixSample extends AbstractVerticle {
public int counter = 0;
@Override
public void start() throws Exception {
HttpServerOptions serverOtions = new HttpServerOptions();
HystrixPrometheusMetricsPublisher.register("test");
// create curcuit breaker
Router route = Router.router(vertx);
route.route("/metrics").handler(HystrixMetricHandler.create(vertx));
route.route("/cmd").handler(hdl -> {
//execute some hystrix command
FailCommand cmd = new FailCommand(0.6);
String result = cmd.execute();
hdl.response().end(result);
});
HttpServer server = vertx.createHttpServer(serverOtions)
.requestHandler(route::accept);
server.listen(8000);
System.out.println("Server is started!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment