项目作者: joelittlejohn

项目描述 :
A Clojure library to wrap clj-http requests as hystrix commands
高级语言: Clojure
项目地址: git://github.com/joelittlejohn/clj-http-hystrix.git
创建时间: 2014-10-11T22:55:43Z
项目社区:https://github.com/joelittlejohn/clj-http-hystrix

开源协议:Eclipse Public License 1.0

下载


clj-http-hystrix Build Status Coverage Status

latest version

A Clojure library to wrap clj-http requests as hystrix commands whenever a request options map includes :hystrix/... keys.

Usage

When you start your app, add:

  1. (clj-http-hystrix.core/add-hook)

Whenever you make an http request, add one or more of the hystrix-clj options to your options map, e.g.:

  1. (http/get "http://www.google.com" {:hystrix/command-key :default
  2. :hystrix/fallback-fn default-fallback
  3. :hystrix/group-key :default
  4. :hystrix/threads 10
  5. :hystrix/queue-size 5
  6. :hystrix/timeout-ms 1000
  7. :hystrix/breaker-request-volume 20
  8. :hystrix/breaker-error-percent 50
  9. :hystrix/breaker-sleep-window-ms 5000
  10. :hystrix/bad-request-pred client-error?})

Requests without any :hystrix/... keys won’t use Hystrix. If you include at least one :hystrix/... key then any keys not specified will take the above (default) values.

Custom default values can be specified when registering with add-hook. Any keys you supply will override the defaults shown above:

  1. (clj-http-hystrix.core/add-hook {:hystrix/timeout-ms 2500
  2. :hystrix/queue-size 12})

Bad requests

Hystrix allows some failures to be marked as bad requests, that is, requests that have failed because of a badly formed request rather than an error in the downstream service1. clj-http-hystrix allows a predicate to be supplied under the :hystrix/bad-request-pred key, and if this predicate returns true for a given request & response, then the failure will be considered a ‘bad request’ (and not counted towards the failure metrics for a command).

By default, all client errors (4xx family of response codes) are considered Hystrix bad requests and are not counted towards the failure metrics for a command. There are some useful predicates and predicate generators provided2.

Cached vs dynamic configuration

Hystrix caches configuration for a command and hence there are limits to how this library can react to configuration options that vary dynamically. For a given command-key, the :hystrix/timeout-ms will be fixed on first use. This means it’s a bad idea to reuse the :hystrix/command-key value in many parts of your app. When you want a new configuration, you should use a new :hystrix/command-key value.

The same is true for thread pools - configuration is cached per :hystrix/group-key, so if you need to use a different value for :hystrix/queue-size or :hystrix/threads then you should use a new :hystrix/group-key value.

License

Copyright © 2014 Joe Littlejohn, Mark Tinsley

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.