basquiat 1.2.0 → 1.3.0.pre.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +50 -0
  3. data/.gitignore +1 -0
  4. data/.metrics +1 -5
  5. data/.reek +0 -1
  6. data/.rubocop.yml +2 -1
  7. data/.ruby-version +1 -1
  8. data/Guardfile +4 -0
  9. data/README.md +77 -61
  10. data/basquiat.gemspec +5 -4
  11. data/basquiat_docker.sh +1 -1
  12. data/docker/Dockerfile +8 -3
  13. data/docker-compose.yml +3 -3
  14. data/lib/basquiat/adapters/base_adapter.rb +42 -7
  15. data/lib/basquiat/adapters/base_message.rb +14 -9
  16. data/lib/basquiat/adapters/rabbitmq/configuration.rb +31 -16
  17. data/lib/basquiat/adapters/rabbitmq/connection.rb +33 -56
  18. data/lib/basquiat/adapters/rabbitmq/events.rb +1 -1
  19. data/lib/basquiat/adapters/rabbitmq/message.rb +10 -9
  20. data/lib/basquiat/adapters/rabbitmq/requeue_strategies/auto_acknowledge.rb +15 -0
  21. data/lib/basquiat/adapters/rabbitmq/requeue_strategies/base_strategy.rb +8 -4
  22. data/lib/basquiat/adapters/rabbitmq/requeue_strategies/basic_acknowledge.rb +1 -1
  23. data/lib/basquiat/adapters/rabbitmq/requeue_strategies/dead_lettering.rb +16 -15
  24. data/lib/basquiat/adapters/rabbitmq/requeue_strategies/delayed_delivery.rb +80 -16
  25. data/lib/basquiat/adapters/rabbitmq/requeue_strategies.rb +7 -0
  26. data/lib/basquiat/adapters/rabbitmq/session.rb +12 -14
  27. data/lib/basquiat/adapters/rabbitmq_adapter.rb +35 -16
  28. data/lib/basquiat/adapters/test_adapter.rb +2 -5
  29. data/lib/basquiat/errors/strategy_not_registered.rb +1 -9
  30. data/lib/basquiat/interfaces/base.rb +28 -7
  31. data/lib/basquiat/support/configuration.rb +33 -4
  32. data/lib/basquiat/support/hash_refinements.rb +9 -0
  33. data/lib/basquiat/support/json.rb +9 -0
  34. data/lib/basquiat/version.rb +1 -1
  35. data/lib/basquiat.rb +6 -1
  36. data/spec/lib/adapters/base_adapter_spec.rb +1 -1
  37. data/spec/lib/adapters/base_message_spec.rb +0 -6
  38. data/spec/lib/adapters/rabbitmq/configuration_spec.rb +2 -2
  39. data/spec/lib/adapters/rabbitmq/connection_spec.rb +8 -13
  40. data/spec/lib/adapters/rabbitmq/events_spec.rb +8 -1
  41. data/spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb +24 -0
  42. data/spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb +4 -4
  43. data/spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb +23 -28
  44. data/spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb +105 -0
  45. data/spec/lib/adapters/rabbitmq_adapter_spec.rb +21 -17
  46. data/spec/lib/basquiat_spec.rb +0 -6
  47. data/spec/lib/interfaces/base_spec.rb +11 -19
  48. data/spec/lib/support/configuration_spec.rb +0 -8
  49. data/spec/lib/support/hash_refinements_spec.rb +2 -2
  50. data/spec/spec_helper.rb +2 -6
  51. data/spec/support/rabbitmq_queue_matchers.rb +9 -3
  52. metadata +21 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2ece36298347faf2fb2607326545c2d35f78d08
4
- data.tar.gz: e461978745bacda7cbf9e276327a91acdf814701
3
+ metadata.gz: 3e62fb7f48142250951c4e6c7d471fe3bbff47f4
4
+ data.tar.gz: 044bfbfdeeeec35150d679eae3425db38ab3699e
5
5
  SHA512:
6
- metadata.gz: 88cfcff653f37e3f25519df53f4ca434af685cd6bc3146f4519e5b00c6efaea54c55fc2a051cbc131b8c92c734c77cc0d784bc83a2148aaccee463eb2857da15
7
- data.tar.gz: 7c500da60290323968215415e264b2bbc698d5c1ac703212bf4bb2745b81ea704d78dae3cf371cab415cbac704032a0c8c23920417dfe1614bba41859bec901c
6
+ metadata.gz: fd73d055c57de8b20fd623876d270d18ddd8f0f8fd29443e76610dbd00c30dc5011010e49b1c3fa0f21a457a43a4a74f49ecdbe35db04e0b3bf9c759b743e545
7
+ data.tar.gz: e8e3af0254e4693d759defe4724f02bb4a6408c98df126303b214f491023fce078c57308967dbf37c72ded09d4eacb569b6d08cc3fc6db068e05cf55f04988dc
data/.codeclimate.yml ADDED
@@ -0,0 +1,50 @@
1
+ # This is a sample .codeclimate.yml configured for Engine analysis on Code
2
+ # Climate Platform. For an overview of the Code Climate Platform, see here:
3
+ # http://docs.codeclimate.com/article/300-the-codeclimate-platform
4
+
5
+ # Under the engines key, you can configure which engines will analyze your repo.
6
+ # Each key is an engine name. For each value, you need to specify enabled: true
7
+ # to enable the engine as well as any other engines-specific configuration.
8
+
9
+ # For more details, see here:
10
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
11
+
12
+ # For a list of all available engines, see here:
13
+ # http://docs.codeclimate.com/article/296-engines-available-engines
14
+
15
+ engines:
16
+ # to turn on an engine, add it here and set enabled to `true`
17
+ # to turn off an engine, set enabled to `false` or remove it
18
+ rubocop:
19
+ enabled: true
20
+ golint:
21
+ enabled: false
22
+ gofmt:
23
+ enabled: false
24
+ eslint:
25
+ enabled: false
26
+ csslint:
27
+ enabled: false
28
+
29
+ # Engines can analyze files and report issues on them, but you can separately
30
+ # decide which files will receive ratings based on those issues. This is
31
+ # specified by path patterns under the ratings key.
32
+
33
+ # For more details see here:
34
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
35
+
36
+ # Note: If the ratings key is not specified, this will result in a 0.0 GPA on your dashboard.
37
+
38
+ # ratings:
39
+ # paths:
40
+ # - app/**
41
+ # - lib/**
42
+ # - "**.rb"
43
+ # - "**.go"
44
+
45
+ # You can globally exclude files from being analyzed by any engine using the
46
+ # exclude_paths key.
47
+
48
+ #exclude_paths:
49
+ #- spec/**/*
50
+ #- vendor/**/*
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ bin
20
20
  docker/Gemfile
21
21
  log
22
22
  .tags*
23
+ doc
data/.metrics CHANGED
@@ -1,10 +1,6 @@
1
1
  MetricFu::Configuration.run do |config|
2
2
  config.configure_metric(:cane) do |cane|
3
- cane.line_length = 110
3
+ cane.line_length = 120
4
4
  cane.no_doc = 'y'
5
5
  end
6
-
7
- config.configure_metric(:reek) do |reek|
8
- reek.config_file_pattern = '.reek'
9
- end
10
6
  end
data/.reek CHANGED
@@ -1,3 +1,2 @@
1
- ---
2
1
  IrresponsibleModule:
3
2
  enabled: false
data/.rubocop.yml CHANGED
@@ -3,8 +3,9 @@ AllCops:
3
3
  - 'bin/*'
4
4
  - 'docker/*'
5
5
  - 'Guardfile'
6
+ - 'basquiat.gemspec'
6
7
  Metrics/LineLength:
7
- Max: 109
8
+ Max: 119
8
9
 
9
10
  Style/AlignHash:
10
11
  EnforcedHashRocketStyle: table
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.2
1
+ ruby-2.2.3
data/Guardfile CHANGED
@@ -16,3 +16,7 @@ guard :rubocop, { cmd: 'rubocop', cli: '-fs -c./.rubocop.yml' } do
16
16
  #watch(%r{.+\.rb$})
17
17
  #watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
18
18
  end
19
+
20
+ guard 'yard', { cli: '-r' } do
21
+ watch(%r{lib/.+\.rb})
22
+ end
data/README.md CHANGED
@@ -1,97 +1,113 @@
1
1
  # Basquiat
2
2
 
3
- **Basquiat** is intended to hide (almost) all the complexity of working with some kind of message queue from the application internals.
3
+ [![Code Climate](https://codeclimate.com/github/VAGAScom/basquiat/badges/gpa.svg)](https://codeclimate.com/github/VAGAScom/basquiat)
4
4
 
5
- All the exchanges, connections, queues and sessions declarations are swept under rug. The main aim is to provide a simple yet flexible interface to work with message queues.
5
+ **Basquiat** is library aimed to hide (almost) all the complexity when working with some kind of message queue from the application internals.
6
+
7
+ All the exchanges, connections, queues and sessions declarations are swept under rug. The aim is to provide a simple yet flexible interface to work with message queues.
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
- gem 'basquiat'
13
+ ```ruby
14
+ gem 'basquiat'
15
+ ```
12
16
 
13
17
  And then execute:
14
18
 
15
- $ bundle
19
+ ```bash
20
+ $ bundle
21
+ ```
16
22
 
17
23
  Or install it yourself as:
18
24
 
19
- $ gem install basquiat
25
+ ```bash
26
+ $ gem install basquiat
27
+ ```
20
28
 
21
- You will also need the right gem for your MQ system. Bundled in this gem you will find 2 adapters for RabbitMQ and ActiveMQ which depends on the gems _bunny_ and _ruby-stomp_ respectively.
29
+ You will also need the right gem for your Message Queue (MQ) system. Bundled in this gem you will find 1 adapter, for RabbitMQ, which depends on the gem _bunny_.
22
30
 
23
31
  ## Basic Usage
24
32
 
25
- First of all require the gem, the dependecy for the adapter and the adapter itself
26
-
27
- require 'basquiat'
28
- require 'bunny'
29
- require 'basquiat/adapters/rabbitmq_adapter'
33
+ First of all require the gem, the dependency for the adapter and the adapter itself
30
34
 
31
- Then you can extend the class that you will use for communicating with the MQ
35
+ ```ruby
36
+ require 'basquiat'
37
+ require 'bunny'
38
+ require 'basquiat/adapters/rabbitmq_adapter'
39
+ ```
32
40
 
33
- class TownCrier
34
- extend Basquiat::Base
35
- end
41
+ Then you can extend the class that you will use for communicating with the MQ, setting the adapter:
36
42
 
37
- From here you can publish events to the queue
38
-
39
- TownCrier.publish('some.nifty.event', {a: 'hash', of: 'values'})
43
+ ```ruby
44
+ class TownCrier
45
+ extend Basquiat::Base
46
+ self.event_adapter Basquiat::Adapters::RabbitMq
47
+ end
48
+ ```
49
+ From there you can publish events to the queue
40
50
 
51
+ ```ruby
52
+ TownCrier.publish('some.nifty.event', {a: 'hash', of: 'values'})
53
+ ```
41
54
  And you can subscribe to one or more events using a proc that will get called when the message is received:
42
55
 
43
- class TownCrier
44
- extend Basquiat::Base
56
+ ```ruby
57
+ class TownCrier
58
+ extend Basquiat::Base
45
59
 
46
- subscribe_to 'some.nifty.event', ->(msg) { msg.fetch(:of, '').upcase }
47
- end
60
+ subscribe_to 'some.nifty.event', ->(msg) { msg.fetch(:of, '').upcase }
61
+ end
62
+ ```
48
63
 
49
64
  ## Configuration
50
65
 
51
66
  You can setup Basquiat using the configure method. This method will yield a Configuration object:
52
67
 
53
- Basquiat.configure do |config|
54
- config.exchange_name = 'my_exchange'
55
- end
56
-
68
+ ```ruby
69
+ Basquiat.configure do |config|
70
+ config.exchange_name = 'my_exchange'
71
+ end
72
+ ```
57
73
  The available options are:
58
74
 
59
75
  - config_file= Receive a path to an YAML file (example here)
60
76
  - queue_name= The default queue name
61
77
  - exchange_name= The default exchange name
62
78
  - environment= Forces the environment to something other than the value of BASQUIAT_ENV
63
- - logger= The logger to be used. Defaults to a null logger.
64
-
65
- The configuration can be reset using the Basquiat.reset method.
66
-
67
- Yaml File configuration example:
68
-
69
- test: #environment
70
- exchange_name: 'my.test_exchange' #required
71
- queue_name: 'my.nice_queue' #required
72
- default_adapter: Basquiat::Adapters::Test #it will overwrite the adapter on all classes that extend Basquiat::Base
73
- adapter_options: #Adapter specific options
74
- :servers:
75
- -
76
- :host: 'localhost'
77
- :port: '5672'
78
- development: #full example of the RabbitMq options
79
- exchange_name: 'my.exchange'
80
- queue_name: 'my.queue'
81
- default_adapter: Basquiat::Adapters::RabbitMq
82
- adapter_options:
83
- servers:
84
- -
85
- :host: 'localhost'
86
- :port: '5672'
87
- failover:
88
- :default_timeout: 5
89
- :max_retries: 5
90
- publisher:
91
- confirm: true
92
- persistent: true
93
- auth:
94
- user: 'guest'
95
- password: 'guest'
96
- requeue:
97
- enabled: false
79
+ - logger= The logger to be used. Defaults to a null object logger.
80
+
81
+ The configuration can be reset using the `Basquiat.reset` method.
82
+
83
+ YAML File configuration example:
84
+
85
+ ```yaml
86
+ test: #environment
87
+ default_adapter: Basquiat::Adapters::Test #it will overwrite the adapter on all classes that extend Basquiat::Base
88
+ adapter_options: #Adapter specific options
89
+ servers:
90
+ -
91
+ host: 'localhost'
92
+ port: '98765'
93
+ development: #full example of the RabbitMq options
94
+ exchange_name: 'basquiat.exchange'
95
+ queue_name: 'basquiat.queue'
96
+ default_adapter: Basquiat::Adapters::RabbitMq
97
+ adapter_options:
98
+ hosts:
99
+ - 'localhost'
100
+ port: 5672
101
+ publisher:
102
+ confirm: true
103
+ persistent: true
104
+ auth:
105
+ user: 'guest'
106
+ password: 'guest'
107
+ requeue:
108
+ enabled: true
109
+ delayed_delivery:
110
+ retries: 10
111
+ queue_name_preffix: wait.for_it
112
+ exchange_name: legendary
113
+ ```
data/basquiat.gemspec CHANGED
@@ -27,14 +27,15 @@ EOD
27
27
  spec.add_development_dependency 'guard-bundler'
28
28
  spec.add_development_dependency 'guard-rspec'
29
29
  spec.add_development_dependency 'guard-rubocop'
30
+ spec.add_development_dependency 'guard-yard'
30
31
  spec.add_development_dependency 'bunny'
31
- spec.add_development_dependency 'stomp'
32
32
  spec.add_development_dependency 'yajl-ruby'
33
33
  spec.add_development_dependency 'simplecov'
34
- spec.add_development_dependency 'metric_fu'
35
34
  spec.add_development_dependency 'rubocop'
36
- spec.add_development_dependency 'byebug'
37
- spec.add_development_dependency 'pry-byebug'
35
+ spec.add_development_dependency 'metric_fu'
36
+ spec.add_development_dependency 'codeclimate-test-reporter'
37
+ spec.add_development_dependency 'yard'
38
+
38
39
 
39
40
  spec.add_dependency 'multi_json'
40
41
  spec.add_dependency 'naught'
data/basquiat_docker.sh CHANGED
@@ -30,6 +30,6 @@ function stop_and_remove_containers {
30
30
 
31
31
  generate_gemfile
32
32
  docker-compose start rabbitmq
33
- docker-compose run basquiat
33
+ docker-compose run --service-ports basquiat
34
34
 
35
35
  trap stop_and_remove_containers EXIT SIGINT SIGTERM SIGKILL
data/docker/Dockerfile CHANGED
@@ -1,10 +1,15 @@
1
- FROM mereghost/ruby:latest
2
-
3
- RUN useradd -m -g users dev
1
+ FROM mereghost/ruby:2.2.2
4
2
 
3
+ RUN useradd -mg users -G network dev
5
4
  VOLUME /basquiat
6
5
  WORKDIR /basquiat
7
6
 
8
7
  ENV REFRESHED_AT 2015-03-29
8
+ USER dev
9
9
  COPY Gemfile /tmp/Gemfile
10
+
11
+ #This is needed by bundler =/
12
+ ENV GEM_HOME=/home/dev/.gem
10
13
  RUN cd /tmp && bundle install
14
+
15
+ EXPOSE 8808
data/docker-compose.yml CHANGED
@@ -5,11 +5,11 @@ basquiat:
5
5
  - ./:/basquiat
6
6
  links:
7
7
  - rabbitmq
8
- tty: true
9
- stdin_open: true
8
+ ports:
9
+ - "8808"
10
10
 
11
11
  rabbitmq:
12
- image: mereghost/rabbitmq:latest
12
+ image: rabbitmq:3-management
13
13
  ports:
14
14
  - "15672"
15
15
  - "5672"
@@ -8,54 +8,89 @@ module Basquiat
8
8
  using Basquiat::HashRefinements
9
9
 
10
10
  class << self
11
+ # A hash representing the registered requeue/acknowledge strategies
12
+ # @return [Hash] the registered RequeueStrategies
11
13
  def strategies
12
14
  @strategies ||= {}
13
15
  end
14
16
 
17
+ # Used to register a requeue/acknowledge strategy
18
+ # @param config_name [#to_sym] the named used on the config file for the Requeue Strategy
19
+ # @param klass [Class] the class name.
15
20
  def register_strategy(config_name, klass)
16
- strategies.merge!(config_name.to_sym => klass)
21
+ strategies[config_name.to_sym] = klass
22
+ end
23
+
24
+ # Return the Strategy Class registered on key
25
+ # @param key [#to_sym] configured key for the wanted strategy
26
+ # @return [Class] return the strategy class
27
+ # @raise [Errors::StrategyNotRegistered] if it fails to find the key
28
+ def strategy(key)
29
+ strategies.fetch(key)
30
+ rescue KeyError
31
+ raise Basquiat::Errors::StrategyNotRegistered
17
32
  end
18
33
  end
19
34
 
20
- def initialize
35
+ # @param procs: [Object]
36
+ # It's a hash by default, but usually will be superseded by the adapter implementation
37
+ def initialize(procs: {})
21
38
  @options = base_options
22
- @procs = {}
39
+ @procs = procs
23
40
  @retries = 0
24
41
  end
25
42
 
43
+ # Utility method to access the class instance variable
26
44
  def strategies
27
45
  self.class.strategies
28
46
  end
29
47
 
30
- # Used to set the options for the adapter. It is merged in
31
- # to the default_options hash.
48
+ # Allows the #base_options to be superseded on the local level
49
+ #
50
+ # You could have configured an exchange_name (on a config file) to +'awesome.sauce'+,
51
+ # but on this object you'd want to publish your messages to the +'killer.mailman'+ exchange.
52
+ # @example
53
+ # class Mailmail
54
+ # extend Basquiat::Base
55
+ # adapter_options {exchange: {name: 'killer.mailman'}}
56
+ # end
57
+ #
32
58
  # @param [Hash] opts an adapter dependant hash of options
33
59
  def adapter_options(opts)
34
60
  @options.deep_merge(opts)
35
61
  end
36
62
 
37
- # Default options for the adapter
38
- # @return [Hash]
63
+ # The default adapter options, merged with the {Basquiat::Configuration#adapter_options}. Used internally.
64
+ # @todo rename this method
65
+ # @return [Hash] the full options hash
39
66
  def base_options
40
67
  default_options.merge(Basquiat.configuration.adapter_options)
41
68
  end
42
69
 
70
+ # The adapter default options
71
+ # @return [Hash]
43
72
  def default_options
44
73
  {}
45
74
  end
46
75
 
76
+ # @!group Adapter specific implementations
77
+ # @abstract Publish an event to the event stream
47
78
  def publish
48
79
  fail Basquiat::Errors::SubclassResponsibility
49
80
  end
50
81
 
82
+ # @abstract subscribe_to the event stream
51
83
  def subscribe_to
52
84
  fail Basquiat::Errors::SubclassResponsibility
53
85
  end
54
86
 
87
+ # @abstract Disconnect from the message queue
55
88
  def disconnect
56
89
  fail Basquiat::Errors::SubclassResponsibility
57
90
  end
58
91
 
92
+ # @!endgroup
93
+
59
94
  private
60
95
 
61
96
  attr_reader :procs, :options
@@ -1,29 +1,34 @@
1
1
  module Basquiat
2
2
  module Adapters
3
+ # The simplest Message class. It's encouraged to tailor it to your adapter needs (hence BaseMessage).
3
4
  class BaseMessage < SimpleDelegator
4
5
  attr_reader :action
5
6
 
7
+ # @param message [Object] It's assumed that message is some kind of JSON
8
+ # @note All unknown messages will be delegated to the resulting Hash
6
9
  def initialize(message)
7
10
  @message = Basquiat::Json.decode(message)
8
11
  super(@message)
9
12
  @action = :ack
10
13
  end
11
14
 
12
- def ack?
13
- fail Basquiat::Errors::SubclassResponsibility
15
+ # @!group Action Setters
16
+ # Sets the action to be taken after processing to be an ack.
17
+ # Here just in case as the default is to acknowledge the message.
18
+ def ack
19
+ @action = :ack
14
20
  end
15
21
 
16
- def unack
17
- fail Basquiat::Errors::SubclassResponsibility
22
+ # Sets the action to be taken after processing to be an nack / reject
23
+ def nack
24
+ @action = :nack
18
25
  end
19
26
 
27
+ # Sets the action to be taken after processing to be a requeue
20
28
  def requeue
21
- fail Basquiat::Errors::SubclassResponsibility
22
- end
23
-
24
- def delay_redelivery
25
- fail Basquiat::Errors::SubclassResponsibility
29
+ @action = :requeue
26
30
  end
31
+ # @!endgroup
27
32
  end
28
33
  end
29
34
  end
@@ -1,20 +1,26 @@
1
1
  module Basquiat
2
2
  module Adapters
3
3
  class RabbitMq
4
+ # Responsible for dealing with the overall configuration of the RabbitMQ adapter
4
5
  class Configuration
5
6
  using Basquiat::HashRefinements
6
7
 
7
8
  def initialize
8
- @options = { failover: { default_timeout: 5, max_retries: 5 },
9
- servers: [{ host: 'localhost', port: 5672 }],
9
+ @options = { connection:
10
+ { hosts: ['localhost'],
11
+ port: 5672,
12
+ auth: { user: 'guest', password: 'guest' }
13
+ },
10
14
  queue: {
11
- name: Basquiat.configuration.queue_name,
12
- options: { durable: true } },
15
+ name: Basquiat.configuration.queue_name,
16
+ durable: true,
17
+ options: {} },
13
18
  exchange: {
14
- name: Basquiat.configuration.exchange_name,
15
- options: { durable: true } },
19
+ name: Basquiat.configuration.exchange_name,
20
+ durable: true,
21
+ options: {} },
16
22
  publisher: { confirm: true, persistent: false },
17
- auth: { user: 'guest', password: 'guest' },
23
+ consumer: { prefetch: 1000, manual_ack: true },
18
24
  requeue: { enabled: false } }
19
25
  end
20
26
 
@@ -22,29 +28,38 @@ module Basquiat
22
28
  @options
23
29
  end
24
30
 
25
- def merge_user_options(user_opts)
31
+ # Merges the user supplied options with the base ones
32
+ # @param user_opts [Hash{Symbol=>Object}]
33
+ # @option user_opts [Hash{Symbol=>Object}] :connection see {Connection#initialize}
34
+ # @option user_opts [Hash{Symbol=>Object}] :queue
35
+ # @option user_opts [Hash{Symbol=>Object}] :exchange
36
+ # @option user_opts [Hash{Symbol=>Object}] :publisher
37
+ # @option user_opts [Hash{Symbol=>Object}] :requeue
38
+ # @return [Hash] the configuration option hash
39
+ def merge_user_options(**user_opts)
26
40
  @options.merge!(user_opts)
27
41
  end
28
42
 
43
+ # @return [Hash] the connection options
29
44
  def connection_options
30
- { servers: @options[:servers],
31
- failover: @options[:failover],
32
- auth: @options[:auth] }
45
+ @options[:connection]
33
46
  end
34
47
 
48
+ # @return [Hash] the session options
35
49
  def session_options
36
50
  { exchange: @options[:exchange],
37
51
  publisher: @options[:publisher],
52
+ consumer: @options[:consumer],
38
53
  queue: @options[:queue] }.deep_merge(strategy.session_options)
39
54
  end
40
55
 
56
+ # @return [BaseStrategy] the requeue strategy or {BasicAcknowledge} if none is configured
41
57
  def strategy
42
- return BasicAcknowledge unless @options[:requeue][:enabled]
43
- @strategy ||= RabbitMq.strategies.fetch(@options[:requeue][:strategy].to_sym)
44
- @strategy.setup(@options[:requeue][:options] || {})
58
+ requeue = @options[:requeue]
59
+ return AutoAcknowledge unless requeue[:enabled]
60
+ @strategy ||= RabbitMq.strategy(requeue[:strategy].to_sym)
61
+ @strategy.setup(requeue[:options] || {})
45
62
  @strategy
46
- rescue KeyError
47
- fail Basquiat::Errors::StrategyNotRegistered.new(@options[:requeue][:strategy])
48
63
  end
49
64
  end
50
65
  end