message-driver 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/features/CHANGELOG.md +5 -0
- data/lib/message_driver/adapters/bunny_adapter.rb +29 -11
- data/lib/message_driver/version.rb +1 -1
- data/spec/integration/bunny/bunny_adapter_spec.rb +86 -0
- metadata +35 -22
- checksums.yaml +0 -7
data/CHANGELOG.md
CHANGED
data/features/CHANGELOG.md
CHANGED
@@ -302,6 +302,7 @@ module MessageDriver
|
|
302
302
|
@rollback_only = false
|
303
303
|
@need_channel_reset = false
|
304
304
|
@in_transaction = false
|
305
|
+
@require_commit = false
|
305
306
|
end
|
306
307
|
|
307
308
|
def create_destination(name, dest_options = {}, message_props = {})
|
@@ -330,8 +331,8 @@ module MessageDriver
|
|
330
331
|
@in_confirms_transaction = true if options[:type] == :confirm_and_wait
|
331
332
|
end
|
332
333
|
|
333
|
-
def commit_transaction
|
334
|
-
if !in_transaction? &&
|
334
|
+
def commit_transaction
|
335
|
+
if !in_transaction? && !@require_commit
|
335
336
|
fail MessageDriver::TransactionError,
|
336
337
|
"you can't finish the transaction unless you already in one!"
|
337
338
|
end
|
@@ -339,7 +340,7 @@ module MessageDriver
|
|
339
340
|
if @in_confirms_transaction
|
340
341
|
wait_for_confirms(@channel) unless @rollback_only
|
341
342
|
else
|
342
|
-
if is_transactional? && valid? && !@need_channel_reset
|
343
|
+
if is_transactional? && valid? && !@need_channel_reset && @require_commit
|
343
344
|
handle_errors do
|
344
345
|
if @rollback_only
|
345
346
|
@channel.tx_rollback
|
@@ -353,6 +354,7 @@ module MessageDriver
|
|
353
354
|
@rollback_only = false
|
354
355
|
@in_transaction = false
|
355
356
|
@in_confirms_transaction = false
|
357
|
+
@require_commit = false
|
356
358
|
end
|
357
359
|
end
|
358
360
|
|
@@ -415,7 +417,7 @@ module MessageDriver
|
|
415
417
|
end
|
416
418
|
|
417
419
|
def nack_message(message, options = {})
|
418
|
-
requeue = options
|
420
|
+
requeue = options.fetch(:requeue, true)
|
419
421
|
with_channel(true) do |ch|
|
420
422
|
ch.reject(message.delivery_tag, requeue)
|
421
423
|
end
|
@@ -471,24 +473,39 @@ module MessageDriver
|
|
471
473
|
raise MessageDriver::ConnectionError.new(e.to_s, e)
|
472
474
|
end
|
473
475
|
|
476
|
+
def ensure_channel
|
477
|
+
@channel = adapter.connection.create_channel if @channel.nil?
|
478
|
+
reset_channel if @need_channel_reset
|
479
|
+
@channel
|
480
|
+
end
|
481
|
+
|
482
|
+
def ensure_transactional_channel
|
483
|
+
ensure_channel
|
484
|
+
make_channel_transactional
|
485
|
+
end
|
486
|
+
|
487
|
+
def make_channel_transactional
|
488
|
+
unless is_transactional?
|
489
|
+
@channel.tx_select
|
490
|
+
@is_transactional = true
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
474
494
|
def with_channel(require_commit = true)
|
475
495
|
fail MessageDriver::TransactionRollbackOnly if @rollback_only
|
476
496
|
fail MessageDriver::Error, 'this adapter context is not valid!' unless valid?
|
477
|
-
|
478
|
-
|
497
|
+
ensure_channel
|
498
|
+
@require_commit ||= require_commit
|
479
499
|
if in_transaction?
|
480
500
|
if @in_confirms_transaction
|
481
501
|
@channel.confirm_select unless @channel.using_publisher_confirmations?
|
482
502
|
else
|
483
|
-
|
484
|
-
@channel.tx_select
|
485
|
-
@is_transactional = true
|
486
|
-
end
|
503
|
+
make_channel_transactional
|
487
504
|
end
|
488
505
|
end
|
489
506
|
handle_errors do
|
490
507
|
result = yield @channel
|
491
|
-
commit_transaction
|
508
|
+
commit_transaction if require_commit && is_transactional? && !in_transaction?
|
492
509
|
result
|
493
510
|
end
|
494
511
|
end
|
@@ -504,6 +521,7 @@ module MessageDriver
|
|
504
521
|
@channel = adapter.connection.create_channel
|
505
522
|
@is_transactional = false
|
506
523
|
@rollback_only = true if in_transaction?
|
524
|
+
@require_commit
|
507
525
|
end
|
508
526
|
@need_channel_reset = false
|
509
527
|
end
|
@@ -117,6 +117,10 @@ module MessageDriver
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
after(:example) do
|
121
|
+
adapter_context.invalidate
|
122
|
+
end
|
123
|
+
|
120
124
|
it_behaves_like 'an adapter context'
|
121
125
|
it_behaves_like 'transactions are supported'
|
122
126
|
it_behaves_like 'client acks are supported'
|
@@ -390,6 +394,88 @@ module MessageDriver
|
|
390
394
|
end
|
391
395
|
end
|
392
396
|
end
|
397
|
+
|
398
|
+
context 'during a transaction with a transactional context' do
|
399
|
+
let(:channel) { adapter_context.ensure_channel }
|
400
|
+
let(:destination) { MessageDriver::Client.dynamic_destination('tx.test.queue') }
|
401
|
+
before do
|
402
|
+
adapter_context.ensure_transactional_channel
|
403
|
+
destination.purge
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'when nothing occurs' do
|
407
|
+
it 'does not send a commit to the broker' do
|
408
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
409
|
+
MessageDriver::Client.with_message_transaction do
|
410
|
+
end
|
411
|
+
expect(channel).not_to have_received(:tx_commit)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
context 'when a queue is declared' do
|
416
|
+
it 'does not send a commit to the broker' do
|
417
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
418
|
+
MessageDriver::Client.with_message_transaction do
|
419
|
+
MessageDriver::Client.dynamic_destination('', exclusive: true)
|
420
|
+
end
|
421
|
+
expect(channel).not_to have_received(:tx_commit)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
context 'when a message is published' do
|
426
|
+
it 'does send a commit to the broker' do
|
427
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
428
|
+
MessageDriver::Client.with_message_transaction do
|
429
|
+
destination.publish('test message')
|
430
|
+
end
|
431
|
+
expect(channel).to have_received(:tx_commit).once
|
432
|
+
expect(destination.message_count).to eq(1)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context 'when a message is popped' do
|
437
|
+
it 'does not send a commit to the broker' do
|
438
|
+
destination.publish('test message')
|
439
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
440
|
+
MessageDriver::Client.with_message_transaction do
|
441
|
+
msg = destination.pop_message(client_ack: true)
|
442
|
+
expect(msg).not_to be_nil
|
443
|
+
expect(msg.body).to eq('test message')
|
444
|
+
end
|
445
|
+
expect(channel).not_to have_received(:tx_commit)
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
context 'when a message is acked' do
|
450
|
+
it 'does send a commit to the broker' do
|
451
|
+
destination.publish('test message')
|
452
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
453
|
+
MessageDriver::Client.with_message_transaction do
|
454
|
+
msg = destination.pop_message(client_ack: true)
|
455
|
+
expect(msg).not_to be_nil
|
456
|
+
expect(msg.body).to eq('test message')
|
457
|
+
msg.ack
|
458
|
+
end
|
459
|
+
expect(channel).to have_received(:tx_commit).once
|
460
|
+
expect(destination.message_count).to eq(0)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context 'when a message is nacked' do
|
465
|
+
it 'does send a commit to the broker' do
|
466
|
+
destination.publish('test message')
|
467
|
+
allow(channel).to receive(:tx_commit).and_call_original
|
468
|
+
MessageDriver::Client.with_message_transaction do
|
469
|
+
msg = destination.pop_message(client_ack: true)
|
470
|
+
expect(msg).not_to be_nil
|
471
|
+
expect(msg.body).to eq('test message')
|
472
|
+
msg.nack
|
473
|
+
end
|
474
|
+
expect(channel).to have_received(:tx_commit).once
|
475
|
+
expect(destination.message_count).to eq(1)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
393
479
|
end
|
394
480
|
end
|
395
481
|
end
|
metadata
CHANGED
@@ -1,69 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Matt Campbell
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rspec
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: 3.1.0
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: 3.1.0
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: cucumber
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: aruba
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- -
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- -
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
78
|
description: Easy message queues for ruby using AMQ, STOMP and others
|
@@ -73,13 +82,13 @@ executables: []
|
|
73
82
|
extensions: []
|
74
83
|
extra_rdoc_files: []
|
75
84
|
files:
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
85
|
+
- .coveralls.yml
|
86
|
+
- .gitignore
|
87
|
+
- .relish
|
88
|
+
- .rspec
|
89
|
+
- .rubocop.yml
|
90
|
+
- .rubocop_todo.yml
|
91
|
+
- .travis.yml
|
83
92
|
- CHANGELOG.md
|
84
93
|
- Gemfile
|
85
94
|
- Guardfile
|
@@ -188,26 +197,30 @@ files:
|
|
188
197
|
homepage: https://github.com/message-driver/message-driver
|
189
198
|
licenses:
|
190
199
|
- MIT
|
191
|
-
metadata: {}
|
192
200
|
post_install_message:
|
193
201
|
rdoc_options: []
|
194
202
|
require_paths:
|
195
203
|
- lib
|
196
204
|
required_ruby_version: !ruby/object:Gem::Requirement
|
205
|
+
none: false
|
197
206
|
requirements:
|
198
|
-
- -
|
207
|
+
- - ! '>='
|
199
208
|
- !ruby/object:Gem::Version
|
200
209
|
version: 1.9.2
|
201
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
|
+
none: false
|
202
212
|
requirements:
|
203
|
-
- -
|
213
|
+
- - ! '>='
|
204
214
|
- !ruby/object:Gem::Version
|
205
215
|
version: '0'
|
216
|
+
segments:
|
217
|
+
- 0
|
218
|
+
hash: -4081124424208803284
|
206
219
|
requirements: []
|
207
220
|
rubyforge_project:
|
208
|
-
rubygems_version:
|
221
|
+
rubygems_version: 1.8.23.2
|
209
222
|
signing_key:
|
210
|
-
specification_version:
|
223
|
+
specification_version: 3
|
211
224
|
summary: Easy message queues for ruby
|
212
225
|
test_files:
|
213
226
|
- features/.nav
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 37e87665e5236aa222f318953697cdd22afb4db9
|
4
|
-
data.tar.gz: 3ad5849abc80a63269e6425a3c4c81cc06694be4
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 484d9c907162ac6b4b23829293daa8ee15e852104f823549306f8437448ecd34ff3e4b3f00c8aa2e07cb35a921e913fdac8ba0a6a70a02e21db33979d4441d84
|
7
|
-
data.tar.gz: 8885281a32669a94934c10e545663ee4a2888655b104bf0182edf90aff2d424c32f53447e53f1c9778c72249c8e7176651523c80770a9e8af9ad2af00cc3306e
|