basquiat 1.3.0.pre.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Guardfile +8 -7
- data/README.md +4 -2
- data/Rakefile +2 -0
- data/basquiat.gemspec +5 -5
- data/lib/basquiat/adapters/base_adapter.rb +10 -9
- data/lib/basquiat/adapters/base_message.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/configuration.rb +14 -13
- data/lib/basquiat/adapters/rabbitmq/connection.rb +7 -4
- data/lib/basquiat/adapters/rabbitmq/events.rb +3 -4
- data/lib/basquiat/adapters/rabbitmq/message.rb +6 -1
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/auto_acknowledge.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/base_strategy.rb +2 -1
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/basic_acknowledge.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/dead_lettering.rb +2 -3
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/delayed_delivery.rb +24 -25
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/session.rb +6 -0
- data/lib/basquiat/adapters/rabbitmq_adapter.rb +2 -1
- data/lib/basquiat/adapters/test_adapter.rb +1 -0
- data/lib/basquiat/adapters.rb +1 -0
- data/lib/basquiat/errors/strategy_not_registered.rb +1 -0
- data/lib/basquiat/errors/subclass_responsibility.rb +1 -3
- data/lib/basquiat/errors.rb +1 -0
- data/lib/basquiat/interfaces/base.rb +7 -1
- data/lib/basquiat/rails/railtie.rb +1 -0
- data/lib/basquiat/support/configuration.rb +3 -2
- data/lib/basquiat/support/hash_refinements.rb +1 -0
- data/lib/basquiat/support/json.rb +1 -0
- data/lib/basquiat/support.rb +1 -0
- data/lib/basquiat/version.rb +2 -1
- data/lib/basquiat.rb +2 -1
- data/spec/lib/adapters/base_adapter_spec.rb +1 -0
- data/spec/lib/adapters/base_message_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/configuration_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/connection_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/events_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/message_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb +1 -0
- data/spec/lib/adapters/rabbitmq/requeue_strategies/base_strategy_spec.rb +11 -0
- data/spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb +12 -5
- data/spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb +15 -12
- data/spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb +7 -8
- data/spec/lib/adapters/rabbitmq_adapter_spec.rb +4 -3
- data/spec/lib/adapters/test_adapter_spec.rb +1 -0
- data/spec/lib/basquiat_spec.rb +1 -0
- data/spec/lib/interfaces/base_spec.rb +1 -0
- data/spec/lib/support/configuration_spec.rb +1 -0
- data/spec/lib/support/hash_refinements_spec.rb +1 -0
- data/spec/lib/support/json_spec.rb +1 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/rabbitmq_queue_matchers.rb +1 -0
- data/spec/support/shared_examples/basquiat_adapter_shared_examples.rb +2 -1
- metadata +7 -17
- data/.codeclimate.yml +0 -50
- data/.gitignore +0 -23
- data/.metrics +0 -6
- data/.reek +0 -2
- data/.rspec +0 -5
- data/.rubocop.yml +0 -14
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/basquiat_docker.sh +0 -35
- data/docker/Dockerfile +0 -15
- data/docker/guard_start.sh +0 -3
- data/docker-compose.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2fd0255f1924260c2253d4b0ffe3bd5434184cc
|
4
|
+
data.tar.gz: 1db61ca0abc893884328a3de429ad0a9a7007578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4755306fa1d78f6aab9e05c4504fa333c508aecafaab2784afcf64d847ae1c56d1e7f4f6c81b94e3cbfa8ca145ddbd5098dcf2cc38a466feba1e64c4dc4ce15
|
7
|
+
data.tar.gz: d41074fe39816491a4eba28241e928b60186d38154a04d2c0a5efbec747b16caa90957c12e5baca3d85977f373c55efcbfa03cbcb4515c52c7b257fa6ac29d74
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
guard :bundler do
|
2
3
|
watch('Gemfile')
|
3
4
|
watch('basquiat.gemspec')
|
4
5
|
end
|
5
6
|
|
6
|
-
guard :rspec,
|
7
|
-
|
7
|
+
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true,
|
8
|
+
keep: true, all_after_pass: true, run_all: { cmd: 'rspec -f progress' } do
|
8
9
|
watch(%r{^spec/.+_spec.rb$})
|
9
10
|
watch(%r{^spec/lib/.+_spec.rb$})
|
10
11
|
watch(%r{^lib/basquiat/(.+)\.rb$}) { |matchdata| "spec/lib/#{matchdata[1]}_spec.rb" }
|
@@ -12,11 +13,11 @@ guard :rspec, { cmd: 'bundle exec rspec', all_on_start: true,
|
|
12
13
|
watch(%r{spec/support/.+\.rb}) { 'spec' }
|
13
14
|
end
|
14
15
|
|
15
|
-
guard :rubocop,
|
16
|
-
#watch(%r{.+\.rb$})
|
17
|
-
#watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
16
|
+
guard :rubocop, cmd: 'rubocop', cli: '-fs -c./.rubocop.yml' do
|
17
|
+
# watch(%r{.+\.rb$})
|
18
|
+
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
18
19
|
end
|
19
20
|
|
20
|
-
guard 'yard',
|
21
|
-
watch
|
21
|
+
guard 'yard', cli: '-r' do
|
22
|
+
watch %r{lib/.+\.rb}
|
22
23
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Basquiat
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Issue Count](https://codeclimate.com/github/VAGAScom/basquiat/badges/issue_count.svg)](https://codeclimate.com/github/VAGAScom/basquiat)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/VAGAScom/basquiat/badges/coverage.svg)](https://codeclimate.com/github/VAGAScom/basquiat/coverage)
|
4
5
|
|
5
6
|
**Basquiat** is library aimed to hide (almost) all the complexity when working with some kind of message queue from the application internals.
|
6
7
|
|
@@ -106,7 +107,8 @@ development: #full example of the RabbitMq option
|
|
106
107
|
password: 'guest'
|
107
108
|
requeue:
|
108
109
|
enabled: true
|
109
|
-
delayed_delivery
|
110
|
+
strategy: delayed_delivery
|
111
|
+
options:
|
110
112
|
retries: 10
|
111
113
|
queue_name_preffix: wait.for_it
|
112
114
|
exchange_name: legendary
|
data/Rakefile
CHANGED
data/basquiat.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'basquiat/version'
|
@@ -15,9 +16,9 @@ EOD
|
|
15
16
|
spec.homepage = 'http://github.com/VAGAScom/basquiat'
|
16
17
|
spec.license = 'MIT'
|
17
18
|
|
18
|
-
spec.files = `git ls-files`.split($RS)
|
19
|
-
spec.executables = spec.files.grep(/^bin
|
20
|
-
spec.test_files = spec.files.grep(
|
19
|
+
spec.files = `git ls-files`.split($RS).reject { |f| f =~ /^\.|docker/ }
|
20
|
+
spec.executables = spec.files.grep(%r{/^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
22
|
spec.require_paths = %w(lib)
|
22
23
|
|
23
24
|
spec.add_development_dependency 'bundler'
|
@@ -36,7 +37,6 @@ EOD
|
|
36
37
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
37
38
|
spec.add_development_dependency 'yard'
|
38
39
|
|
39
|
-
|
40
40
|
spec.add_dependency 'multi_json'
|
41
41
|
spec.add_dependency 'naught'
|
42
42
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'delegate'
|
2
3
|
require 'basquiat/adapters/base_message'
|
3
4
|
|
4
5
|
module Basquiat
|
5
6
|
module Adapters
|
6
|
-
# Base implementation for an adapter
|
7
|
+
# Base implementation for an adapter in uses {HashRefinements} internally.
|
7
8
|
class Base
|
8
9
|
using Basquiat::HashRefinements
|
9
10
|
|
@@ -21,9 +22,9 @@ module Basquiat
|
|
21
22
|
strategies[config_name.to_sym] = klass
|
22
23
|
end
|
23
24
|
|
24
|
-
# Return the Strategy Class registered on key
|
25
|
+
# Return the Strategy Class registered on given key
|
25
26
|
# @param key [#to_sym] configured key for the wanted strategy
|
26
|
-
# @return [Class]
|
27
|
+
# @return [Class] the strategy class
|
27
28
|
# @raise [Errors::StrategyNotRegistered] if it fails to find the key
|
28
29
|
def strategy(key)
|
29
30
|
strategies.fetch(key)
|
@@ -32,7 +33,7 @@ module Basquiat
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
# @param procs
|
36
|
+
# @param procs [Object]
|
36
37
|
# It's a hash by default, but usually will be superseded by the adapter implementation
|
37
38
|
def initialize(procs: {})
|
38
39
|
@options = base_options
|
@@ -61,8 +62,9 @@ module Basquiat
|
|
61
62
|
end
|
62
63
|
|
63
64
|
# The default adapter options, merged with the {Basquiat::Configuration#adapter_options}. Used internally.
|
64
|
-
# @
|
65
|
+
# @api private
|
65
66
|
# @return [Hash] the full options hash
|
67
|
+
# @todo rename this method
|
66
68
|
def base_options
|
67
69
|
default_options.merge(Basquiat.configuration.adapter_options)
|
68
70
|
end
|
@@ -76,19 +78,18 @@ module Basquiat
|
|
76
78
|
# @!group Adapter specific implementations
|
77
79
|
# @abstract Publish an event to the event stream
|
78
80
|
def publish
|
79
|
-
|
81
|
+
raise Basquiat::Errors::SubclassResponsibility
|
80
82
|
end
|
81
83
|
|
82
84
|
# @abstract subscribe_to the event stream
|
83
85
|
def subscribe_to
|
84
|
-
|
86
|
+
raise Basquiat::Errors::SubclassResponsibility
|
85
87
|
end
|
86
88
|
|
87
89
|
# @abstract Disconnect from the message queue
|
88
90
|
def disconnect
|
89
|
-
|
91
|
+
raise Basquiat::Errors::SubclassResponsibility
|
90
92
|
end
|
91
|
-
|
92
93
|
# @!endgroup
|
93
94
|
|
94
95
|
private
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
@@ -7,21 +8,21 @@ module Basquiat
|
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
@options = { connection:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
queue:
|
15
|
-
name:
|
11
|
+
{ hosts: ['localhost'],
|
12
|
+
port: 5672,
|
13
|
+
auth: { user: 'guest', password: 'guest' }
|
14
|
+
},
|
15
|
+
queue: {
|
16
|
+
name: Basquiat.configuration.queue_name,
|
16
17
|
durable: true,
|
17
18
|
options: {} },
|
18
|
-
exchange:
|
19
|
-
name:
|
19
|
+
exchange: {
|
20
|
+
name: Basquiat.configuration.exchange_name,
|
20
21
|
durable: true,
|
21
22
|
options: {} },
|
22
23
|
publisher: { confirm: true, persistent: false },
|
23
|
-
consumer:
|
24
|
-
requeue:
|
24
|
+
consumer: { prefetch: 1000, manual_ack: true },
|
25
|
+
requeue: { enabled: false } }
|
25
26
|
end
|
26
27
|
|
27
28
|
def base_options
|
@@ -47,10 +48,10 @@ module Basquiat
|
|
47
48
|
|
48
49
|
# @return [Hash] the session options
|
49
50
|
def session_options
|
50
|
-
{ exchange:
|
51
|
+
{ exchange: @options[:exchange],
|
51
52
|
publisher: @options[:publisher],
|
52
|
-
consumer:
|
53
|
-
queue:
|
53
|
+
consumer: @options[:consumer],
|
54
|
+
queue: @options[:queue] }.deep_merge(strategy.session_options)
|
54
55
|
end
|
55
56
|
|
56
57
|
# @return [BaseStrategy] the requeue strategy or {BasicAcknowledge} if none is configured
|
@@ -1,15 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
4
5
|
# Control the connection to the RabitMQ server. Delegates calls to {Bunny::Connection}
|
5
6
|
class Connection < SimpleDelegator
|
6
7
|
# @param hosts: [Array<String>] IPs or FQDN of the RabbitMQ instances
|
7
|
-
# @param port
|
8
|
-
# @param failover: [Hash]
|
8
|
+
# @param port [Fixnum] Port that the RabbitMQ instances run
|
9
9
|
# @option failover: [Fixnum] :max_retries (5) Maximum number of reconnection retries
|
10
10
|
# @option failover: [Fixnum] :default_timeout (5) Interval between to reconnect attempts
|
11
11
|
# @option failover: [Fixnum] :connection_timeout (5) Allowed time before a connection attempt timeouts
|
12
|
-
# @param auth: [Hash]
|
13
12
|
# @option auth: [String] :user ('guest')
|
14
13
|
# @option auth: [String] :password ('guest')
|
15
14
|
def initialize(hosts:, port: 5672, failover: {}, auth: {})
|
@@ -23,19 +22,22 @@ module Basquiat
|
|
23
22
|
# @return [Bunny::Channel]
|
24
23
|
def create_channel
|
25
24
|
connection.start
|
25
|
+
Basquiat.logger.debug 'Creating a new channel'
|
26
26
|
connection.create_channel
|
27
27
|
end
|
28
28
|
|
29
29
|
# Starts the connection if needed
|
30
30
|
def start
|
31
|
+
Basquiat.logger.debug 'Connecting to RabbitMQ'
|
31
32
|
connection.start unless connection.connected?
|
32
33
|
end
|
33
34
|
|
35
|
+
# checks if the connection is started
|
34
36
|
def connected?
|
35
37
|
connection.status == :started
|
36
38
|
end
|
37
39
|
|
38
|
-
# Closes
|
40
|
+
# Closes all channels and then the connection.
|
39
41
|
def disconnect
|
40
42
|
connection.close_all_channels
|
41
43
|
connection.close
|
@@ -46,6 +48,7 @@ module Basquiat
|
|
46
48
|
|
47
49
|
def reset
|
48
50
|
@connection = nil
|
51
|
+
__setobj__(nil)
|
49
52
|
end
|
50
53
|
|
51
54
|
def connection
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
3
2
|
module Basquiat
|
4
3
|
module Adapters
|
5
4
|
class RabbitMq
|
@@ -13,7 +12,7 @@ module Basquiat
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def []=(key, value)
|
16
|
-
if key =~
|
15
|
+
if key =~ /\*|#/
|
17
16
|
set_pattern_key(key, value)
|
18
17
|
else
|
19
18
|
@exact[key] = value
|
@@ -34,7 +33,7 @@ module Basquiat
|
|
34
33
|
key = if key =~ /\*/
|
35
34
|
/^#{key.gsub('*', '[^.]+')}$/
|
36
35
|
else
|
37
|
-
/^#{key.gsub(
|
36
|
+
/^#{key.gsub(/#/, '.*')}$/
|
38
37
|
end
|
39
38
|
@patterns[key] = value
|
40
39
|
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
5
|
+
# A RabbitMQ message, with it's delivery info and properties
|
6
|
+
# It's used instead of a simple hash so we can access more easily
|
7
|
+
# the properties needed for acks and requeues
|
4
8
|
class Message < Basquiat::Adapters::BaseMessage
|
5
9
|
attr_reader :delivery_info, :props
|
6
|
-
|
10
|
+
alias di delivery_info
|
7
11
|
# @!attribute [r] delivery_info
|
8
12
|
# @return [Hash] RabbitMQ delivery_info.
|
9
13
|
# @!attribute [r] props
|
@@ -25,6 +29,7 @@ module Basquiat
|
|
25
29
|
end
|
26
30
|
|
27
31
|
# Shorthand for delivery_info.delivery_tag
|
32
|
+
# @return [String] the message's Delivery Tag
|
28
33
|
def delivery_tag
|
29
34
|
delivery_info.delivery_tag
|
30
35
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
@@ -17,7 +18,7 @@ module Basquiat
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def run(_message)
|
20
|
-
|
21
|
+
raise Basquiat::Errors::SubclassResponsibility
|
21
22
|
end
|
22
23
|
|
23
24
|
def ack(message)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
@@ -11,13 +12,11 @@ module Basquiat
|
|
11
12
|
queue: {
|
12
13
|
options: {
|
13
14
|
'x-dead-letter-exchange' => opts.fetch(:exchange, 'basquiat.dlx') } } },
|
14
|
-
dlx:
|
15
|
+
dlx: { ttl: opts.fetch(:ttl, 1_000) } }
|
15
16
|
end
|
16
17
|
|
17
18
|
def session_options
|
18
19
|
options.fetch :session
|
19
|
-
rescue KeyError
|
20
|
-
raise 'You have to setup the strategy first'
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
@@ -7,15 +8,16 @@ module Basquiat
|
|
7
8
|
attr_reader :options
|
8
9
|
|
9
10
|
def setup(opts)
|
10
|
-
@options = {
|
11
|
-
|
12
|
-
|
11
|
+
@options = { retries: 5,
|
12
|
+
exchange_name: 'basquiat.dlx',
|
13
|
+
queue_name_preffix: 'basquiat.ddlq' }.deep_merge(opts)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def initialize(session)
|
17
18
|
super
|
18
19
|
setup_delayed_delivery
|
20
|
+
@queue_name = session.queue_name
|
19
21
|
end
|
20
22
|
|
21
23
|
def run(message)
|
@@ -36,10 +38,10 @@ module Basquiat
|
|
36
38
|
# @return [String] the calculated routing key for a republish / requeue
|
37
39
|
def requeue_route_for(key)
|
38
40
|
event_name, timeout = extract_event_info(key)
|
39
|
-
if timeout ==
|
40
|
-
"rejected.#{
|
41
|
+
if timeout == max_timeout
|
42
|
+
"rejected.#{@queue_name}.#{event_name}"
|
41
43
|
else
|
42
|
-
"#{timeout * 2}.#{
|
44
|
+
"#{timeout * 2}.#{@queue_name}.#{event_name}"
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -47,43 +49,40 @@ module Basquiat
|
|
47
49
|
# @return [Array<String, Integer>] a 2 item array composed of the event.name (aka original routing_key) and
|
48
50
|
# the current timeout
|
49
51
|
def extract_event_info(key)
|
50
|
-
|
51
|
-
|
52
|
-
[md.captures[1], md.captures[0].to_i]
|
53
|
-
else
|
54
|
-
# So timeout can turn into 1 second, weird but spares some checking
|
55
|
-
[key, 500]
|
56
|
-
end
|
52
|
+
matched = key.match(/^(\d+)\.#{session.queue.name}\.(.+)$/)
|
53
|
+
matched && [matched.captures[1], matched.captures[0].to_i] || [key, 500]
|
57
54
|
end
|
58
55
|
|
59
56
|
def options
|
60
|
-
self.class.options
|
57
|
+
self.class.options
|
61
58
|
end
|
62
59
|
|
63
60
|
def setup_delayed_delivery
|
64
61
|
@exchange = session.channel.topic(options[:exchange_name], durable: true)
|
65
62
|
session.bind_queue("*.#{session.queue.name}.#")
|
66
63
|
prepare_timeout_queues
|
64
|
+
create_and_bind_rejected_queue
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_and_bind_rejected_queue
|
67
68
|
queue = session.channel.queue("#{options[:queue_name_preffix]}_rejected", durable: true)
|
68
69
|
queue.bind(@exchange, routing_key: 'rejected.#')
|
69
70
|
end
|
70
71
|
|
71
72
|
def prepare_timeout_queues
|
72
|
-
|
73
|
+
(0..options[:retries] - 1).each do |iteration|
|
73
74
|
timeout = 2**iteration
|
74
|
-
session.channel.queue("#{options[:queue_name_preffix]}_#{timeout}",
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
queue = session.channel.queue("#{options[:queue_name_preffix]}_#{timeout}",
|
76
|
+
durable: true,
|
77
|
+
arguments: {
|
78
|
+
'x-dead-letter-exchange' => session.exchange.name,
|
79
|
+
'x-message-ttl' => timeout * 1_000 })
|
80
|
+
queue.bind(@exchange, routing_key: "#{timeout * 1_000}.#")
|
78
81
|
end
|
79
|
-
bind_timeout_queues(queues)
|
80
82
|
end
|
81
83
|
|
82
|
-
def
|
83
|
-
|
84
|
-
timeout = queue.arguments['x-message-ttl'].to_i
|
85
|
-
queue.bind(@exchange, routing_key: "#{timeout}.#")
|
86
|
-
end
|
84
|
+
def max_timeout
|
85
|
+
2**(options[:retries] - 1) * 1_000
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Basquiat
|
2
3
|
module Adapters
|
3
4
|
class RabbitMq
|
5
|
+
# A RabbitMQ session.
|
4
6
|
class Session
|
5
7
|
attr_reader :channel
|
6
8
|
|
@@ -34,6 +36,10 @@ module Basquiat
|
|
34
36
|
arguments: (@options[:queue][:options] || {}))
|
35
37
|
end
|
36
38
|
|
39
|
+
def queue_name
|
40
|
+
queue.name
|
41
|
+
end
|
42
|
+
|
37
43
|
def exchange
|
38
44
|
@exchange ||= channel.topic(@options[:exchange][:name],
|
39
45
|
durable: @options[:exchange][:durable],
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'bunny'
|
2
3
|
require 'delegate'
|
3
4
|
|
@@ -68,7 +69,7 @@ module Basquiat
|
|
68
69
|
@strategy = nil
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
+
alias disconnect reset_connection
|
72
73
|
|
73
74
|
# Lazy initializes the requeue strategy configured for the adapter
|
74
75
|
# @return [BaseStrategy]
|
data/lib/basquiat/adapters.rb
CHANGED
data/lib/basquiat/errors.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'set'
|
2
3
|
|
3
4
|
module Basquiat
|
@@ -11,6 +12,10 @@ module Basquiat
|
|
11
12
|
def descendants
|
12
13
|
@descendants ||= []
|
13
14
|
end
|
15
|
+
|
16
|
+
def reconfigure_children
|
17
|
+
descendants.each(&:reload_adapter_from_configuration)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
def reload_adapter_from_configuration
|
@@ -25,7 +30,8 @@ module Basquiat
|
|
25
30
|
def adapter=(adapter_klass)
|
26
31
|
@adapter = adapter_klass.new
|
27
32
|
end
|
28
|
-
|
33
|
+
|
34
|
+
alias event_adapter= adapter=
|
29
35
|
|
30
36
|
def adapter
|
31
37
|
@adapter ||= Kernel.const_get(Basquiat.configuration.default_adapter).new
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'naught'
|
2
3
|
require 'erb'
|
3
4
|
require 'basquiat/support/hash_refinements'
|
@@ -15,7 +16,7 @@ module Basquiat
|
|
15
16
|
logger.error do
|
16
17
|
{ exception: exception, stack_trace: exception.stack_trace, message: message }.to_json
|
17
18
|
end
|
18
|
-
|
19
|
+
raise exception
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -70,7 +71,7 @@ module Basquiat
|
|
70
71
|
|
71
72
|
# Used by the railtie. Forces the reconfiguration of all extended classes
|
72
73
|
def reload_classes
|
73
|
-
Basquiat::Base.
|
74
|
+
Basquiat::Base.reconfigure_children
|
74
75
|
end
|
75
76
|
|
76
77
|
private
|
data/lib/basquiat/support.rb
CHANGED
data/lib/basquiat/version.rb
CHANGED
data/lib/basquiat.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'multi_json'
|
2
3
|
require 'naught'
|
3
4
|
require 'yaml'
|
@@ -11,7 +12,7 @@ require 'basquiat/interfaces/base'
|
|
11
12
|
# Overall namespace config class
|
12
13
|
module Basquiat
|
13
14
|
class << self
|
14
|
-
# resets the
|
15
|
+
# resets the library configuration. Useful for testing and not much else
|
15
16
|
def reset
|
16
17
|
@configuration = Configuration.new
|
17
18
|
end
|