klomp 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +5 -0
- data/Manifest.txt +1 -0
- data/README.md +4 -0
- data/klomp.gemspec +3 -3
- data/lib/klomp.rb +8 -6
- data/lib/klomp/connection.rb +17 -10
- data/lib/klomp/frames.rb +12 -4
- data/lib/klomp/subscription.rb +14 -0
- data/spec/klomp/connection_spec.rb +29 -1
- data/spec/klomp_spec.rb +4 -4
- metadata +4 -3
data/ChangeLog.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Klomp Changes
|
2
2
|
--------------------------------------------------------------------------------
|
3
3
|
|
4
|
+
1.0.8 (2013/04/16)
|
5
|
+
================================================================================
|
6
|
+
- Allow headers to be passed to subscribe and unsubscribe.
|
7
|
+
|
8
|
+
|
4
9
|
1.0.7 (2013/02/04)
|
5
10
|
================================================================================
|
6
11
|
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,10 @@ end
|
|
38
38
|
klomp.subscribe("/queue/klomp", Klompen.new)
|
39
39
|
klomp.unsubscribe("/queue/klomp")
|
40
40
|
|
41
|
+
# subscribe with custom headers
|
42
|
+
klomp.subscribe("/queue/klomp", Klompen.new, :persistent => :true)
|
43
|
+
klomp.subscribe("/queue/klomp", :persistent => :true) do ... end
|
44
|
+
|
41
45
|
klomp.disconnect
|
42
46
|
```
|
43
47
|
|
data/klomp.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "klomp"
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nick Sieger"]
|
9
|
-
s.date = "2013-
|
9
|
+
s.date = "2013-04-17"
|
10
10
|
s.description = "Klomp is a simple [Stomp] messaging client that keeps your sanity intact.\n\nThe purpose of Klomp is to be the simplest possible Stomp client. No in-memory\nbuffering of outgoing messages, no fanout subscriptions in-process, no\ntransactions, no complicated messaging patterns. Code simple enough so that when\nsomething goes wrong, the problem is obvious.\n\n[Stomp]: http://stomp.github.com/"
|
11
11
|
s.email = ["nick.sieger@livingsocial.com"]
|
12
12
|
s.extra_rdoc_files = ["Manifest.txt"]
|
13
|
-
s.files = [".gemtest", ".rspec", ".simplecov", "ChangeLog.md", "Gemfile", "Gemfile.lock", "Manifest.txt", "README.md", "Rakefile", "klomp.gemspec", "lib/klomp.rb", "lib/klomp/connection.rb", "lib/klomp/frames.rb", "lib/klomp/sentinel.rb", "spec/acceptance/acceptance_spec.rb", "spec/acceptance/reconnect_spec.rb", "spec/frames/auth_error.txt", "spec/frames/connect.txt", "spec/frames/connect_vhost.txt", "spec/frames/connected.txt", "spec/frames/disconnect.txt", "spec/frames/error.txt", "spec/frames/greeting.txt", "spec/frames/message.txt", "spec/frames/receipt.txt", "spec/frames/subscribe.txt", "spec/frames/unsubscribe.txt", "spec/klomp/connection_spec.rb", "spec/klomp/frames_spec.rb", "spec/klomp/sentinel_spec.rb", "spec/klomp_spec.rb", "spec/spec_helper.rb", "spec/support/have_received.rb", "spec/support/shared_contexts.rb"]
|
13
|
+
s.files = [".gemtest", ".rspec", ".simplecov", "ChangeLog.md", "Gemfile", "Gemfile.lock", "Manifest.txt", "README.md", "Rakefile", "klomp.gemspec", "lib/klomp.rb", "lib/klomp/connection.rb", "lib/klomp/frames.rb", "lib/klomp/sentinel.rb", "lib/klomp/subscription.rb", "spec/acceptance/acceptance_spec.rb", "spec/acceptance/reconnect_spec.rb", "spec/frames/auth_error.txt", "spec/frames/connect.txt", "spec/frames/connect_vhost.txt", "spec/frames/connected.txt", "spec/frames/disconnect.txt", "spec/frames/error.txt", "spec/frames/greeting.txt", "spec/frames/message.txt", "spec/frames/receipt.txt", "spec/frames/subscribe.txt", "spec/frames/unsubscribe.txt", "spec/klomp/connection_spec.rb", "spec/klomp/frames_spec.rb", "spec/klomp/sentinel_spec.rb", "spec/klomp_spec.rb", "spec/spec_helper.rb", "spec/support/have_received.rb", "spec/support/shared_contexts.rb"]
|
14
14
|
s.homepage = "http://github.com/livingsocial/klomp"
|
15
15
|
s.rdoc_options = ["--main", "README.md"]
|
16
16
|
s.require_paths = ["lib"]
|
data/lib/klomp.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Klomp
|
2
|
-
VERSION = '1.0.
|
2
|
+
VERSION = '1.0.8'
|
3
3
|
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
@@ -23,17 +23,18 @@ class Klomp
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
def subscribe(queue, subscriber = nil, headers = {}, &block)
|
28
|
+
connections.map {|conn| conn.subscribe(queue, subscriber, headers, &block) }
|
28
29
|
end
|
29
30
|
|
30
|
-
def unsubscribe(queue)
|
31
|
+
def unsubscribe(queue, headers = {})
|
31
32
|
if Array === queue
|
32
33
|
raise ArgumentError,
|
33
34
|
"wrong size array for #{connections.size} (#{queue.size})" unless connections.size == queue.size
|
34
|
-
connections.zip(queue).map {|conn,arg| conn.unsubscribe
|
35
|
+
connections.zip(queue).map {|conn,arg| conn.unsubscribe(arg, headers) rescue nil }
|
35
36
|
else
|
36
|
-
connections.map {|conn| conn.unsubscribe(queue) rescue nil }
|
37
|
+
connections.map {|conn| conn.unsubscribe(queue, headers) rescue nil }
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -48,6 +49,7 @@ class Klomp
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
52
|
+
require 'klomp/subscription'
|
51
53
|
require 'klomp/connection'
|
52
54
|
require 'klomp/sentinel'
|
53
55
|
require 'klomp/frames'
|
data/lib/klomp/connection.rb
CHANGED
@@ -32,18 +32,23 @@ class Klomp
|
|
32
32
|
connect
|
33
33
|
end
|
34
34
|
|
35
|
-
def publish(queue, body, headers={})
|
35
|
+
def publish(queue, body, headers = {})
|
36
36
|
write Frames::Send.new(queue, body, headers)
|
37
37
|
end
|
38
38
|
|
39
|
-
def subscribe(queue, subscriber = nil, &block)
|
39
|
+
def subscribe(queue, subscriber = nil, headers = {}, &block)
|
40
|
+
if subscriber.is_a?(Hash)
|
41
|
+
headers = subscriber
|
42
|
+
subscriber = nil
|
43
|
+
end
|
44
|
+
|
40
45
|
raise Klomp::Error, "no subscriber provided" unless subscriber || block
|
41
46
|
raise Klomp::Error, "subscriber does not respond to #call" if subscriber && !subscriber.respond_to?(:call)
|
42
47
|
previous = subscriptions[queue]
|
43
|
-
subscriptions[queue] = subscriber || block
|
44
|
-
frame = Frames::Subscribe.new(queue)
|
48
|
+
subscriptions[queue] = Subscription.new(subscriber || block, headers)
|
49
|
+
frame = Frames::Subscribe.new(queue, headers)
|
45
50
|
if previous
|
46
|
-
frame.previous_subscriber = previous
|
51
|
+
frame.previous_subscriber = previous.subscriber
|
47
52
|
else
|
48
53
|
write frame
|
49
54
|
end
|
@@ -51,9 +56,9 @@ class Klomp
|
|
51
56
|
frame
|
52
57
|
end
|
53
58
|
|
54
|
-
def unsubscribe(queue)
|
59
|
+
def unsubscribe(queue, headers = {})
|
55
60
|
queue = queue.headers['destination'] if Frames::Subscribe === queue
|
56
|
-
write Frames::Unsubscribe.new(queue) if subscriptions.delete queue
|
61
|
+
write Frames::Unsubscribe.new(queue, headers) if subscriptions.delete queue
|
57
62
|
end
|
58
63
|
|
59
64
|
def connected?() @socket end
|
@@ -75,7 +80,9 @@ class Klomp
|
|
75
80
|
connect
|
76
81
|
subs = subscriptions.dup
|
77
82
|
subscriptions.clear
|
78
|
-
subs.each
|
83
|
+
subs.each do |queue, subscription|
|
84
|
+
subscribe(queue, subscription.subscriber, subscription.headers)
|
85
|
+
end
|
79
86
|
@sentinel = nil
|
80
87
|
ensure
|
81
88
|
@subscriptions = subs if subs && subs.size != @subscriptions.size
|
@@ -152,8 +159,8 @@ class Klomp
|
|
152
159
|
begin
|
153
160
|
message = read Frames::Message
|
154
161
|
raise Error, message.headers['message'] if message.error?
|
155
|
-
if
|
156
|
-
|
162
|
+
if subscription = subscriptions[message.headers['destination']]
|
163
|
+
subscription.call(message)
|
157
164
|
end
|
158
165
|
rescue INTERRUPT
|
159
166
|
break
|
data/lib/klomp/frames.rb
CHANGED
@@ -26,6 +26,12 @@ class Klomp
|
|
26
26
|
pair.map {|x| x.to_s.gsub("\n","\\n").gsub(":","\\c").gsub("\\", "\\\\") }.join(':')
|
27
27
|
end.join("\n").tap {|s| s << "\n" unless s.empty? }
|
28
28
|
end
|
29
|
+
|
30
|
+
def stringify_headers(hdrs)
|
31
|
+
new_hdrs = {}
|
32
|
+
hdrs.each { |k, v| new_hdrs[k.to_s] = v }
|
33
|
+
new_hdrs
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
class ServerFrame < Frame
|
@@ -87,7 +93,7 @@ class Klomp
|
|
87
93
|
class Send < Frame
|
88
94
|
def initialize(queue, body, hdrs)
|
89
95
|
headers['destination'] = queue
|
90
|
-
headers.update(hdrs.reject{|k,v| %w(destination content-length).include? k })
|
96
|
+
headers.update(stringify_headers(hdrs).reject { |k,v| %w(destination content-length).include? k })
|
91
97
|
headers['content-type'] ||= 'text/plain'
|
92
98
|
headers['content-length'] = body.bytesize.to_s
|
93
99
|
@body = body
|
@@ -96,16 +102,18 @@ class Klomp
|
|
96
102
|
|
97
103
|
class Subscribe < Frame
|
98
104
|
attr_accessor :previous_subscriber
|
99
|
-
def initialize(queue)
|
100
|
-
headers
|
105
|
+
def initialize(queue, hdrs = {})
|
106
|
+
headers.update(stringify_headers(hdrs).reject { |k,v| %w(destination ack).include? k })
|
107
|
+
headers['id'] ||= queue
|
101
108
|
headers['destination'] = queue
|
102
109
|
headers['ack'] = 'auto'
|
103
110
|
end
|
104
111
|
end
|
105
112
|
|
106
113
|
class Unsubscribe < Frame
|
107
|
-
def initialize(queue)
|
114
|
+
def initialize(queue, hdrs = {})
|
108
115
|
headers['id'] = queue
|
116
|
+
headers.update(stringify_headers(hdrs).reject { |k,v| %w(id).include? k })
|
109
117
|
end
|
110
118
|
end
|
111
119
|
|
@@ -137,7 +137,35 @@ describe Klomp::Connection do
|
|
137
137
|
|
138
138
|
When { connection.subscribe("/queue/foo", subscriber) }
|
139
139
|
|
140
|
-
Then { connection.subscriptions["/queue/foo"].should == subscriber }
|
140
|
+
Then { connection.subscriptions["/queue/foo"].subscriber.should == subscriber }
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
context "and accepts custom headers" do
|
145
|
+
|
146
|
+
Given(:headers) { { :foo => "bar" } }
|
147
|
+
|
148
|
+
Given { Klomp::Frames::Subscribe.stub!(:new => Klomp::Frames::Subscribe.new("/queue/foo")) }
|
149
|
+
|
150
|
+
When { connection.subscribe("/queue/foo", subscriber, headers) }
|
151
|
+
|
152
|
+
Then { Klomp::Frames::Subscribe.should have_received(:new).with("/queue/foo", headers) }
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
context "and accepts custom headers plus subscriber object" do
|
157
|
+
|
158
|
+
Given(:headers) { { :foo => "bar" } }
|
159
|
+
|
160
|
+
Given { Klomp::Frames::Subscribe.stub!(:new => Klomp::Frames::Subscribe.new("/queue/foo")) }
|
161
|
+
|
162
|
+
When { connection.subscribe("/queue/foo", subscriber, headers) }
|
163
|
+
|
164
|
+
Then do
|
165
|
+
Klomp::Frames::Subscribe.should have_received(:new).with("/queue/foo", headers)
|
166
|
+
connection.subscriptions["/queue/foo"].subscriber.should == subscriber
|
167
|
+
connection.subscriptions["/queue/foo"].headers.should == headers
|
168
|
+
end
|
141
169
|
|
142
170
|
end
|
143
171
|
|
data/spec/klomp_spec.rb
CHANGED
@@ -117,7 +117,7 @@ describe Klomp do
|
|
117
117
|
|
118
118
|
When(:result) { klomp.subscribe("/queue/greeting") { true } }
|
119
119
|
|
120
|
-
Then { connections.values.each {|conn| conn.should have_received(:subscribe).with("/queue/greeting", nil) } }
|
120
|
+
Then { connections.values.each {|conn| conn.should have_received(:subscribe).with("/queue/greeting", nil, {}) } }
|
121
121
|
|
122
122
|
context "and returns the results of all Connection#subscribe as an array" do
|
123
123
|
|
@@ -147,7 +147,7 @@ describe Klomp do
|
|
147
147
|
|
148
148
|
When(:result) { klomp.unsubscribe("/queue/greeting") }
|
149
149
|
|
150
|
-
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with("/queue/greeting") } }
|
150
|
+
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with("/queue/greeting", {}) } }
|
151
151
|
|
152
152
|
context "and returns the results of all Connection#unsubscribe as an array" do
|
153
153
|
|
@@ -163,7 +163,7 @@ describe Klomp do
|
|
163
163
|
|
164
164
|
When { klomp.unsubscribe("/queue/greeting") }
|
165
165
|
|
166
|
-
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with("/queue/greeting") } }
|
166
|
+
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with("/queue/greeting", {}) } }
|
167
167
|
|
168
168
|
end
|
169
169
|
|
@@ -177,7 +177,7 @@ describe Klomp do
|
|
177
177
|
|
178
178
|
When { klomp.unsubscribe arg }
|
179
179
|
|
180
|
-
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with(42) } }
|
180
|
+
Then { connections.values.each {|conn| conn.should have_received(:unsubscribe).with(42, {}) } }
|
181
181
|
|
182
182
|
end
|
183
183
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -238,6 +238,7 @@ files:
|
|
238
238
|
- lib/klomp/connection.rb
|
239
239
|
- lib/klomp/frames.rb
|
240
240
|
- lib/klomp/sentinel.rb
|
241
|
+
- lib/klomp/subscription.rb
|
241
242
|
- spec/acceptance/acceptance_spec.rb
|
242
243
|
- spec/acceptance/reconnect_spec.rb
|
243
244
|
- spec/frames/auth_error.txt
|
@@ -274,7 +275,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
275
|
version: '0'
|
275
276
|
segments:
|
276
277
|
- 0
|
277
|
-
hash:
|
278
|
+
hash: 2253396799858323588
|
278
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
280
|
none: false
|
280
281
|
requirements:
|