ears 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 288afca56e18d5cd8add5e50155a37d243daf862079893c2e2aa54728b5ce6dc
4
- data.tar.gz: 7e961cf4efaf97fd72c79a8ff8fd49f2536decc6728a1f8d8ddb176b42de5ff3
3
+ metadata.gz: 2b5be9543cc8c9a75eb078b181786cd85864515064cce8ddb130647e53611700
4
+ data.tar.gz: 48b47f63a7e90c9e149cb008c6a34c35b9d8f4b8133f43c558906fe1fb5398ec
5
5
  SHA512:
6
- metadata.gz: afee5b7d9069bfda962b20776cbb38e0d9b0a416461cb9a41a7eae3c3aa1531d6e29dedebcd7210d1295b17ff9b1bce17fcf0d91bc516d3ff302f067f2f23461
7
- data.tar.gz: f595da01d69259e73d497aef6dee354d202d6bb413fb4e4dba240b1060fc6794352f4f43c16f6bc12f53ef553bbdce025bff5867ecfc2d6c770cdc73169fc09c
6
+ metadata.gz: c0e1a9620e0b167921c80e54df06f52fbfff47ea1023d07f8533f888e81443c5583addf46fa3129c32944b534da1595f7b23bff93e457575e72502b1fb7e98c9
7
+ data.tar.gz: 119f76252574d361b0d339e427203dbd952045afda5d329e6a327d48f5cabdcacb752f04e4ebe4398d86d55ac26314d678f61d925bf79e81d9e11f67b3f4240f
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --require spec_helper
2
+ --format doc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 (2023-10-26)
4
+
5
+ - add new interface to setup consumers including their exchange, queue and binding the queue to the exchange via routing key via `Ears.setup_consumers` and `configure(queue:, exchange:,routing_key:, ...)` for Ears::Consumers subclasses
6
+
3
7
  ## 0.11.2 (2023-10-25)
4
8
 
5
9
  - Add documentation generation via yard
data/Gemfile CHANGED
@@ -2,13 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :development, :test do
6
- gem 'prettier'
5
+ group :test do
6
+ gem 'prettier', require: false
7
7
  gem 'rake'
8
- gem 'redcarpet'
9
8
  gem 'rspec'
10
- gem 'rubocop'
11
- gem 'rubocop-rake'
12
- gem 'rubocop-rspec'
13
- gem 'yard'
9
+ gem 'rubocop', require: false
10
+ gem 'rubocop-rake', require: false
11
+ gem 'rubocop-rspec', require: false
12
+ gem 'simplecov'
13
+ gem 'yard', require: false
14
14
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ears (0.11.2)
4
+ ears (0.12.0)
5
5
  bunny (~> 2.22.0)
6
6
  multi_json
7
7
 
@@ -15,6 +15,7 @@ GEM
15
15
  amq-protocol (~> 2.3, >= 2.3.1)
16
16
  sorted_set (~> 1, >= 1.0.2)
17
17
  diff-lcs (1.5.0)
18
+ docile (1.4.0)
18
19
  haml (6.1.2)
19
20
  temple (>= 0.8.2)
20
21
  thor
@@ -36,7 +37,6 @@ GEM
36
37
  rake (13.0.6)
37
38
  rbs (3.1.3)
38
39
  rbtree (0.4.6)
39
- redcarpet (3.6.0)
40
40
  regexp_parser (2.8.1)
41
41
  rexml (3.2.6)
42
42
  rspec (3.12.0)
@@ -78,6 +78,12 @@ GEM
78
78
  rubocop-factory_bot (~> 2.22)
79
79
  ruby-progressbar (1.13.0)
80
80
  set (1.0.3)
81
+ simplecov (0.22.0)
82
+ docile (~> 1.1)
83
+ simplecov-html (~> 0.11)
84
+ simplecov_json_formatter (~> 0.1)
85
+ simplecov-html (0.12.3)
86
+ simplecov_json_formatter (0.1.4)
81
87
  sorted_set (1.0.3)
82
88
  rbtree
83
89
  set (~> 1.0)
@@ -101,6 +107,7 @@ PLATFORMS
101
107
  arm64-darwin-20
102
108
  arm64-darwin-21
103
109
  arm64-darwin-22
110
+ ruby
104
111
  x86_64-darwin-20
105
112
  x86_64-darwin-21
106
113
  x86_64-darwin-22
@@ -110,11 +117,11 @@ DEPENDENCIES
110
117
  ears!
111
118
  prettier
112
119
  rake
113
- redcarpet
114
120
  rspec
115
121
  rubocop
116
122
  rubocop-rake
117
123
  rubocop-rspec
124
+ simplecov
118
125
  yard
119
126
 
120
127
  BUNDLED WITH
data/Rakefile CHANGED
@@ -2,13 +2,23 @@
2
2
 
3
3
  require 'rake/clean'
4
4
  require 'bundler/gem_tasks'
5
+ require 'rubocop'
6
+ require 'rubocop/rake_task'
5
7
  require 'rspec/core/rake_task'
6
8
  require 'yard'
7
9
 
8
10
  CLEAN << '.yardoc'
9
- CLOBBER << 'doc'
11
+ CLOBBER << 'doc' << 'coverage'
10
12
 
11
13
  RSpec::Core::RakeTask.new(:spec)
12
14
  YARD::Rake::YardocTask.new { |t| t.stats_options = %w[--list-undoc] }
13
15
 
14
- task default: :spec
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.formatters = ['simple']
18
+ task.fail_on_error = true
19
+ end
20
+
21
+ desc 'Run Prettier'
22
+ task(:prettier) { sh 'npm run lint' }
23
+
24
+ task default: %i[spec rubocop prettier]
data/lib/ears/consumer.rb CHANGED
@@ -27,6 +27,28 @@ module Ears
27
27
  middlewares << middleware.new(opts)
28
28
  end
29
29
 
30
+ # Configures the consumer, setting queue, exchange and other options to be used by
31
+ # the add_consumer method.
32
+ #
33
+ # @param [Hash] opts The options to configure the consumer with.
34
+ # @option opts [String] :queue The name of the queue to consume from.
35
+ # @option opts [String] :exchange The name of the exchange the queue should be bound to.
36
+ # @option opts [String] :routing_key The routing key used the queue binding.
37
+ # @option opts [Boolean] :durable_queue (true) Whether the queue should be durable.
38
+ # @option opts [Boolean] :retry_queue (false) Whether a retry queue should be provided.
39
+ # @option opts [Integer] :retry_delay (5000) The delay in milliseconds before retrying a message.
40
+ # @option opts [Boolean] :error_queue (false) Whether an error queue should be provided.
41
+ # @option opts [Boolean] :durable_exchange (true) Whether the exchange should be durable.
42
+ # @option opts [Symbol] :exchange_type (:topic) The type of exchange to use.
43
+ def self.configure(opts = {})
44
+ self.queue = opts.fetch(:queue)
45
+ self.exchange = opts.fetch(:exchange)
46
+ self.routing_key = opts.fetch(:routing_key)
47
+ self.queue_options = queue_options_from(opts: opts)
48
+ self.durable_exchange = opts.fetch(:durable_exchange, true)
49
+ self.exchange_type = opts.fetch(:exchange_type, :topic)
50
+ end
51
+
30
52
  # The method that is called when a message from the queue is received.
31
53
  # Keep in mind that the parameters received can be altered by middlewares!
32
54
  #
@@ -101,5 +123,32 @@ module Ears
101
123
  raise InvalidReturnError, result
102
124
  end
103
125
  end
126
+
127
+ class << self
128
+ attr_reader :queue,
129
+ :exchange,
130
+ :routing_key,
131
+ :queue_options,
132
+ :durable_exchange,
133
+ :exchange_type
134
+
135
+ private
136
+
137
+ def queue_options_from(opts:)
138
+ {
139
+ durable: opts.fetch(:durable_queue, true),
140
+ retry_queue: opts.fetch(:retry_queue, false),
141
+ retry_delay: opts.fetch(:retry_delay, 5000),
142
+ error_queue: opts.fetch(:error_queue, false),
143
+ }
144
+ end
145
+
146
+ attr_writer :queue,
147
+ :exchange,
148
+ :routing_key,
149
+ :queue_options,
150
+ :durable_exchange,
151
+ :exchange_type
152
+ end
104
153
  end
105
154
  end
@@ -15,6 +15,7 @@ module Ears
15
15
 
16
16
  def call(delivery_info, metadata, payload, app)
17
17
  return handle_exceeded(payload) if retries_exceeded?(metadata)
18
+
18
19
  app.call(delivery_info, metadata, payload)
19
20
  end
20
21
 
data/lib/ears/setup.rb CHANGED
@@ -58,8 +58,28 @@ module Ears
58
58
  end
59
59
  end
60
60
 
61
+ # Sets up consumers, including bindings to exchanges and queues.
62
+ #
63
+ # @param [Array<Class<Ears::Consumer>>] consumer_classes An array of subclasses of {Ears::Consumer} that call {Ears::Consumer#configure} in their class definition.
64
+ def setup_consumers(*consumer_classes)
65
+ consumer_classes.each { |consumer_class| setup_consumer(consumer_class) }
66
+ end
67
+
61
68
  private
62
69
 
70
+ def setup_consumer(consumer_class)
71
+ exchange =
72
+ exchange(
73
+ consumer_class.exchange,
74
+ consumer_class.exchange_type,
75
+ durable: consumer_class.durable_exchange,
76
+ )
77
+ configured_queue =
78
+ queue(consumer_class.queue, consumer_class.queue_options)
79
+ configured_queue.bind(exchange, routing_key: consumer_class.routing_key)
80
+ consumer(configured_queue, consumer_class)
81
+ end
82
+
63
83
  def queue_options(bunny_opts, retry_arguments)
64
84
  return bunny_opts unless retry_arguments
65
85
 
data/lib/ears/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ears
2
- VERSION = '0.11.2'
2
+ VERSION = '0.12.0'
3
3
  end
data/lib/ears.rb CHANGED
@@ -8,7 +8,6 @@ require 'ears/version'
8
8
  module Ears
9
9
  class << self
10
10
  # The global configuration for Ears.
11
- #
12
11
  # @return [Ears::Configuration]
13
12
  def configuration
14
13
  @configuration ||= Ears::Configuration.new
@@ -48,6 +47,11 @@ module Ears
48
47
  Ears::Setup.new.instance_eval(&block)
49
48
  end
50
49
 
50
+ # Quick setup your consumers (including exchanges and queues).
51
+ def setup_consumers(*consumer_classes)
52
+ Ears::Setup.new.setup_consumers(*consumer_classes)
53
+ end
54
+
51
55
  # Blocks the calling thread until +SIGTERM+ or +SIGINT+ is received.
52
56
  # Used to keep the process alive while processing messages.
53
57
  def run!
@@ -74,9 +78,7 @@ module Ears
74
78
 
75
79
  # Used internally for testing.
76
80
  def reset!
77
- @connection = nil
78
- @configuration = nil
79
- Thread.current[:ears_channel] = nil
81
+ @configuration = @connection = Thread.current[:ears_channel] = nil
80
82
  end
81
83
 
82
84
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ears
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - InVision AG
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-25 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny