hutch 0.23.1 → 0.24.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/.travis.yml +6 -8
- data/CHANGELOG.md +36 -2
- data/Gemfile +3 -1
- data/README.md +60 -17
- data/hutch.gemspec +4 -4
- data/lib/hutch/config.rb +7 -1
- data/lib/hutch/logging.rb +5 -6
- data/lib/hutch/tracers/opbeat.rb +37 -0
- data/lib/hutch/tracers.rb +1 -0
- data/lib/hutch/version.rb +1 -1
- data/lib/hutch/waiter.rb +68 -5
- data/lib/hutch/worker.rb +10 -1
- data/spec/hutch/waiter_spec.rb +28 -14
- data/spec/hutch/worker_spec.rb +19 -1
- data/spec/tracers/opbeat_spec.rb +44 -0
- metadata +16 -9
- data/gemfiles/Gemfile.activesupport4 +0 -2
- data/gemfiles/Gemfile.activesupport5 +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb197fc767359bc60d35790ec650c9c077120d0d
|
4
|
+
data.tar.gz: e1152a8d434fdc9a4752c095ad5fdce4871ffd9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c34020a830413a6e970bfae9e59fecdaebbe770aaf7df753a7f263af6d7dc98b0ae4433a4aafc27d9d8f45689168d0b39a64d3ba4086c05187fc7b0e352d9814
|
7
|
+
data.tar.gz: cc24d3e6ab11c4979455c06ba057760b00cffae9dd577a39f4f89bfe7b45a33378c2190362c2d003a5418b3e64238d2997610c8b4f8f52a5287d0765563109ad
|
data/.travis.yml
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
|
-
before_install:
|
3
|
+
before_install:
|
4
|
+
- gem update --system
|
5
|
+
- gem install bundler
|
4
6
|
matrix:
|
5
7
|
include:
|
6
|
-
- rvm: 2.
|
7
|
-
|
8
|
+
- rvm: 2.4.0
|
9
|
+
- rvm: 2.3.3
|
8
10
|
- rvm: 2.2
|
9
|
-
gemfile: gemfiles/Gemfile.activesupport4
|
10
11
|
- rvm: 2.1
|
11
|
-
gemfile: gemfiles/Gemfile.activesupport4
|
12
12
|
- rvm: 2.0
|
13
|
-
|
14
|
-
- rvm: jruby-9.1.5.0
|
13
|
+
- rvm: jruby-9.1.7.0
|
15
14
|
jdk: oraclejdk8
|
16
|
-
gemfile: gemfiles/Gemfile.activesupport5
|
17
15
|
env:
|
18
16
|
- JRUBY_OPTS='--debug'
|
19
17
|
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,43 @@
|
|
1
1
|
## 0.24.0 — (unreleased)
|
2
2
|
|
3
|
-
|
3
|
+
### Configurable Consumer Prefixes
|
4
4
|
|
5
|
+
Hutch consumers now can use user-provided prefixes for consumer tags.
|
5
6
|
|
6
|
-
|
7
|
+
Contributed by Dávid Lantos.
|
8
|
+
|
9
|
+
GitHub issue: [#265](https://github.com/gocardless/hutch/pull/265)
|
10
|
+
|
11
|
+
### Signal Handling in Workers
|
12
|
+
|
13
|
+
Hutch will now handle several OS signals:
|
14
|
+
|
15
|
+
* `USR2` will log stack traces of all alive VM threads
|
16
|
+
* `QUIT` (except on JRuby), `INT`, `TERM` will cause Hutch daemon to shut down
|
17
|
+
|
18
|
+
Contributed by Olle Jonsson.
|
19
|
+
|
20
|
+
GitHub issues: [#263](https://github.com/gocardless/hutch/pull/263), [#271](https://github.com/gocardless/hutch/pull/271)
|
21
|
+
|
22
|
+
### Opbeat Tracer
|
23
|
+
|
24
|
+
Hutch now provides a tracer implementation for [Opbeat](https://opbeat.com/).
|
25
|
+
|
26
|
+
Contributed by Olle Jonsson.
|
27
|
+
|
28
|
+
GitHub issue: [#262](https://github.com/gocardless/hutch/pull/262)
|
29
|
+
|
30
|
+
### `HUTCH_URI` Support
|
31
|
+
|
32
|
+
The `HUTCH_URI` environment variable now can be used to configure
|
33
|
+
Hutch connection URI.
|
34
|
+
|
35
|
+
Contributed by Sam Stickland.
|
36
|
+
|
37
|
+
GitHub issue: [#270](https://github.com/gocardless/hutch/pull/270)
|
38
|
+
|
39
|
+
|
40
|
+
## 0.23.1 — October 20th, 2016
|
7
41
|
|
8
42
|
This release contains a **breaking change** in the error
|
9
43
|
handlers interface.
|
data/Gemfile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
ruby RUBY_VERSION
|
4
|
+
|
3
5
|
gemspec
|
4
6
|
|
5
7
|
group :development do
|
@@ -14,7 +16,7 @@ group :development do
|
|
14
16
|
end
|
15
17
|
|
16
18
|
group :development, :test do
|
17
|
-
gem "rspec", "~> 3.
|
19
|
+
gem "rspec", "~> 3.5"
|
18
20
|
gem "simplecov", "~> 0.12"
|
19
21
|
|
20
22
|
gem "sentry-raven"
|
data/README.md
CHANGED
@@ -1,29 +1,47 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
Hutch is a Ruby library for enabling asynchronous inter-service communication
|
4
|
-
in a service-oriented architecture, using RabbitMQ.
|
5
|
-
|
6
3
|
[](http://badge.fury.io/rb/hutch)
|
7
4
|
[](https://travis-ci.org/gocardless/hutch)
|
8
5
|
[](https://gemnasium.com/gocardless/hutch)
|
9
6
|
[](https://codeclimate.com/github/gocardless/hutch)
|
10
7
|
|
8
|
+
Hutch is a Ruby library for enabling asynchronous inter-service communication
|
9
|
+
in a service-oriented architecture, using RabbitMQ.
|
10
|
+
|
11
11
|
To install with RubyGems:
|
12
12
|
|
13
13
|
```
|
14
14
|
gem install hutch
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
18
18
|
|
19
|
-
|
20
|
-
that was extracted from production systems.
|
19
|
+
### Table of Contents
|
21
20
|
|
21
|
+
- [Requirements](#requirements)
|
22
|
+
- [Overview](#overview)
|
23
|
+
- [Project Maturity](#project-maturity)
|
24
|
+
- [Consumers](#consumers)
|
25
|
+
- [Message Processing Tracers](#message-processing-tracers)
|
26
|
+
- [Running Hutch](#running-hutch)
|
27
|
+
- [Loading Consumers](#loading-consumers)
|
28
|
+
- [Stopping Hutch](#stopping-hutch)
|
29
|
+
- [Producers](#producers)
|
30
|
+
- [Producer Configuration](#producer-configuration)
|
31
|
+
- [Publisher Confirms](#publisher-confirms)
|
32
|
+
- [Writing Well-Behaved Publishers](#writing-well-behaved-publishers)
|
33
|
+
- [Configuration](#configuration)
|
34
|
+
- [Config File](#config-file)
|
35
|
+
- [Environment variables](#environment-variables)
|
36
|
+
- [Configuration precedence](#configuration-precedence)
|
37
|
+
- [Generated list of configuration options](#generated-list-of-configuration-options)
|
22
38
|
|
23
|
-
|
39
|
+
<!-- Tocer[finish]: Auto-generated, don't remove. -->
|
24
40
|
|
25
|
-
|
41
|
+
## Requirements
|
26
42
|
|
43
|
+
- Hutch requires Ruby 2.0+ or JRuby 9K.
|
44
|
+
- Hutch requires RabbitMQ 3.3 or later.
|
27
45
|
|
28
46
|
## Overview
|
29
47
|
|
@@ -39,8 +57,12 @@ and so on. Publishers connect to RabbitMQ via `Hutch.connect` and publish using
|
|
39
57
|
Hutch uses [Bunny](http://rubybunny.info) or [March Hare](http://rubymarchhare.info)
|
40
58
|
(on JRuby) under the hood.
|
41
59
|
|
60
|
+
### Project Maturity
|
61
|
+
|
62
|
+
Hutch is a moderately mature project (started in early 2013)
|
63
|
+
that was extracted from production systems.
|
42
64
|
|
43
|
-
##
|
65
|
+
## Consumers
|
44
66
|
|
45
67
|
Consumers receive messages from a RabbitMQ queue. That queue may be bound to
|
46
68
|
one or more topics (represented by routing keys).
|
@@ -136,11 +158,13 @@ to learn more.
|
|
136
158
|
|
137
159
|
Tracers allow you to track message processing.
|
138
160
|
|
139
|
-
|
161
|
+
This will enable NewRelic custom instrumentation:
|
162
|
+
|
140
163
|
```ruby
|
141
164
|
Hutch::Config.set(:tracer, Hutch::Tracers::NewRelic)
|
142
165
|
```
|
143
|
-
|
166
|
+
|
167
|
+
Batteries included!
|
144
168
|
|
145
169
|
## Running Hutch
|
146
170
|
|
@@ -279,7 +303,7 @@ end
|
|
279
303
|
If using publisher confirms with amqp gem, see [this issue][pc-issue]
|
280
304
|
and [this gist][pc-gist] for more info.
|
281
305
|
|
282
|
-
## Configuration
|
306
|
+
## Configuration
|
283
307
|
|
284
308
|
### Config File
|
285
309
|
|
@@ -334,7 +358,12 @@ In order from lowest to highest precedence:
|
|
334
358
|
|
335
359
|
### Generated list of configuration options
|
336
360
|
|
337
|
-
|
361
|
+
Generate with
|
362
|
+
|
363
|
+
0. `yard doc lib/hutch/config.rb`
|
364
|
+
0. Copy the _Configuration_ section from `doc/Hutch/Config.html` here, with the anchor tags stripped.
|
365
|
+
|
366
|
+
<table border="1" class="settings" style="overflow:visible;">
|
338
367
|
<thead>
|
339
368
|
<tr>
|
340
369
|
<th>
|
@@ -401,6 +430,15 @@ In order from lowest to highest precedence:
|
|
401
430
|
</td>
|
402
431
|
</tr>
|
403
432
|
|
433
|
+
<tr>
|
434
|
+
<td><tt>uri</tt></td>
|
435
|
+
<td>nil</td>
|
436
|
+
<td>String</td>
|
437
|
+
<td><tt>HUTCH_URI</tt></td>
|
438
|
+
<td><p>RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings)</p>
|
439
|
+
</td>
|
440
|
+
</tr>
|
441
|
+
|
404
442
|
<tr>
|
405
443
|
<td><tt>mq_api_host</tt></td>
|
406
444
|
<td>127.0.0.1</td>
|
@@ -571,15 +609,20 @@ In order from lowest to highest precedence:
|
|
571
609
|
<td><p>Should Bunny's consumer work pool threads abort on exception.</p>
|
572
610
|
</td>
|
573
611
|
</tr>
|
612
|
+
|
613
|
+
<tr>
|
614
|
+
<td><tt>consumer_tag_prefix</tt></td>
|
615
|
+
<td>hutch</td>
|
616
|
+
<td>String</td>
|
617
|
+
<td><tt>HUTCH_CONSUMER_TAG_PREFIX</tt></td>
|
618
|
+
<td><p>Prefix displayed on the consumers tags.</p>
|
619
|
+
</td>
|
620
|
+
</tr>
|
574
621
|
|
575
622
|
</tbody>
|
576
623
|
</table>
|
577
624
|
|
578
625
|
|
579
|
-
## Supported RabbitMQ Versions
|
580
|
-
|
581
|
-
Hutch requires RabbitMQ 3.3 or later.
|
582
|
-
|
583
626
|
---
|
584
627
|
|
585
628
|
GoCardless ♥ open source. If you do too, come [join us](https://gocardless.com/jobs/backend_developer).
|
data/hutch.gemspec
CHANGED
@@ -3,18 +3,18 @@ require File.expand_path('../lib/hutch/version', __FILE__)
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
if defined?(JRUBY_VERSION)
|
5
5
|
gem.platform = 'java'
|
6
|
-
gem.add_runtime_dependency 'march_hare', '>= 2.
|
6
|
+
gem.add_runtime_dependency 'march_hare', '>= 2.22.0'
|
7
7
|
else
|
8
8
|
gem.platform = Gem::Platform::RUBY
|
9
|
-
gem.add_runtime_dependency 'bunny', '>= 2.6.
|
9
|
+
gem.add_runtime_dependency 'bunny', '>= 2.6.3'
|
10
10
|
end
|
11
11
|
gem.add_runtime_dependency 'carrot-top', '~> 0.0.7'
|
12
12
|
gem.add_runtime_dependency 'multi_json', '~> 1.12'
|
13
|
-
gem.add_runtime_dependency 'activesupport'
|
13
|
+
gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 6'
|
14
14
|
|
15
15
|
gem.name = 'hutch'
|
16
16
|
gem.summary = 'Easy inter-service communication using RabbitMQ.'
|
17
|
-
gem.description = 'Hutch is a Ruby library for enabling asynchronous '
|
17
|
+
gem.description = 'Hutch is a Ruby library for enabling asynchronous ' \
|
18
18
|
'inter-service communication using RabbitMQ.'
|
19
19
|
gem.version = Hutch::VERSION.dup
|
20
20
|
gem.required_ruby_version = '>= 2.0'
|
data/lib/hutch/config.rb
CHANGED
@@ -60,6 +60,9 @@ module Hutch
|
|
60
60
|
# RabbitMQ password
|
61
61
|
string_setting :mq_password, 'guest'
|
62
62
|
|
63
|
+
# RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings)
|
64
|
+
string_setting :uri, nil
|
65
|
+
|
63
66
|
# RabbitMQ HTTP API hostname
|
64
67
|
string_setting :mq_api_host, '127.0.0.1'
|
65
68
|
|
@@ -130,6 +133,9 @@ module Hutch
|
|
130
133
|
# The option is ignored on JRuby.
|
131
134
|
boolean_setting :consumer_pool_abort_on_exception, false
|
132
135
|
|
136
|
+
# Prefix displayed on the consumers tags.
|
137
|
+
string_setting :consumer_tag_prefix, 'hutch'
|
138
|
+
|
133
139
|
# Set of all setting keys
|
134
140
|
ALL_KEYS = @boolean_keys + @number_keys + @string_keys
|
135
141
|
|
@@ -267,4 +273,4 @@ module Hutch
|
|
267
273
|
end
|
268
274
|
end
|
269
275
|
end
|
270
|
-
Hutch::Config.initialize
|
276
|
+
Hutch::Config.initialize
|
data/lib/hutch/logging.rb
CHANGED
@@ -9,13 +9,12 @@ module Hutch
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.setup_logger
|
12
|
+
def self.setup_logger
|
13
13
|
require 'hutch/config'
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@logger
|
14
|
+
@logger = Logger.new($stdout).tap do |l|
|
15
|
+
l.level = Hutch::Config.log_level
|
16
|
+
l.formatter = HutchFormatter.new
|
17
|
+
end
|
19
18
|
end
|
20
19
|
|
21
20
|
def self.logger
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'opbeat'
|
2
|
+
|
3
|
+
module Hutch
|
4
|
+
module Tracers
|
5
|
+
# Tracer for Opbeat, which traces each message processed.
|
6
|
+
class Opbeat
|
7
|
+
KIND = 'messaging.hutch'.freeze
|
8
|
+
|
9
|
+
# @param klass [Consumer] Consumer instance (!)
|
10
|
+
def initialize(klass)
|
11
|
+
@klass = klass
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param message [Message]
|
15
|
+
def handle(message)
|
16
|
+
::Opbeat.transaction(sig, KIND, extra: extra_from(message)) do
|
17
|
+
@klass.process(message)
|
18
|
+
end.done(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def sig
|
24
|
+
@klass.class.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def extra_from(message)
|
28
|
+
{
|
29
|
+
body: message.body.to_s,
|
30
|
+
message_id: message.message_id,
|
31
|
+
timestamp: message.timestamp,
|
32
|
+
routing_key: message.routing_key
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/hutch/tracers.rb
CHANGED
data/lib/hutch/version.rb
CHANGED
data/lib/hutch/waiter.rb
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
require 'hutch/logging'
|
2
2
|
|
3
3
|
module Hutch
|
4
|
+
# Signal-handling class.
|
5
|
+
#
|
6
|
+
# Currently, the signal USR2 performs a thread dump,
|
7
|
+
# while QUIT, TERM and INT all perform a graceful shutdown.
|
4
8
|
class Waiter
|
5
9
|
include Logging
|
6
10
|
|
7
|
-
|
11
|
+
class ContinueProcessingSignals < RuntimeError
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.supported_signals_of(list)
|
15
|
+
list.keep_if { |s| Signal.list.keys.include?(s) }.tap do |result|
|
16
|
+
result.delete('QUIT') if defined?(JRUBY_VERSION)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
SHUTDOWN_SIGNALS = supported_signals_of(%w(QUIT TERM INT)).freeze
|
21
|
+
# We have chosen a JRuby-supported signal
|
22
|
+
USER_SIGNALS = supported_signals_of(%w(USR2)).freeze
|
23
|
+
REGISTERED_SIGNALS = (SHUTDOWN_SIGNALS + USER_SIGNALS).freeze
|
8
24
|
|
9
25
|
def self.wait_until_signaled
|
10
26
|
new.wait_until_signaled
|
@@ -14,14 +30,57 @@ module Hutch
|
|
14
30
|
self.sig_read, self.sig_write = IO.pipe
|
15
31
|
|
16
32
|
register_signal_handlers
|
17
|
-
wait_for_signal
|
18
33
|
|
19
|
-
|
20
|
-
|
34
|
+
begin
|
35
|
+
wait_for_signal
|
36
|
+
|
37
|
+
sig = sig_read.gets.strip
|
38
|
+
handle_signal(sig)
|
39
|
+
rescue ContinueProcessingSignals
|
40
|
+
retry
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_signal(sig)
|
45
|
+
raise ContinueProcessingSignals unless REGISTERED_SIGNALS.include?(sig)
|
46
|
+
if user_signal?(sig)
|
47
|
+
handle_user_signal(sig)
|
48
|
+
else
|
49
|
+
handle_shutdown_signal(sig)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @raises ContinueProcessingSignals
|
54
|
+
def handle_user_signal(sig)
|
55
|
+
case sig
|
56
|
+
when 'USR2' then log_thread_backtraces
|
57
|
+
else raise "Assertion failed - unhandled signal: #{sig.inspect}"
|
58
|
+
end
|
59
|
+
raise ContinueProcessingSignals
|
60
|
+
end
|
61
|
+
|
62
|
+
def handle_shutdown_signal(sig)
|
63
|
+
logger.info "caught SIG#{sig}, stopping hutch..."
|
21
64
|
end
|
22
65
|
|
23
66
|
private
|
24
67
|
|
68
|
+
def log_thread_backtraces
|
69
|
+
logger.info 'Requested a VM-wide thread stack trace dump...'
|
70
|
+
Thread.list.each do |thread|
|
71
|
+
logger.info "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
|
72
|
+
logger.info backtrace_for(thread)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def backtrace_for(thread)
|
77
|
+
if thread.backtrace
|
78
|
+
thread.backtrace.join("\n")
|
79
|
+
else
|
80
|
+
'<no backtrace available>'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
25
84
|
attr_accessor :sig_read, :sig_write
|
26
85
|
|
27
86
|
def wait_for_signal
|
@@ -29,7 +88,7 @@ module Hutch
|
|
29
88
|
end
|
30
89
|
|
31
90
|
def register_signal_handlers
|
32
|
-
|
91
|
+
REGISTERED_SIGNALS.each do |sig|
|
33
92
|
# This needs to be reentrant, so we queue up signals to be handled
|
34
93
|
# in the run loop, rather than acting on signals here
|
35
94
|
trap(sig) do
|
@@ -37,5 +96,9 @@ module Hutch
|
|
37
96
|
end
|
38
97
|
end
|
39
98
|
end
|
99
|
+
|
100
|
+
def user_signal?(sig)
|
101
|
+
USER_SIGNALS.include?(sig)
|
102
|
+
end
|
40
103
|
end
|
41
104
|
end
|
data/lib/hutch/worker.rb
CHANGED
@@ -4,6 +4,7 @@ require 'hutch/broker'
|
|
4
4
|
require 'hutch/acknowledgements/nack_on_all_failures'
|
5
5
|
require 'hutch/waiter'
|
6
6
|
require 'carrot-top'
|
7
|
+
require 'securerandom'
|
7
8
|
|
8
9
|
module Hutch
|
9
10
|
class Worker
|
@@ -44,7 +45,7 @@ module Hutch
|
|
44
45
|
queue = @broker.queue(consumer.get_queue_name, consumer.get_arguments)
|
45
46
|
@broker.bind_queue(queue, consumer.routing_keys)
|
46
47
|
|
47
|
-
queue.subscribe(manual_ack: true) do |*args|
|
48
|
+
queue.subscribe(consumer_tag: unique_consumer_tag, manual_ack: true) do |*args|
|
48
49
|
delivery_info, properties, payload = Hutch::Adapter.decode_message(*args)
|
49
50
|
handle_message(consumer, delivery_info, properties, payload)
|
50
51
|
end
|
@@ -103,5 +104,13 @@ module Hutch
|
|
103
104
|
private
|
104
105
|
|
105
106
|
attr_accessor :setup_procs
|
107
|
+
|
108
|
+
def unique_consumer_tag
|
109
|
+
prefix = Hutch::Config[:consumer_tag_prefix]
|
110
|
+
unique_part = SecureRandom.uuid
|
111
|
+
"#{prefix}-#{unique_part}".tap do |tag|
|
112
|
+
raise "Tag must be 255 bytes long at most, current one is #{tag.bytesize} ('#{tag}')" if tag.bytesize > 255
|
113
|
+
end
|
114
|
+
end
|
106
115
|
end
|
107
116
|
end
|
data/spec/hutch/waiter_spec.rb
CHANGED
@@ -12,25 +12,39 @@ RSpec.describe Hutch::Waiter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
context 'a QUIT signal is received', if: RSpec::Support::Ruby.mri? do
|
16
|
+
it 'logs that hutch is stopping' do
|
17
|
+
expect(Hutch::Logging.logger).to receive(:info)
|
18
|
+
.with('caught SIGQUIT, stopping hutch...')
|
19
|
+
|
20
|
+
start_kill_thread('QUIT')
|
21
|
+
described_class.wait_until_signaled
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'a TERM signal is received' do
|
26
|
+
it 'logs that hutch is stopping' do
|
27
|
+
expect(Hutch::Logging.logger).to receive(:info)
|
28
|
+
.with('caught SIGTERM, stopping hutch...')
|
29
|
+
|
30
|
+
start_kill_thread('TERM')
|
31
|
+
described_class.wait_until_signaled
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'a INT signal is received' do
|
36
|
+
it 'logs that hutch is stopping' do
|
37
|
+
expect(Hutch::Logging.logger).to receive(:info)
|
38
|
+
.with('caught SIGINT, stopping hutch...')
|
39
|
+
|
40
|
+
start_kill_thread('INT')
|
41
|
+
described_class.wait_until_signaled
|
28
42
|
end
|
29
43
|
end
|
30
44
|
end
|
31
45
|
|
32
46
|
describe described_class::SHUTDOWN_SIGNALS do
|
33
|
-
it
|
47
|
+
it 'includes only things in Signal.list.keys' do
|
34
48
|
expect(described_class).to eq(described_class & Signal.list.keys)
|
35
49
|
end
|
36
50
|
end
|
data/spec/hutch/worker_spec.rb
CHANGED
@@ -45,9 +45,27 @@ describe Hutch::Worker do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'sets up a subscription' do
|
48
|
-
expect(queue).to receive(:subscribe).with(manual_ack: true)
|
48
|
+
expect(queue).to receive(:subscribe).with(consumer_tag: %r(^hutch\-.{36}$), manual_ack: true)
|
49
49
|
worker.setup_queue(consumer)
|
50
50
|
end
|
51
|
+
|
52
|
+
context 'with a configured consumer tag prefix' do
|
53
|
+
before { Hutch::Config.set(:consumer_tag_prefix, 'appname') }
|
54
|
+
|
55
|
+
it 'sets up a subscription with the configured tag prefix' do
|
56
|
+
expect(queue).to receive(:subscribe).with(consumer_tag: %r(^appname\-.{36}$), manual_ack: true)
|
57
|
+
worker.setup_queue(consumer)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with a configured consumer tag prefix that is too long' do
|
62
|
+
let(:maximum_size) { 255 - SecureRandom.uuid.size - 1 }
|
63
|
+
before { Hutch::Config.set(:consumer_tag_prefix, 'a'.*(maximum_size + 1)) }
|
64
|
+
|
65
|
+
it 'raises an error' do
|
66
|
+
expect { worker.setup_queue(consumer) }.to raise_error(/Tag must be 255 bytes long at most/)
|
67
|
+
end
|
68
|
+
end
|
51
69
|
end
|
52
70
|
|
53
71
|
describe '#handle_message' do
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'hutch/message'
|
2
|
+
require 'hutch/serializers/identity'
|
3
|
+
require 'hutch/tracers'
|
4
|
+
|
5
|
+
RSpec.describe Hutch::Tracers::Opbeat do
|
6
|
+
let(:consumer) { double('the-consumer') }
|
7
|
+
|
8
|
+
subject(:tracer) { described_class.new(consumer) }
|
9
|
+
|
10
|
+
let(:message) do
|
11
|
+
Hutch::Message.new(double('the-delivery-info', routing_key: 'foo.bar',
|
12
|
+
exchange: 'foo'),
|
13
|
+
double('the-properties', message_id: 'the-id',
|
14
|
+
timestamp: 'the-time'),
|
15
|
+
double('the-payload', to_s: 'the-body'),
|
16
|
+
Hutch::Serializers::Identity)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'formats messages as extra information' do
|
20
|
+
expected_extra = {
|
21
|
+
body: 'the-body',
|
22
|
+
message_id: 'the-id',
|
23
|
+
timestamp: 'the-time',
|
24
|
+
routing_key: 'foo.bar'
|
25
|
+
}
|
26
|
+
expect(Opbeat).to receive(:transaction).with(anything,
|
27
|
+
'messaging.hutch',
|
28
|
+
extra: expected_extra) {
|
29
|
+
double('done-callback', done: true)
|
30
|
+
}
|
31
|
+
|
32
|
+
tracer.handle(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'presents consumer class name as Opbeat tracing signature' do
|
36
|
+
expect(Opbeat).to receive(:transaction).with(consumer.class.name,
|
37
|
+
'messaging.hutch',
|
38
|
+
anything) {
|
39
|
+
double('done-callback', done: true)
|
40
|
+
}
|
41
|
+
|
42
|
+
tracer.handle(message)
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hutch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.24.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: 2017-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.6.
|
19
|
+
version: 2.6.3
|
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: 2.6.
|
26
|
+
version: 2.6.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: carrot-top
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,20 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.2'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '6'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
71
|
+
version: '4.2'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '6'
|
69
75
|
description: Hutch is a Ruby library for enabling asynchronous inter-service communication
|
70
76
|
using RabbitMQ.
|
71
77
|
email:
|
@@ -88,8 +94,6 @@ files:
|
|
88
94
|
- bin/hutch
|
89
95
|
- examples/consumer.rb
|
90
96
|
- examples/producer.rb
|
91
|
-
- gemfiles/Gemfile.activesupport4
|
92
|
-
- gemfiles/Gemfile.activesupport5
|
93
97
|
- hutch.gemspec
|
94
98
|
- lib/hutch.rb
|
95
99
|
- lib/hutch/acknowledgements/base.rb
|
@@ -116,6 +120,7 @@ files:
|
|
116
120
|
- lib/hutch/tracers.rb
|
117
121
|
- lib/hutch/tracers/newrelic.rb
|
118
122
|
- lib/hutch/tracers/null_tracer.rb
|
123
|
+
- lib/hutch/tracers/opbeat.rb
|
119
124
|
- lib/hutch/version.rb
|
120
125
|
- lib/hutch/waiter.rb
|
121
126
|
- lib/hutch/worker.rb
|
@@ -137,6 +142,7 @@ files:
|
|
137
142
|
- spec/hutch/worker_spec.rb
|
138
143
|
- spec/hutch_spec.rb
|
139
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/tracers/opbeat_spec.rb
|
140
146
|
- templates/default/class/html/settings.erb
|
141
147
|
- templates/default/class/setup.rb
|
142
148
|
- templates/default/fulldoc/html/css/hutch.css
|
@@ -166,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
172
|
version: '0'
|
167
173
|
requirements: []
|
168
174
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.5.1
|
170
176
|
signing_key:
|
171
177
|
specification_version: 4
|
172
178
|
summary: Easy inter-service communication using RabbitMQ.
|
@@ -187,3 +193,4 @@ test_files:
|
|
187
193
|
- spec/hutch/worker_spec.rb
|
188
194
|
- spec/hutch_spec.rb
|
189
195
|
- spec/spec_helper.rb
|
196
|
+
- spec/tracers/opbeat_spec.rb
|