basquiat 1.2.0 → 1.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +50 -0
- data/.gitignore +1 -0
- data/.metrics +1 -5
- data/.reek +0 -1
- data/.rubocop.yml +2 -1
- data/.ruby-version +1 -1
- data/Guardfile +4 -0
- data/README.md +77 -61
- data/basquiat.gemspec +5 -4
- data/basquiat_docker.sh +1 -1
- data/docker/Dockerfile +8 -3
- data/docker-compose.yml +3 -3
- data/lib/basquiat/adapters/base_adapter.rb +42 -7
- data/lib/basquiat/adapters/base_message.rb +14 -9
- data/lib/basquiat/adapters/rabbitmq/configuration.rb +31 -16
- data/lib/basquiat/adapters/rabbitmq/connection.rb +33 -56
- data/lib/basquiat/adapters/rabbitmq/events.rb +1 -1
- data/lib/basquiat/adapters/rabbitmq/message.rb +10 -9
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/auto_acknowledge.rb +15 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/base_strategy.rb +8 -4
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/basic_acknowledge.rb +1 -1
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/dead_lettering.rb +16 -15
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/delayed_delivery.rb +80 -16
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies.rb +7 -0
- data/lib/basquiat/adapters/rabbitmq/session.rb +12 -14
- data/lib/basquiat/adapters/rabbitmq_adapter.rb +35 -16
- data/lib/basquiat/adapters/test_adapter.rb +2 -5
- data/lib/basquiat/errors/strategy_not_registered.rb +1 -9
- data/lib/basquiat/interfaces/base.rb +28 -7
- data/lib/basquiat/support/configuration.rb +33 -4
- data/lib/basquiat/support/hash_refinements.rb +9 -0
- data/lib/basquiat/support/json.rb +9 -0
- data/lib/basquiat/version.rb +1 -1
- data/lib/basquiat.rb +6 -1
- data/spec/lib/adapters/base_adapter_spec.rb +1 -1
- data/spec/lib/adapters/base_message_spec.rb +0 -6
- data/spec/lib/adapters/rabbitmq/configuration_spec.rb +2 -2
- data/spec/lib/adapters/rabbitmq/connection_spec.rb +8 -13
- data/spec/lib/adapters/rabbitmq/events_spec.rb +8 -1
- data/spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb +24 -0
- data/spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb +4 -4
- data/spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb +23 -28
- data/spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb +105 -0
- data/spec/lib/adapters/rabbitmq_adapter_spec.rb +21 -17
- data/spec/lib/basquiat_spec.rb +0 -6
- data/spec/lib/interfaces/base_spec.rb +11 -19
- data/spec/lib/support/configuration_spec.rb +0 -8
- data/spec/lib/support/hash_refinements_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -6
- data/spec/support/rabbitmq_queue_matchers.rb +9 -3
- metadata +21 -12
@@ -5,8 +5,8 @@ describe Basquiat::Adapters::RabbitMq do
|
|
5
5
|
subject(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
6
6
|
|
7
7
|
let(:base_options) do
|
8
|
-
{
|
9
|
-
port:
|
8
|
+
{ connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
|
9
|
+
port: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_PORT') { 5672 } },
|
10
10
|
publisher: { persistent: true } }
|
11
11
|
end
|
12
12
|
|
@@ -29,33 +29,37 @@ describe Basquiat::Adapters::RabbitMq do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'listener' do
|
32
|
+
it 'runs the rescue block when an exception happens' do
|
33
|
+
coisa = ''
|
34
|
+
adapter.subscribe_to('some.event', ->(_msg) { fail ArgumentError })
|
35
|
+
adapter.listen(block: false, rescue_proc: -> (ex, _msg) { coisa = ex.class.to_s })
|
36
|
+
adapter.publish('some.event', data: 'coisa')
|
37
|
+
sleep 0.7
|
38
|
+
|
39
|
+
expect(coisa).to eq('ArgumentError')
|
40
|
+
end
|
41
|
+
|
32
42
|
it '#subscribe_to some event' do
|
33
43
|
message = ''
|
34
|
-
adapter.subscribe_to('some.event',
|
35
|
-
->(msg) { message << msg[:data].upcase! })
|
44
|
+
adapter.subscribe_to('some.event', ->(msg) { message = msg[:data].upcase })
|
36
45
|
adapter.listen(block: false)
|
37
|
-
adapter.publish('some.event', data: '
|
38
|
-
sleep 0.7
|
46
|
+
adapter.publish('some.event', data: 'message')
|
47
|
+
sleep 0.7
|
39
48
|
|
40
|
-
expect(message).to eq('
|
49
|
+
expect(message).to eq('MESSAGE')
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
44
|
-
it '#subscribe_to other
|
53
|
+
it '#subscribe_to other.event with #' do
|
45
54
|
message_received = ''
|
46
|
-
subject.subscribe_to('other.event.#',
|
47
|
-
lambda do |msg|
|
48
|
-
msg[:data].upcase!
|
49
|
-
message_received = msg
|
50
|
-
end)
|
55
|
+
subject.subscribe_to('other.event.#', ->(msg) { message_received = msg[:data].upcase })
|
51
56
|
subject.listen(block: false)
|
52
57
|
|
53
|
-
subject.publish('other.event.
|
54
|
-
sleep 0.
|
58
|
+
subject.publish('other.event.test', data: 'some stuff')
|
59
|
+
sleep 0.7
|
55
60
|
|
56
|
-
expect(message_received).to eq(
|
61
|
+
expect(message_received).to eq('SOME STUFF')
|
57
62
|
end
|
58
|
-
|
59
63
|
end
|
60
64
|
|
61
65
|
def remove_queues_and_exchanges
|
data/spec/lib/basquiat_spec.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Basquiat do
|
4
|
-
after(:all) do
|
5
|
-
Basquiat.configure do |config|
|
6
|
-
config.config_file = File.expand_path('../../support/basquiat.yml', __FILE__)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
it 'should have a version number' do
|
11
5
|
expect(Basquiat::VERSION).not_to be_nil
|
12
6
|
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# Sample class used for testing
|
4
|
-
class SampleClass
|
5
|
-
extend Basquiat::Base
|
6
|
-
self.event_adapter = Basquiat::Adapters::Test
|
7
|
-
end
|
8
|
-
|
9
3
|
describe Basquiat::Base do
|
4
|
+
# Sample class used for testing
|
5
|
+
class SampleClass
|
6
|
+
extend Basquiat::Base
|
7
|
+
self.adapter = Basquiat::Adapters::Test
|
8
|
+
end
|
9
|
+
|
10
10
|
subject { SampleClass }
|
11
11
|
|
12
|
-
it '.event_adapter' do
|
12
|
+
it '.event_adapter= / .adapter=' do
|
13
13
|
expect(subject).to respond_to(:event_adapter=)
|
14
|
+
expect(subject).to respond_to(:adapter=)
|
14
15
|
end
|
15
16
|
|
16
|
-
it '.
|
17
|
+
it '.adapter_options(option_hash)' do
|
17
18
|
expect(subject).to respond_to(:adapter_options)
|
18
19
|
end
|
19
20
|
|
@@ -45,8 +46,8 @@ describe Basquiat::Base do
|
|
45
46
|
|
46
47
|
it 'publishes to the configured queue and exchanges' do
|
47
48
|
expect do
|
48
|
-
|
49
|
-
end.to change {
|
49
|
+
defaults.publish('test.message', message: 'useful test message')
|
50
|
+
end.to change { defaults.adapter.events('test.message').size }.by(1)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -88,13 +89,4 @@ describe Basquiat::Base do
|
|
88
89
|
expect(subject.listen(block: false)).to eq(%w(e e e))
|
89
90
|
end
|
90
91
|
end
|
91
|
-
|
92
|
-
it 'trigger an event after processing a message' do
|
93
|
-
subject.publish('some.event', 'some message')
|
94
|
-
subject.instance_eval <<-METHCALL
|
95
|
-
subscribe_to 'some.event', ->(msg) { publish('other.event', "Redirected \#{msg}") }
|
96
|
-
METHCALL
|
97
|
-
expect { subject.listen(block: false) }.to_not raise_error
|
98
|
-
expect(subject.adapter.events('other.event').size).to eq(1)
|
99
|
-
end
|
100
92
|
end
|
@@ -14,8 +14,8 @@ describe Basquiat::HashRefinements do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it '#deep_merge with nested different hashes' do
|
17
|
-
base
|
18
|
-
other
|
17
|
+
base = { queue: { options: { some: 'value' } } }
|
18
|
+
other = { queue: { options: { another: 'setting' } } }
|
19
19
|
base.deep_merge(other)
|
20
20
|
expect(base[:queue][:options].keys).to contain_exactly(:some, :another)
|
21
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
|
2
|
+
require 'codeclimate-test-reporter'
|
3
3
|
require 'simplecov'
|
4
|
-
|
4
|
+
CodeClimate::TestReporter.start
|
5
5
|
SimpleCov.start do
|
6
6
|
add_filter { |source| source.lines_of_code <= 3 }
|
7
7
|
add_filter { |source| source.filename =~ /spec/ }
|
@@ -17,9 +17,5 @@ end
|
|
17
17
|
ENV['BASQUIAT_ENV'] = 'test'
|
18
18
|
require 'basquiat'
|
19
19
|
|
20
|
-
Basquiat.configure do |config|
|
21
|
-
config.config_file = File.expand_path('../support/basquiat.yml', __FILE__)
|
22
|
-
config.logger = Logger.new('log/basquiat_test.log')
|
23
|
-
end
|
24
20
|
require 'support/shared_examples/basquiat_adapter_shared_examples'
|
25
21
|
require 'support/rabbitmq_queue_matchers'
|
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
1
4
|
class QueueStats
|
2
5
|
def initialize(queue)
|
3
6
|
@queue = queue
|
4
|
-
host = ENV.fetch('
|
7
|
+
host = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_ADDR', 'localhost')
|
5
8
|
port = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_PORT', 15_672)
|
6
|
-
@uri = "http
|
9
|
+
@uri = URI.parse("http://#{host}:#{port}/api/queues/%2F/#{@queue}")
|
7
10
|
end
|
8
11
|
|
9
12
|
def unacked_messages
|
@@ -17,7 +20,10 @@ class QueueStats
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def fetch
|
20
|
-
|
23
|
+
req = Net::HTTP::Get.new @uri
|
24
|
+
req.basic_auth('guest', 'guest')
|
25
|
+
res = Net::HTTP.start(@uri.host, @uri.port) { |http| http.request(req) }
|
26
|
+
res.body
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basquiat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello "mereghost" Rocha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: guard-yard
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: bunny
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: rubocop
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - ">="
|
@@ -179,7 +179,7 @@ dependencies:
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: metric_fu
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
@@ -193,7 +193,7 @@ dependencies:
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: codeclimate-test-reporter
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
@@ -207,7 +207,7 @@ dependencies:
|
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: yard
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - ">="
|
@@ -248,14 +248,17 @@ dependencies:
|
|
248
248
|
- - ">="
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '0'
|
251
|
-
description:
|
252
|
-
|
251
|
+
description: 'Basquiat is a library that intends to abstract all the complexity of
|
252
|
+
working with message queues
|
253
|
+
|
254
|
+
'
|
253
255
|
email:
|
254
256
|
- marcello.rocha@gmail.com.br
|
255
257
|
executables: []
|
256
258
|
extensions: []
|
257
259
|
extra_rdoc_files: []
|
258
260
|
files:
|
261
|
+
- ".codeclimate.yml"
|
259
262
|
- ".gitignore"
|
260
263
|
- ".metrics"
|
261
264
|
- ".reek"
|
@@ -282,6 +285,7 @@ files:
|
|
282
285
|
- lib/basquiat/adapters/rabbitmq/events.rb
|
283
286
|
- lib/basquiat/adapters/rabbitmq/message.rb
|
284
287
|
- lib/basquiat/adapters/rabbitmq/requeue_strategies.rb
|
288
|
+
- lib/basquiat/adapters/rabbitmq/requeue_strategies/auto_acknowledge.rb
|
285
289
|
- lib/basquiat/adapters/rabbitmq/requeue_strategies/base_strategy.rb
|
286
290
|
- lib/basquiat/adapters/rabbitmq/requeue_strategies/basic_acknowledge.rb
|
287
291
|
- lib/basquiat/adapters/rabbitmq/requeue_strategies/dead_lettering.rb
|
@@ -305,8 +309,10 @@ files:
|
|
305
309
|
- spec/lib/adapters/rabbitmq/connection_spec.rb
|
306
310
|
- spec/lib/adapters/rabbitmq/events_spec.rb
|
307
311
|
- spec/lib/adapters/rabbitmq/message_spec.rb
|
312
|
+
- spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb
|
308
313
|
- spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb
|
309
314
|
- spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb
|
315
|
+
- spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb
|
310
316
|
- spec/lib/adapters/rabbitmq_adapter_spec.rb
|
311
317
|
- spec/lib/adapters/test_adapter_spec.rb
|
312
318
|
- spec/lib/basquiat_spec.rb
|
@@ -333,9 +339,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
333
339
|
version: '0'
|
334
340
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
335
341
|
requirements:
|
336
|
-
- - "
|
342
|
+
- - ">"
|
337
343
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
344
|
+
version: 1.3.1
|
339
345
|
requirements: []
|
340
346
|
rubyforge_project:
|
341
347
|
rubygems_version: 2.4.8
|
@@ -349,8 +355,10 @@ test_files:
|
|
349
355
|
- spec/lib/adapters/rabbitmq/connection_spec.rb
|
350
356
|
- spec/lib/adapters/rabbitmq/events_spec.rb
|
351
357
|
- spec/lib/adapters/rabbitmq/message_spec.rb
|
358
|
+
- spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb
|
352
359
|
- spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb
|
353
360
|
- spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb
|
361
|
+
- spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb
|
354
362
|
- spec/lib/adapters/rabbitmq_adapter_spec.rb
|
355
363
|
- spec/lib/adapters/test_adapter_spec.rb
|
356
364
|
- spec/lib/basquiat_spec.rb
|
@@ -362,3 +370,4 @@ test_files:
|
|
362
370
|
- spec/support/basquiat.yml
|
363
371
|
- spec/support/rabbitmq_queue_matchers.rb
|
364
372
|
- spec/support/shared_examples/basquiat_adapter_shared_examples.rb
|
373
|
+
has_rdoc:
|