https://github.com/dcoxall/eventmachine-circuit_breaker
A circuit breaker for eventmachine and em-http-request
https://github.com/dcoxall/eventmachine-circuit_breaker
circuit-breaker eventmachine http middleware
Last synced: 12 months ago
JSON representation
A circuit breaker for eventmachine and em-http-request
- Host: GitHub
- URL: https://github.com/dcoxall/eventmachine-circuit_breaker
- Owner: dcoxall
- License: mit
- Created: 2017-10-26T20:36:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-20T15:16:13.000Z (about 8 years ago)
- Last Synced: 2024-04-25T04:22:26.743Z (almost 2 years ago)
- Topics: circuit-breaker, eventmachine, http, middleware
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# EventMachine::CircuitBreaker
[](https://travis-ci.org/dcoxall/eventmachine-circuit_breaker)
**This project is still in active development**
This library is meant to provide a simple way to enable the circuit breaker pattern to em-http requests by providing some middleware that can prevent requests and manage circuit state based on response parameters.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'eventmachine-circuit_breaker'
```
And then execute:
$ bundle
## Usage
```ruby
require 'eventmachine/circuit_breaker'
require 'em-http-request'
# circuit breaker for all requests
EventMachine.run do
EventMachine::HttpRequest.use EventMachine::CircuitBreaker
# now you can use em-http-request as normal
end
# circuit breaker per connection
EventMachine.run do
connection = EventMachine::HttpRequest.new("http://example.com")
connection.use EventMachine::CircuitBreaker
connection.get
# ...
end
# sharing circuit state
EventMachine.run do
circuit_strategy = EventMachine::CircuitBreaker::Strategy::Basic.new
connection_1 = EventMachine::HttpRequest.new("http://example.com/foo")
connection_1.use EventMachine::CircuitBreaker, strategy: circuit_strategy
connection_1.get
# ...
connection_2 = EventMachine::HttpRequest.new("http://example.com/bar")
connection_2.use EventMachine::CircuitBreaker, strategy: circuit_strategy
connection_2.get
# ...
end
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/dcoxall/eventmachine-circuit_breaker.