hutch 0.27.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07e4ec8d85eefed7b25ae9bb43fb3c0ff8ffe0a4f24526b986686906aaa0f5cc
4
- data.tar.gz: 94062cdf67c00e9224d3fee9be1fa294ba0e234f8400ec4efc640eaecc07a2df
3
+ metadata.gz: 9725ddb3e39e305bad95abd6c8605c1d9828691904bb2ae31430fd22d88bd180
4
+ data.tar.gz: db1d87d81de0f89c84b1ec387c66443aa9ead6be2d71b50b6cee32e9146dd080
5
5
  SHA512:
6
- metadata.gz: e5a9ef9a749741aee734246701cde0a99f1c36f02e730eb1e888d2a125dba6e4ed9f9cdf945656ebbf8dcd118775c4717110c4d542b6547df84119baeb29f0a4
7
- data.tar.gz: 8a929dafd7c168256da9c349e4bf60a052456f2d34db4e717e3c46a08e461dac60f95ea6903a76a54bb934fbbcabb62a1c2e24b662469d3e5afd9e459a165b2c
6
+ metadata.gz: 296138c5cb4c08340f4a72bb8d30009402272f9843efffd0dc1d647328ca1531d188fd3b5a9a15f891f4a8447dbf5f72a7a583aa702f1c999fc557c1ab4ac024
7
+ data.tar.gz: 2c0406261d2535d5e5d00037e20e29f5cb781e337732491cf36195231e5d647b75c0d96d74c0861afa36cfb24575a0e2b34ce06f59693a98b84342cf1d52ad95
@@ -0,0 +1,42 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ services:
15
+ rabbitmq:
16
+ image: rabbitmq:3-management
17
+ ports:
18
+ - 5672:5672
19
+ - 15672:15672
20
+ options: --name rabbitmq
21
+
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ ruby-version: ['jruby-9.2.19.0', 'jruby-9.3.0.0', 'jruby-head']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ uses: ruby/setup-ruby@v1
33
+ # uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Set up RabbitMQ
38
+ run: |
39
+ until sudo lsof -i:5672; do echo "Waiting for RabbitMQ to start..."; sleep 1; done
40
+ ./bin/ci/before_build_docker.sh
41
+ - name: Run tests
42
+ run: bundle exec rspec spec
data/CHANGELOG.md CHANGED
@@ -1,8 +1,150 @@
1
- ## 0.28.0 (under development)
1
+ ## 1.1.1 (March 18th, 2022)
2
+ ### Dependency Bump
2
3
 
3
- No chages yet.
4
+ Hutch now allows ActiveSupport 7.x.
4
5
 
5
6
 
7
+ ## 1.1.0 (July 26th, 2021)
8
+
9
+ ### Bugsnag Error Handler
10
+
11
+ Contributed by @ivanhuang1.
12
+
13
+ GitHub issue: [#362](https://github.com/ruby-amqp/hutch/pull/362)
14
+
15
+ ### Datadog Tracer
16
+
17
+ Contributed by Karol @Azdaroth Galanciak.
18
+
19
+ GitHub issue: [#360](https://github.com/ruby-amqp/hutch/pull/360)
20
+
21
+ ### Updated Sentry Error Handler
22
+
23
+ Contributed by Karol @Azdaroth Galanciak.
24
+
25
+ GitHub issue: [#363](https://github.com/ruby-amqp/hutch/pull/363)
26
+
27
+ ### Type Casting for Values Set Using Hutch::Config.set
28
+
29
+ Values set with `Hutch::Config.set` now have expected setting type casting
30
+ applied to them.
31
+
32
+ Contributed by Karol @Azdaroth Galanciak.
33
+
34
+ GitHub issue: [#358](https://github.com/ruby-amqp/hutch/pull/358)
35
+
36
+ ### Wider MultiJson Adoption
37
+
38
+ Contributed by Ulysse @BuonOmo Buonomo.
39
+
40
+ GitHub issue: [#356](https://github.com/ruby-amqp/hutch/pull/356)
41
+
42
+ ### README Corrections
43
+
44
+ Contributed by Johan @johankok Kok.
45
+
46
+ GitHub issue: [#353](https://github.com/ruby-amqp/hutch/pull/353)
47
+
48
+ ## 1.0.0 (April 8th, 2020)
49
+
50
+ Hutch has been around for several years. It is time to ship a 1.0. With it we try to correct
51
+ a few of overly opinionated decisions from recent releases. This means this release
52
+ contains potentially breaking changes.
53
+
54
+ ### Breaking Changes
55
+
56
+ * Hutch will no longer configure any queue type (such as [quorum queues](https://www.rabbitmq.com/quorum-queues.html))
57
+ or queue mode (used by classic [lazy queues](https://www.rabbitmq.com/lazy-queues.html))
58
+ by default as that can be breaking change for existing Hutch and RabbitMQ installations due to the
59
+ [property equivalence requirement](https://www.rabbitmq.com/queues.html#property-equivalence) in AMQP 0-9-1.
60
+
61
+ This means **some defaults introduced in `0.28.0` ([gocardless/hutch#341](https://github.com/gocardless/hutch/pull/341)) were reverted**.
62
+ The user has to opt in to configure the queue type and mode and other [optional arguments](https://www.rabbitmq.com/queues.html#optional-arguments) they need to use.
63
+ Most optional arguments can be set via [policies](https://www.rabbitmq.com/parameters.html#policies) which is always the recommended approach.
64
+ Queue type, unfortunately, is not one of them as different queue types have completely different
65
+ implementation details, on disk data formats and so on.
66
+
67
+ To use a quorum queue, use the `quorum_queue` consumer DSL method:
68
+
69
+ ``` ruby
70
+ class ConsumerUsingQuorumQueue
71
+ include Hutch::Consumer
72
+ consume 'hutch.test1'
73
+ # when in doubt, prefer using a policy to this DSL
74
+ # https://www.rabbitmq.com/parameters.html#policies
75
+ arguments 'x-key': :value
76
+
77
+ quorum_queue
78
+ end
79
+ ```
80
+
81
+ To use a classic lazy queue, use the `lazy_queue` consumer DSL method:
82
+
83
+ ``` ruby
84
+ class ConsumerUsingLazyQueue
85
+ include Hutch::Consumer
86
+ consume 'hutch.test1'
87
+ # when in doubt, prefer using a policy to this DSL
88
+ # https://www.rabbitmq.com/parameters.html#policies
89
+ arguments 'x-key': :value
90
+
91
+ lazy_queue
92
+ classic_queue
93
+ end
94
+ ```
95
+
96
+ By default Hutch will not configure any `x-queue-type` or `x-queue-mode` optional arguments
97
+ which is identical to RabbitMQ defaults (a regular classic queue).
98
+
99
+ Note that as of RabbitMQ 3.8.2, an omitted `x-queue-type` is [considered to be identical](https://github.com/rabbitmq/rabbitmq-common/issues/341)
100
+ to `x-queue-type` set to `classic` by RabbitMQ server.
101
+
102
+
103
+ #### Enhancements
104
+
105
+ * Exchange type is now configurable via the `mq_exchange_type` config setting. Supported exchanges must be
106
+ compatible with topic exchanges (e.g. wrap it). Default value is `topic`.
107
+
108
+ This feature is limited to topic and delayed message exchange plugins and is mostly
109
+ useful for forward compatibility.
110
+
111
+ Contributed by Michael Bumann.
112
+
113
+ GitHub issue: [gocardless/hutch#349](https://github.com/gocardless/hutch/pull/349)
114
+
115
+
116
+ ## 0.28.0 (March 17, 2020)
117
+
118
+ ### Enhancements
119
+
120
+ * Add lazy and quorum options for queues.
121
+
122
+ GitHub issue: [gocardless/hutch#341](https://github.com/gocardless/hutch/pull/341)
123
+
124
+ Contributed by: Arthur Del Esposte
125
+
126
+ * Log level in the message publisher switched to DEBUG.
127
+
128
+ GitHub issue: [gocardless/hutch#343](https://github.com/gocardless/hutch/pull/343)
129
+
130
+ Contributed by: Codruț Constantin Gușoi
131
+
132
+ ### Documentation
133
+
134
+ * Add zeitwerk note to README.
135
+
136
+ GitHub issue: [gocardless/hutch#342](https://github.com/gocardless/hutch/pull/342)
137
+
138
+ Contributed by: Paolo Zaccagnini
139
+
140
+ ### CI
141
+
142
+ * Use jruby-9.2.9.0
143
+
144
+ GitHub issue: [gocardless/hutch#336](https://github.com/gocardless/hutch/pull/336)
145
+
146
+ Contributed by: Olle Jonsson
147
+
6
148
  ## 0.27.0 (September 9th, 2019)
7
149
 
8
150
  ### Enhancements
data/Gemfile CHANGED
@@ -20,11 +20,14 @@ group :development, :test do
20
20
  gem "simplecov", "~> 0.12"
21
21
 
22
22
  gem "sentry-raven"
23
+ gem "sentry-ruby"
23
24
  gem "honeybadger"
24
25
  gem "coveralls", "~> 0.8.15", require: false
25
26
  gem "newrelic_rpm"
26
- gem "airbrake", "~> 9.0"
27
+ gem "ddtrace"
28
+ gem "airbrake", "~> 10.0"
27
29
  gem "rollbar"
30
+ gem "bugsnag"
28
31
  end
29
32
 
30
33
  group :development, :darwin do
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
1
  Copyright (c) 2013-2016 GoCardless
2
+ Copyright (c) 2016-2021 Hutch contributors
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person
4
5
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  ![](http://cl.ly/image/3h0q3F3G142K/hutch.png)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/hutch.svg)](http://badge.fury.io/rb/hutch)
4
- [![Build Status](https://travis-ci.org/gocardless/hutch.svg?branch=master)](https://travis-ci.org/gocardless/hutch)
5
4
  [![Code Climate](https://codeclimate.com/github/gocardless/hutch.svg)](https://codeclimate.com/github/gocardless/hutch)
6
5
 
7
6
  Hutch is a Ruby library for enabling asynchronous inter-service communication
@@ -39,7 +38,7 @@ gem install hutch
39
38
 
40
39
  ## Requirements
41
40
 
42
- - Hutch requires Ruby 2.3+ or JRuby 9K.
41
+ - Hutch requires Ruby 2.4+ or JRuby 9K.
43
42
  - Hutch requires RabbitMQ 3.3 or later.
44
43
 
45
44
  ## Overview
@@ -59,8 +58,8 @@ Hutch uses [Bunny](http://rubybunny.info) or [March Hare](http://rubymarchhare.i
59
58
  ### Project Maturity
60
59
 
61
60
  Hutch is a mature project that was originally extracted from production systems
62
- at [GoCardless](https://gocardless.com) in 2013 and is now maintained by a large
63
- group of contributors.
61
+ at [GoCardless](https://gocardless.com) in 2013 and is now maintained by its contributors
62
+ and users.
64
63
 
65
64
  ## Consumers
66
65
 
@@ -109,6 +108,28 @@ class FailedPaymentConsumer
109
108
  end
110
109
  ```
111
110
 
111
+ It is possible to set some custom options to consumer's queue explicitly.
112
+ This example sets the consumer's queue as a
113
+ [quorum queue](https://www.rabbitmq.com/quorum-queues.html)
114
+ and to operate in the [lazy mode](https://www.rabbitmq.com/lazy-queues.html).
115
+ The `initial_group_size`
116
+ [argument](https://www.rabbitmq.com/quorum-queues.html#replication-factor) is
117
+ optional.
118
+
119
+ ```ruby
120
+ class FailedPaymentConsumer
121
+ include Hutch::Consumer
122
+ consume 'gc.ps.payment.failed'
123
+ queue_name 'failed_payments'
124
+ lazy_queue
125
+ quorum_queue initial_group_size: 3
126
+
127
+ def process(message)
128
+ mark_payment_as_failed(message[:id])
129
+ end
130
+ end
131
+ ```
132
+
112
133
  You can also set custom arguments per consumer. This example declares a consumer with
113
134
  a maximum length of 10 messages:
114
135
 
@@ -166,6 +187,12 @@ This will enable NewRelic custom instrumentation:
166
187
  Hutch::Config.set(:tracer, Hutch::Tracers::NewRelic)
167
188
  ```
168
189
 
190
+ And this will enable Datadog custom instrumentation:
191
+
192
+ ```ruby
193
+ Hutch::Config.set(:tracer, Hutch::Tracers::Datadog)
194
+ ```
195
+
169
196
  Batteries included!
170
197
 
171
198
  ## Running Hutch
@@ -219,13 +246,55 @@ directory of a Rails app, or pass the path to a Rails app in with the
219
246
  the `app/consumers/` directory, to allow them to be auto-loaded when Rails
220
247
  boots.
221
248
 
249
+ If you're using the new Zeitwerk autoloader (enabled by default in Rails 6)
250
+ and the consumers are not loaded in development environment you will need to
251
+ trigger the autoloading in an initializer with
252
+
253
+ ```ruby
254
+ ::Zeitwerk::Loader.eager_load_all
255
+ ```
256
+
257
+ or with something more specific like
258
+
259
+ ```ruby
260
+ autoloader = Rails.autoloaders.main
261
+
262
+ Dir.glob(File.join('app/consumers', '*_consumer.rb')).each do |consumer|
263
+ autoloader.preload(consumer)
264
+ end
265
+ ```
266
+
267
+ ### Consumer Groups
268
+
269
+ It is possible to load only a subset of consumers. This is done by defining a consumer
270
+ group under the `consumer_groups` configuration key:
271
+
272
+ ``` yaml
273
+ consumer_groups:
274
+ payments:
275
+ - DepositConsumer
276
+ - CashoutConsumer
277
+ notification:
278
+ - EmailNotificationConsumer
279
+ ```
280
+
281
+ To only load a group of consumers, use the `--only-group` option:
282
+
283
+ ``` shell
284
+ hutch --only-group=payments --config=/path/to/hutch.yaml
285
+ ```
286
+
287
+ ### Loading Consumers Manually (One-by-One)
288
+
222
289
  To require files that define consumers manually, simply pass each file as an
223
290
  option to `--require`. Hutch will automatically detect whether you've provided
224
291
  a Rails app or a standard file, and take the appropriate behaviour:
225
292
 
226
293
  ```bash
227
- $ hutch --require path/to/rails-app # loads a rails app
228
- $ hutch --require path/to/file.rb # loads a ruby file
294
+ # loads a rails app
295
+ hutch --require path/to/rails-app
296
+ # loads a ruby file
297
+ hutch --require path/to/file.rb
229
298
  ```
230
299
 
231
300
  ### Stopping Hutch
@@ -344,6 +413,7 @@ Known configuration parameters are:
344
413
  * `automatically_recover`: Bunny's enable/disable network recovery (default: `true`)
345
414
  * `network_recovery_interval`: Bunny's reconnect interval (default: `1`)
346
415
  * `tracer`: tracer to use to track message processing
416
+ * `namespace`: A namespace string to help group your queues (default: `nil`)
347
417
 
348
418
  ### Environment variables
349
419
 
@@ -402,6 +472,13 @@ Generate with
402
472
  <td><tt>HUTCH_MQ_EXCHANGE</tt></td>
403
473
  <td><p>RabbitMQ Exchange to use for publishing</p></td>
404
474
  </tr>
475
+ <tr>
476
+ <td><tt>mq_exchange_type</tt></td>
477
+ <td>topic</td>
478
+ <td>String</td>
479
+ <td><tt>HUTCH_MQ_EXCHANGE_TYPE</tt></td>
480
+ <td><p>RabbitMQ Exchange type to use for publishing</p></td>
481
+ </tr>
405
482
  <tr>
406
483
  <td><tt>mq_vhost</tt></td>
407
484
  <td>/</td>
@@ -584,5 +661,19 @@ Generate with
584
661
  <td><tt>HUTCH_CONSUMER_TAG_PREFIX</tt></td>
585
662
  <td><p>Prefix displayed on the consumers tags.</p></td>
586
663
  </tr>
664
+ <tr>
665
+ <td><tt>namespace</tt></td>
666
+ <td>nil</td>
667
+ <td>String</td>
668
+ <td><tt>HUTCH_NAMESPACE</tt></td>
669
+ <td><p>A namespace to help group your queues</p></td>
670
+ </tr>
671
+ <tr>
672
+ <td><tt>group</tt></td>
673
+ <td>''</td>
674
+ <td>String</td>
675
+ <td><tt>HUTCH_GROUP</tt></td>
676
+ <td></td>
677
+ </tr>
587
678
  </tbody>
588
679
  </table>
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env sh
2
+
3
+ CTL=${BUNNY_RABBITMQCTL:-"sudo rabbitmqctl"}
4
+ PLUGINS=${BUNNY_RABBITMQ_PLUGINS:-"sudo rabbitmq-plugins"}
5
+
6
+ echo "Will use rabbitmqctl at ${CTL}"
7
+ echo "Will use rabbitmq-plugins at ${PLUGINS}"
8
+
9
+ $PLUGINS enable rabbitmq_management
10
+
11
+ sleep 3
12
+
13
+ # guest:guest has full access to /
14
+ $CTL add_vhost /
15
+ $CTL add_user guest guest
16
+ $CTL set_permissions -p / guest ".*" ".*" ".*"
17
+
18
+ # Reduce retention policy for faster publishing of stats
19
+ $CTL eval 'supervisor2:terminate_child(rabbit_mgmt_sup_sup, rabbit_mgmt_sup), application:set_env(rabbitmq_management, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_sup_sup:start_child().' || true
20
+ $CTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().' || true
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+
3
+ CTL=${MARCH_HARE_RABBITMQCTL:="docker exec rabbitmq rabbitmqctl"}
4
+ PLUGINS=${MARCH_HARE_RABBITMQ_PLUGINS:="docker exec rabbitmq rabbitmq-plugins"}
5
+
6
+ $PLUGINS enable rabbitmq_management
7
+
8
+ sleep 3
9
+
10
+ # guest:guest has full access to /
11
+
12
+ $CTL add_vhost /
13
+ # $CTL add_user guest guest # already exists
14
+ $CTL set_permissions -p / guest ".*" ".*" ".*"
15
+
16
+ # Reduce retention policy for faster publishing of stats
17
+ $CTL eval 'supervisor2:terminate_child(rabbit_mgmt_sup_sup, rabbit_mgmt_sup), application:set_env(rabbitmq_management, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_sup_sup:start_child().'
18
+ $CTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().'
19
+
20
+ sleep 3
@@ -1,17 +1,46 @@
1
1
  #!/bin/sh
2
2
 
3
- sudo apt-get install -y wget
4
- wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add -
3
+ sudo apt-get install curl gnupg debian-keyring debian-archive-keyring apt-transport-https -y
5
4
 
6
- sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
7
- deb https://dl.bintray.com/rabbitmq-erlang/debian xenial erlang
8
- deb https://dl.bintray.com/rabbitmq/debian xenial main
5
+ ## Team RabbitMQ's main signing key
6
+ sudo apt-key adv --keyserver "hkps://keys.openpgp.org" --recv-keys "0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
7
+ ## Launchpad PPA that provides modern Erlang releases
8
+ sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC"
9
+ ## PackageCloud RabbitMQ repository
10
+ sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F6609E60DC62814E"
11
+
12
+ ## Add apt repositories maintained by Team RabbitMQ
13
+ sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
14
+ ## Provides modern Erlang/OTP releases
15
+ ##
16
+ ## "bionic" as distribution name should work for any reasonably recent Ubuntu or Debian release.
17
+ ## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
18
+ deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu bionic main
19
+ deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu bionic main
20
+
21
+ ## Provides RabbitMQ
22
+ ##
23
+ ## "bionic" as distribution name should work for any reasonably recent Ubuntu or Debian release.
24
+ ## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
25
+ deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ bionic main
26
+ deb-src https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ bionic main
9
27
  EOF
10
28
 
29
+ ## Update package indices
11
30
  sudo apt-get update -y
12
- sudo apt-get upgrade -y
13
- sudo apt-get install -y rabbitmq-server
31
+
32
+ ## Install Erlang packages
33
+ sudo apt-get install -y erlang-base \
34
+ erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
35
+ erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
36
+ erlang-runtime-tools erlang-snmp erlang-ssl \
37
+ erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
38
+
39
+ ## Install rabbitmq-server and its dependencies
40
+ sudo apt-get install rabbitmq-server -y --fix-missing
14
41
 
15
42
  sudo service rabbitmq-server start
16
43
 
44
+ sudo rabbitmqctl await_startup --timeout 120
45
+
17
46
  until sudo lsof -i:5672; do echo "Waiting for RabbitMQ to start..."; sleep 1; done
data/hutch.gemspec CHANGED
@@ -6,21 +6,19 @@ Gem::Specification.new do |gem|
6
6
  gem.add_runtime_dependency 'march_hare', '>= 3.0.0'
7
7
  else
8
8
  gem.platform = Gem::Platform::RUBY
9
- gem.add_runtime_dependency 'bunny', '>= 2.13', '< 2.15'
9
+ gem.add_runtime_dependency 'bunny', '>= 2.19', '< 3.0'
10
10
  end
11
11
  gem.add_runtime_dependency 'carrot-top', '~> 0.0.7'
12
- gem.add_runtime_dependency 'multi_json', '~> 1.12'
13
- gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 7'
12
+ gem.add_runtime_dependency 'multi_json', '~> 1.15'
13
+ gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 8'
14
14
 
15
15
  gem.name = 'hutch'
16
- gem.summary = 'Easy inter-service communication using RabbitMQ.'
17
- gem.description = 'Hutch is a Ruby library for enabling asynchronous ' \
18
- 'inter-service communication using RabbitMQ.'
16
+ gem.summary = 'Opinionated asynchronous inter-service communication using RabbitMQ'
17
+ gem.description = 'Hutch is a Ruby library for enabling asynchronous inter-service communication using RabbitMQ'
19
18
  gem.version = Hutch::VERSION.dup
20
19
  gem.required_ruby_version = '>= 2.2'
21
- gem.authors = ['Harry Marr']
22
- gem.email = ['developers@gocardless.com']
23
- gem.homepage = 'https://github.com/gocardless/hutch'
20
+ gem.authors = ['Harry Marr', 'Michael Klishin']
21
+ gem.homepage = 'https://github.com/ruby-amqp/hutch'
24
22
  gem.require_paths = ['lib']
25
23
  gem.license = 'MIT'
26
24
  gem.executables = ['hutch']
@@ -28,6 +28,10 @@ module Hutch
28
28
  def current_timestamp
29
29
  Time.now.to_i
30
30
  end
31
+
32
+ def self.new_exchange(ch, exchange_type, exchange_name, exchange_options)
33
+ Bunny::Exchange.new(ch, exchange_type, exchange_name, exchange_options)
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -32,6 +32,10 @@ module Hutch
32
32
  def current_timestamp
33
33
  Time.now
34
34
  end
35
+
36
+ def self.new_exchange(ch, exchange_type, exchange_name, exchange_options)
37
+ MarchHare::Exchange.new(ch, exchange_name, exchange_options.merge(type: exchange_type))
38
+ end
35
39
  end
36
40
  end
37
41
  end
data/lib/hutch/broker.rb CHANGED
@@ -122,11 +122,12 @@ module Hutch
122
122
 
123
123
  def declare_exchange(ch = channel)
124
124
  exchange_name = @config[:mq_exchange]
125
+ exchange_type = @config[:mq_exchange_type]
125
126
  exchange_options = { durable: true }.merge(@config[:mq_exchange_options])
126
127
  logger.info "using topic exchange '#{exchange_name}'"
127
128
 
128
129
  with_bunny_precondition_handler('exchange') do
129
- ch.topic(exchange_name, exchange_options)
130
+ Adapter.new_exchange(ch, exchange_type, exchange_name, exchange_options)
130
131
  end
131
132
  end
132
133
 
@@ -170,23 +171,26 @@ module Hutch
170
171
  end
171
172
 
172
173
  # Create / get a durable queue and apply namespace if it exists.
173
- def queue(name, arguments = {})
174
+ def queue(name, options = {})
174
175
  with_bunny_precondition_handler('queue') do
175
176
  namespace = @config[:namespace].to_s.downcase.gsub(/[^-_:\.\w]/, "")
176
177
  name = name.prepend(namespace + ":") if namespace.present?
177
- channel.queue(name, durable: true, arguments: arguments)
178
+ channel.queue(name, **options)
178
179
  end
179
180
  end
180
181
 
181
182
  # Return a mapping of queue names to the routing keys they're bound to.
182
183
  def bindings
183
184
  results = Hash.new { |hash, key| hash[key] = [] }
184
- api_client.bindings.each do |binding|
185
- next if binding['destination'] == binding['routing_key']
186
- next unless binding['source'] == @config[:mq_exchange]
187
- next unless binding['vhost'] == @config[:mq_vhost]
185
+
186
+ filtered = api_client.bindings.
187
+ reject { |b| b['destination'] == b['routing_key'] }.
188
+ select { |b| b['source'] == @config[:mq_exchange] && b['vhost'] == @config[:mq_vhost] }
189
+
190
+ filtered.each do |binding|
188
191
  results[binding['destination']] << binding['routing_key']
189
192
  end
193
+
190
194
  results
191
195
  end
192
196
 
@@ -194,8 +198,8 @@ module Hutch
194
198
  def unbind_redundant_bindings(queue, routing_keys)
195
199
  return unless http_api_use_enabled?
196
200
 
197
- bindings.each do |dest, keys|
198
- next unless dest == queue.name
201
+ filtered = bindings.select { |dest, keys| dest == queue.name }
202
+ filtered.each do |dest, keys|
199
203
  keys.reject { |key| routing_keys.include?(key) }.each do |key|
200
204
  logger.debug "removing redundant binding #{queue.name} <--> #{key}"
201
205
  queue.unbind(exchange, routing_key: key)
data/lib/hutch/cli.rb CHANGED
@@ -33,6 +33,23 @@ module Hutch
33
33
  def load_app
34
34
  # Try to load a Rails app in the current directory
35
35
  load_rails_app('.') if Hutch::Config.autoload_rails
36
+ set_up_code_paths!
37
+
38
+ # Because of the order things are required when we run the Hutch binary
39
+ # in hutch/bin, the Sentry Raven gem gets required **after** the error
40
+ # handlers are set up. Due to this, we never got any Sentry notifications
41
+ # when an error occurred in any of the consumers.
42
+ if defined?(Raven)
43
+ Hutch::Config[:error_handlers] << Hutch::ErrorHandlers::SentryRaven.new
44
+ end
45
+ if defined?(Sentry)
46
+ Hutch::Config[:error_handlers] << Hutch::ErrorHandlers::Sentry.new
47
+ end
48
+
49
+ true
50
+ end
51
+
52
+ def set_up_code_paths!
36
53
  Hutch::Config.require_paths.each do |path|
37
54
  # See if each path is a Rails app. If so, try to load it.
38
55
  next if load_rails_app(path)
@@ -51,16 +68,6 @@ module Hutch
51
68
  $LOAD_PATH.pop
52
69
  end
53
70
  end
54
-
55
- # Because of the order things are required when we run the Hutch binary
56
- # in hutch/bin, the Sentry Raven gem gets required **after** the error
57
- # handlers are set up. Due to this, we never got any Sentry notifications
58
- # when an error occurred in any of the consumers.
59
- if defined?(Raven)
60
- Hutch::Config[:error_handlers] << Hutch::ErrorHandlers::Sentry.new
61
- end
62
-
63
- true
64
71
  end
65
72
 
66
73
  def load_rails_app(path)