qsagi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/lib/qsagi/message.rb +7 -3
- data/lib/qsagi/queue.rb +5 -3
- data/lib/qsagi/version.rb +1 -1
- data/spec/qsagi/message_spec.rb +8 -0
- data/spec/qsagi/queue_spec.rb +13 -0
- metadata +10 -4
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/qsagi/message.rb
CHANGED
@@ -3,16 +3,20 @@ module Qsagi
|
|
3
3
|
attr_reader :payload
|
4
4
|
|
5
5
|
def initialize(message, payload)
|
6
|
-
@
|
6
|
+
@message = message
|
7
7
|
@payload = payload
|
8
8
|
end
|
9
9
|
|
10
10
|
def delivery_tag
|
11
|
-
|
11
|
+
_delivery_details[:delivery_tag]
|
12
12
|
end
|
13
13
|
|
14
14
|
def exchange
|
15
|
-
|
15
|
+
_delivery_details[:exchange]
|
16
|
+
end
|
17
|
+
|
18
|
+
def _delivery_details
|
19
|
+
@delivery_details ||= @message.fetch(:delivery_details, {})
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
data/lib/qsagi/queue.rb
CHANGED
@@ -23,6 +23,10 @@ module Qsagi
|
|
23
23
|
@client.send(:close_socket) unless @client.nil?
|
24
24
|
end
|
25
25
|
|
26
|
+
def length
|
27
|
+
@queue.status[:message_count]
|
28
|
+
end
|
29
|
+
|
26
30
|
def pop(options = {})
|
27
31
|
auto_ack = options.fetch(:auto_ack, true)
|
28
32
|
message = @queue.pop(:ack => !auto_ack)
|
@@ -33,10 +37,8 @@ module Qsagi
|
|
33
37
|
end
|
34
38
|
|
35
39
|
def push(message)
|
36
|
-
#exchange = @client.exchange(self.class._exchange)
|
37
40
|
serialized_message = self.class._serializer.serialize(message)
|
38
|
-
|
39
|
-
@exchange.publish(serialized_message, :key => @queue.name, :persistent => true)
|
41
|
+
@exchange.publish(serialized_message, :key => @queue.name, :persistent => true, :mandatory => true)
|
40
42
|
end
|
41
43
|
|
42
44
|
def reconnect
|
data/lib/qsagi/version.rb
CHANGED
data/spec/qsagi/message_spec.rb
CHANGED
@@ -9,6 +9,10 @@ describe Qsagi::Message do
|
|
9
9
|
}
|
10
10
|
Qsagi::Message.new(data, :parsed_payload).delivery_tag.should == "tag"
|
11
11
|
end
|
12
|
+
|
13
|
+
it "gracefully handles no delivery details" do
|
14
|
+
Qsagi::Message.new({}, :parsed_payload).delivery_tag.should be_nil
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
describe "exchange" do
|
@@ -19,6 +23,10 @@ describe Qsagi::Message do
|
|
19
23
|
}
|
20
24
|
Qsagi::Message.new(data, :parsed_payload).exchange.should == "the_exchange"
|
21
25
|
end
|
26
|
+
|
27
|
+
it "gracefully handles no delivery details" do
|
28
|
+
Qsagi::Message.new({}, :parsed_payload).exchange.should be_nil
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
describe "payload" do
|
data/spec/qsagi/queue_spec.rb
CHANGED
@@ -41,6 +41,19 @@ describe Qsagi::Queue do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
describe "length" do
|
45
|
+
it "returns the number of messages in the queue" do
|
46
|
+
ExampleQueue.connect do |queue|
|
47
|
+
queue.push("message")
|
48
|
+
queue.length.should == 1
|
49
|
+
queue.push("message")
|
50
|
+
queue.length.should == 2
|
51
|
+
queue.pop
|
52
|
+
queue.length.should == 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
describe "pop" do
|
45
58
|
it "automatically acks if :auto_ack is not passed in" do
|
46
59
|
ExampleQueue.connect do |queue|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: qsagi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Braintree
|
@@ -10,11 +10,10 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bunny
|
17
|
-
prerelease: false
|
18
17
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
19
|
requirements:
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
- !ruby/object:Gem::Version
|
23
22
|
version: 0.8.0
|
24
23
|
type: :runtime
|
24
|
+
prerelease: false
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: json
|
28
|
-
prerelease: false
|
29
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
30
|
requirements:
|
@@ -33,6 +32,7 @@ dependencies:
|
|
33
32
|
- !ruby/object:Gem::Version
|
34
33
|
version: 1.7.0
|
35
34
|
type: :runtime
|
35
|
+
prerelease: false
|
36
36
|
version_requirements: *id002
|
37
37
|
description: A friendly way to talk to RabbitMQ
|
38
38
|
email:
|
@@ -73,12 +73,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3593553663519129653
|
77
|
+
segments:
|
78
|
+
- 0
|
76
79
|
version: "0"
|
77
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
81
|
none: false
|
79
82
|
requirements:
|
80
83
|
- - ">="
|
81
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3593553663519129653
|
86
|
+
segments:
|
87
|
+
- 0
|
82
88
|
version: "0"
|
83
89
|
requirements: []
|
84
90
|
|