hot_bunnies 1.3.2-java → 1.3.3-java
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.
- data/lib/hot_bunnies/queue.rb +30 -12
- data/lib/hot_bunnies/version.rb +1 -1
- data/spec/integration/basic_consume_spec.rb +29 -0
- metadata +21 -39
data/lib/hot_bunnies/queue.rb
CHANGED
@@ -48,21 +48,23 @@ module HotBunnies
|
|
48
48
|
[response.message_count, response.consumer_count]
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
private
|
52
52
|
|
53
53
|
def declare!
|
54
54
|
response = if @options[:passive]
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
then @channel.queue_declare_passive(@name)
|
56
|
+
else @channel.queue_declare(@name, @options[:durable], @options[:exclusive], @options[:auto_delete], @options[:arguments])
|
57
|
+
end
|
58
58
|
@name = response.queue
|
59
59
|
end
|
60
60
|
|
61
61
|
class Subscription
|
62
62
|
def initialize(channel, queue_name, options={})
|
63
|
-
@channel
|
63
|
+
@channel = channel
|
64
64
|
@queue_name = queue_name
|
65
|
-
@ack
|
65
|
+
@ack = options.fetch(:ack, false)
|
66
|
+
|
67
|
+
@cancelled = java.util.concurrent.atomic.AtomicBoolean.new(false)
|
66
68
|
end
|
67
69
|
|
68
70
|
def each(options={}, &block)
|
@@ -82,19 +84,35 @@ module HotBunnies
|
|
82
84
|
end
|
83
85
|
|
84
86
|
def cancel
|
85
|
-
raise 'Can\'t cancel: the subscriber haven\'t received an OK yet' if
|
87
|
+
raise 'Can\'t cancel: the subscriber haven\'t received an OK yet' if !self.active?
|
86
88
|
@channel.basic_cancel(@subscriber.consumer_tag)
|
87
89
|
|
90
|
+
# RabbitMQ Java client won't clear consumer_tag from cancelled consumers,
|
91
|
+
# so we have to do this. Sharing consumers
|
92
|
+
# between threads in general is a can of worms but someone somewhere
|
93
|
+
# will almost certainly do it, so. MK.
|
94
|
+
@cancelled.set(true)
|
95
|
+
|
88
96
|
maybe_shutdown_executor
|
89
97
|
end
|
90
98
|
|
91
|
-
|
99
|
+
def active?
|
100
|
+
!@cancelled.get && !@subscriber.nil? && !@subscriber.consumer_tag.nil?
|
101
|
+
end
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
|
103
|
+
def shutdown!
|
104
|
+
if @executor && @shut_down_executor
|
105
|
+
@executor.shutdown_now
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def maybe_shutdown_executor
|
112
|
+
if @executor && @shut_down_executor
|
113
|
+
@executor.shutdown
|
114
|
+
end
|
96
115
|
end
|
97
|
-
end
|
98
116
|
|
99
117
|
def run(&block)
|
100
118
|
@subscriber = BlockingSubscriber.new(@channel, self)
|
data/lib/hot_bunnies/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Queue consumer" do
|
4
|
+
let(:connection) { HotBunnies.connect }
|
5
|
+
let(:channel) { connection.create_channel }
|
6
|
+
|
7
|
+
after :each do
|
8
|
+
channel.close
|
9
|
+
connection.close
|
10
|
+
end
|
11
|
+
|
12
|
+
it "provides predicates" do
|
13
|
+
queue = channel.queue("", :auto_delete => true)
|
14
|
+
|
15
|
+
subscription = queue.subscribe(:blocking => false) { |_, _| nil }
|
16
|
+
|
17
|
+
# consumer tag will be sent by the broker, so this happens
|
18
|
+
# asynchronously and we can either add callbacks/use latches or
|
19
|
+
# just wait. MK.
|
20
|
+
sleep(1.0)
|
21
|
+
subscription.should be_active
|
22
|
+
|
23
|
+
subscription.cancel
|
24
|
+
sleep(1.0)
|
25
|
+
subscription.should_not be_active
|
26
|
+
|
27
|
+
subscription.shutdown!
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,25 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hot_bunnies
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
- 2
|
10
|
-
version: 1.3.2
|
11
6
|
platform: java
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Theo Hultberg
|
14
9
|
- Michael S. Klishin
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2011-11-15 00:00:00 Z
|
13
|
+
date: 2011-11-17 00:00:00.000000000 Z
|
20
14
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
email:
|
15
|
+
description: A object oriented interface to RabbitMQ that uses the Java driver under
|
16
|
+
the hood
|
17
|
+
email:
|
24
18
|
- theo@burtcorp.com
|
25
19
|
executables: []
|
26
|
-
|
27
20
|
extensions: []
|
28
|
-
|
29
21
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
22
|
+
files:
|
32
23
|
- .gitignore
|
33
24
|
- .rvmrc
|
34
25
|
- .travis.yml
|
@@ -48,6 +39,7 @@ files:
|
|
48
39
|
- lib/hot_bunnies/queue.rb
|
49
40
|
- lib/hot_bunnies/version.rb
|
50
41
|
- spec/integration/alternate_exchanges_spec.rb
|
42
|
+
- spec/integration/basic_consume_spec.rb
|
51
43
|
- spec/integration/exchange_bind_spec.rb
|
52
44
|
- spec/integration/exchange_declare_spec.rb
|
53
45
|
- spec/integration/publisher_confirmations_spec.rb
|
@@ -60,36 +52,26 @@ files:
|
|
60
52
|
- spec/spec_helper.rb
|
61
53
|
homepage: http://github.com/iconara/hot_bunnies
|
62
54
|
licenses: []
|
63
|
-
|
64
55
|
post_install_message:
|
65
56
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
57
|
+
require_paths:
|
68
58
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
60
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
66
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
87
71
|
requirements: []
|
88
|
-
|
89
72
|
rubyforge_project: hot_bunnies
|
90
73
|
rubygems_version: 1.8.10
|
91
74
|
signing_key:
|
92
75
|
specification_version: 3
|
93
76
|
summary: Ruby wrapper for the RabbitMQ Java driver
|
94
77
|
test_files: []
|
95
|
-
|