hutch 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/Gemfile +1 -0
- data/README.md +5 -2
- data/hutch.gemspec +1 -1
- data/lib/hutch.rb +4 -6
- data/lib/hutch/broker.rb +13 -6
- data/lib/hutch/config.rb +3 -0
- data/lib/hutch/error_handlers.rb +3 -2
- data/lib/hutch/error_handlers/honeybadger.rb +28 -0
- data/lib/hutch/version.rb +1 -1
- data/spec/hutch/error_handlers/honeybadger_spec.rb +36 -0
- data/spec/hutch_spec.rb +33 -5
- metadata +22 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c92582d4268b9d9623c60f4b2588d4afc244c17
|
4
|
+
data.tar.gz: f783601d90dd7031c90c6a6372eb6f2b6b4ef2e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e40a52fafa102ec87c2df5e885dcffd48a0a6786b08cd4c133122e4da85a2a614aeca75513fbd4f3d464409b6d8189c8585ea4b9d456f893e44b97957ffcba0a
|
7
|
+
data.tar.gz: 19f8a9dc63bf258f9b0211f49f9b21a509266a1f09eb2d3e3865d3acc2d2eb13a6fdc5d4c682accbaf98ec6d4794f1775d28156723a62e88be2b68c651e4d8bc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1
|
+
## 0.14.0 — (unreleased)
|
2
|
+
|
3
|
+
### Configurable Socket Timeouts
|
4
|
+
|
5
|
+
Socket read and write timeouts are now configurable using
|
6
|
+
the `read_timeout` and `write_timeout` options, respectively.
|
7
|
+
|
8
|
+
Contributed by Chris Barton.
|
9
|
+
|
10
|
+
|
11
|
+
### Logged Messages as Serialised as JSON
|
12
|
+
|
13
|
+
...as opposed to Ruby object printing.
|
14
|
+
|
15
|
+
Contributed by Andrew Morton.
|
16
|
+
|
17
|
+
|
18
|
+
### Configurable Heartbeat
|
19
|
+
|
20
|
+
Config now supports a new option: `:heartbeat`, which is passed
|
21
|
+
on to Bunny.
|
22
|
+
|
23
|
+
Contributed by Simon Taranto.
|
24
|
+
|
25
|
+
|
26
|
+
### HoneyBadger Error Handler
|
27
|
+
|
28
|
+
Contributed by Daniel Farrell.
|
29
|
+
|
30
|
+
|
31
|
+
### Hutch.connected? Now Returns Up-to-Date Value
|
32
|
+
|
33
|
+
`Hutch.connected?` no longer relies on an ivar and always returns
|
34
|
+
an up-to-date value.
|
35
|
+
|
36
|
+
Contributed by Pierre-Louis Gottfrois.
|
37
|
+
|
38
|
+
|
1
39
|
## 0.13.0 — Dec 5th, 2014
|
2
40
|
|
3
41
|
### HTTP API Can Be Disabled for Consumers
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -242,12 +242,15 @@ Known configuration parameters are:
|
|
242
242
|
* `force_publisher_confirms`: enables publisher confirms, forces `Hutch::Broker#wait_for_confirms` for every publish. **This is the safest option which also offers the lowest throughput**.
|
243
243
|
* `log_level`: log level used by the standard Ruby logger (default: `Logger::INFO`)
|
244
244
|
* `mq_exchange`: exchange to use for publishing (default: `hutch`)
|
245
|
+
* `heartbeat`: [RabbitMQ heartbeat timeout](http://rabbitmq.com/heartbeats.html) (default: `30`)
|
246
|
+
* `connection_timeout`: Bunny's socket open timeout (default: `11`)
|
247
|
+
* `read_timeout`: Bunny's socket read timeout (default: `11`)
|
248
|
+
* `write_timemout`: Bunny's socket write timeout (default: `11`)
|
245
249
|
|
246
250
|
|
247
251
|
## Supported RabbitMQ Versions
|
248
252
|
|
249
|
-
Hutch requires RabbitMQ
|
250
|
-
are recommended.
|
253
|
+
Hutch requires RabbitMQ 3.3 or later.
|
251
254
|
|
252
255
|
---
|
253
256
|
|
data/hutch.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../lib/hutch/version', __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
|
-
gem.add_runtime_dependency 'bunny', '>= 1.
|
4
|
+
gem.add_runtime_dependency 'bunny', '>= 1.7.0'
|
5
5
|
gem.add_runtime_dependency 'carrot-top', '~> 0.0.7'
|
6
6
|
gem.add_runtime_dependency 'multi_json', '~> 1.5'
|
7
7
|
gem.add_development_dependency 'rspec', '~> 3.0'
|
data/lib/hutch.rb
CHANGED
@@ -35,15 +35,11 @@ module Hutch
|
|
35
35
|
unless connected?
|
36
36
|
@broker = Hutch::Broker.new(config)
|
37
37
|
@broker.connect(options)
|
38
|
-
@connected = true
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
41
|
def self.disconnect
|
43
|
-
if @broker
|
44
|
-
@broker.disconnect
|
45
|
-
@connected = false
|
46
|
-
end
|
42
|
+
@broker.disconnect if @broker
|
47
43
|
end
|
48
44
|
|
49
45
|
def self.broker
|
@@ -51,7 +47,9 @@ module Hutch
|
|
51
47
|
end
|
52
48
|
|
53
49
|
def self.connected?
|
54
|
-
|
50
|
+
return false unless broker
|
51
|
+
return false unless broker.connection
|
52
|
+
broker.connection.open?
|
55
53
|
end
|
56
54
|
|
57
55
|
def self.publish(*args)
|
data/lib/hutch/broker.rb
CHANGED
@@ -77,15 +77,22 @@ module Hutch
|
|
77
77
|
tls = @config[:mq_tls]
|
78
78
|
tls_key = @config[:mq_tls_key]
|
79
79
|
tls_cert = @config[:mq_tls_cert]
|
80
|
+
heartbeat = @config[:heartbeat]
|
80
81
|
connection_timeout = @config[:connection_timeout]
|
82
|
+
read_timeout = @config[:read_timeout]
|
83
|
+
write_timeout = @config[:write_timeout]
|
84
|
+
|
81
85
|
protocol = tls ? "amqps://" : "amqp://"
|
82
86
|
sanitized_uri = "#{protocol}#{username}@#{host}:#{port}/#{vhost.sub(/^\//, '')}"
|
83
87
|
logger.info "connecting to rabbitmq (#{sanitized_uri})"
|
84
88
|
@connection = Bunny.new(host: host, port: port, vhost: vhost,
|
85
89
|
tls: tls, tls_key: tls_key, tls_cert: tls_cert,
|
86
90
|
username: username, password: password,
|
87
|
-
heartbeat:
|
88
|
-
network_recovery_interval: 1,
|
91
|
+
heartbeat: heartbeat, automatically_recover: true,
|
92
|
+
network_recovery_interval: 1,
|
93
|
+
connection_timeout: connection_timeout,
|
94
|
+
read_timeout: read_timeout,
|
95
|
+
write_timeout: write_timeout)
|
89
96
|
|
90
97
|
with_bunny_connection_handler(sanitized_uri) do
|
91
98
|
@connection.start
|
@@ -215,9 +222,9 @@ module Hutch
|
|
215
222
|
}
|
216
223
|
properties[:message_id] ||= generate_id
|
217
224
|
|
218
|
-
|
219
|
-
|
220
|
-
response = @exchange.publish(
|
225
|
+
json = JSON.dump(message)
|
226
|
+
logger.info("publishing message '#{json}' to #{routing_key}")
|
227
|
+
response = @exchange.publish(json, {persistent: true}.
|
221
228
|
merge(properties).
|
222
229
|
merge(global_properties).
|
223
230
|
merge(non_overridable_properties))
|
@@ -241,7 +248,7 @@ module Hutch
|
|
241
248
|
private
|
242
249
|
|
243
250
|
def raise_publish_error(reason, routing_key, message)
|
244
|
-
msg = "
|
251
|
+
msg = "unable to publish - #{reason}. Message: #{JSON.dump(message)}, Routing key: #{routing_key}."
|
245
252
|
logger.error(msg)
|
246
253
|
raise PublishError, msg
|
247
254
|
end
|
data/lib/hutch/config.rb
CHANGED
@@ -21,6 +21,7 @@ module Hutch
|
|
21
21
|
mq_api_host: 'localhost',
|
22
22
|
mq_api_port: 15672,
|
23
23
|
mq_api_ssl: false,
|
24
|
+
heartbeat: 30,
|
24
25
|
# placeholder, allows specifying connection parameters
|
25
26
|
# as a URI.
|
26
27
|
uri: nil,
|
@@ -40,6 +41,8 @@ module Hutch
|
|
40
41
|
force_publisher_confirms: false,
|
41
42
|
# Heroku needs > 10. MK.
|
42
43
|
connection_timeout: 11,
|
44
|
+
read_timeout: 11,
|
45
|
+
write_timeout: 11,
|
43
46
|
enable_http_api_use: true
|
44
47
|
}.merge(params)
|
45
48
|
end
|
data/lib/hutch/error_handlers.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Hutch
|
2
2
|
module ErrorHandlers
|
3
|
-
autoload :Logger,
|
4
|
-
autoload :Sentry,
|
3
|
+
autoload :Logger, 'hutch/error_handlers/logger'
|
4
|
+
autoload :Sentry, 'hutch/error_handlers/sentry'
|
5
|
+
autoload :Honeybadger, 'hutch/error_handlers/honeybadger'
|
5
6
|
end
|
6
7
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'hutch/logging'
|
2
|
+
require 'honeybadger'
|
3
|
+
|
4
|
+
module Hutch
|
5
|
+
module ErrorHandlers
|
6
|
+
class Honeybadger
|
7
|
+
include Logging
|
8
|
+
|
9
|
+
def handle(message_id, payload, consumer, ex)
|
10
|
+
prefix = "message(#{message_id || '-'}): "
|
11
|
+
logger.error prefix + "Logging event to Honeybadger"
|
12
|
+
logger.error prefix + "#{ex.class} - #{ex.message}"
|
13
|
+
::Honeybadger.notify_or_ignore(
|
14
|
+
:error_class => ex.class.name,
|
15
|
+
:error_message => "#{ ex.class.name }: #{ ex.message }",
|
16
|
+
:backtrace => ex.backtrace,
|
17
|
+
:context => {
|
18
|
+
:message_id => message_id,
|
19
|
+
:consumer => consumer
|
20
|
+
},
|
21
|
+
:parameters => {
|
22
|
+
:payload => payload
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/hutch/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hutch::ErrorHandlers::Honeybadger do
|
4
|
+
let(:error_handler) { Hutch::ErrorHandlers::Honeybadger.new }
|
5
|
+
|
6
|
+
describe '#handle' do
|
7
|
+
let(:error) do
|
8
|
+
begin
|
9
|
+
raise "Stuff went wrong"
|
10
|
+
rescue RuntimeError => err
|
11
|
+
err
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "logs the error to Honeybadger" do
|
16
|
+
message_id = "1"
|
17
|
+
payload = "{}"
|
18
|
+
consumer = double
|
19
|
+
ex = error
|
20
|
+
message = {
|
21
|
+
:error_class => ex.class.name,
|
22
|
+
:error_message => "#{ ex.class.name }: #{ ex.message }",
|
23
|
+
:backtrace => ex.backtrace,
|
24
|
+
:context => {
|
25
|
+
:message_id => message_id,
|
26
|
+
:consumer => consumer
|
27
|
+
},
|
28
|
+
:parameters => {
|
29
|
+
:payload => payload
|
30
|
+
}
|
31
|
+
}
|
32
|
+
expect(::Honeybadger).to receive(:notify_or_ignore).with(message)
|
33
|
+
error_handler.handle(message_id, payload, consumer, ex)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/hutch_spec.rb
CHANGED
@@ -27,11 +27,6 @@ describe Hutch do
|
|
27
27
|
action
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'sets @connect' do
|
31
|
-
action
|
32
|
-
|
33
|
-
expect(Hutch.connected?).to be_truthy
|
34
|
-
end
|
35
30
|
end
|
36
31
|
|
37
32
|
context 'connected' do
|
@@ -44,6 +39,39 @@ describe Hutch do
|
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
42
|
+
describe '.connected?' do
|
43
|
+
subject(:connected?) { Hutch.connected? }
|
44
|
+
|
45
|
+
before { allow(Hutch).to receive(:broker).and_return(broker) }
|
46
|
+
|
47
|
+
context 'without a broker' do
|
48
|
+
let(:broker) { nil }
|
49
|
+
|
50
|
+
it { expect(connected?).to be_falsey }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'without a connection' do
|
54
|
+
let(:connection) { nil }
|
55
|
+
let(:broker) { double(:broker, connection: connection) }
|
56
|
+
|
57
|
+
it { expect(connected?).to be_falsey }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with a closed connection' do
|
61
|
+
let(:connection) { double(:connection, open?: false) }
|
62
|
+
let(:broker) { double(:broker, connection: connection) }
|
63
|
+
|
64
|
+
it { expect(connected?).to be_falsey }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with an opened connection' do
|
68
|
+
let(:connection) { double(:connection, open?: true) }
|
69
|
+
let(:broker) { double(:broker, connection: connection) }
|
70
|
+
|
71
|
+
it { expect(connected?).to be_truthy }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
47
75
|
describe '#publish' do
|
48
76
|
let(:broker) { double(Hutch::Broker) }
|
49
77
|
let(:args) { ['test.key', 'message', { headers: { foo: 'bar' } }] }
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hutch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.7.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.7.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: carrot-top
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.0.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: multi_json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.7.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.7.1
|
83
83
|
description: Hutch is a Ruby library for enabling asynchronous inter-service communication
|
@@ -89,8 +89,8 @@ executables:
|
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
|
-
- .gitignore
|
93
|
-
- .travis.yml
|
92
|
+
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
94
94
|
- CHANGELOG.md
|
95
95
|
- Gemfile
|
96
96
|
- Guardfile
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/hutch/config.rb
|
109
109
|
- lib/hutch/consumer.rb
|
110
110
|
- lib/hutch/error_handlers.rb
|
111
|
+
- lib/hutch/error_handlers/honeybadger.rb
|
111
112
|
- lib/hutch/error_handlers/logger.rb
|
112
113
|
- lib/hutch/error_handlers/sentry.rb
|
113
114
|
- lib/hutch/exceptions.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- spec/hutch/cli_spec.rb
|
120
121
|
- spec/hutch/config_spec.rb
|
121
122
|
- spec/hutch/consumer_spec.rb
|
123
|
+
- spec/hutch/error_handlers/honeybadger_spec.rb
|
122
124
|
- spec/hutch/error_handlers/logger_spec.rb
|
123
125
|
- spec/hutch/error_handlers/sentry_spec.rb
|
124
126
|
- spec/hutch/logger_spec.rb
|
@@ -136,17 +138,17 @@ require_paths:
|
|
136
138
|
- lib
|
137
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
140
|
requirements:
|
139
|
-
- -
|
141
|
+
- - ">="
|
140
142
|
- !ruby/object:Gem::Version
|
141
143
|
version: '0'
|
142
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
145
|
requirements:
|
144
|
-
- -
|
146
|
+
- - ">="
|
145
147
|
- !ruby/object:Gem::Version
|
146
148
|
version: '0'
|
147
149
|
requirements: []
|
148
150
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.4.5
|
150
152
|
signing_key:
|
151
153
|
specification_version: 4
|
152
154
|
summary: Easy inter-service communication using RabbitMQ.
|
@@ -155,6 +157,7 @@ test_files:
|
|
155
157
|
- spec/hutch/cli_spec.rb
|
156
158
|
- spec/hutch/config_spec.rb
|
157
159
|
- spec/hutch/consumer_spec.rb
|
160
|
+
- spec/hutch/error_handlers/honeybadger_spec.rb
|
158
161
|
- spec/hutch/error_handlers/logger_spec.rb
|
159
162
|
- spec/hutch/error_handlers/sentry_spec.rb
|
160
163
|
- spec/hutch/logger_spec.rb
|