klomp 0.0.2 → 0.0.3
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/.rvmrc +1 -0
- data/ChangeLog.md +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -0
- data/lib/klomp.rb +1 -1
- data/lib/klomp/client.rb +33 -7
- data/test/test_client.rb +10 -3
- data/test/test_helper.rb +14 -0
- metadata +8 -2
data/.rvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rvm use --create 1.9.3@klomp
|
data/ChangeLog.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
Changes
|
|
2
2
|
--------------------------------------------------------------------------------
|
|
3
3
|
|
|
4
|
+
0.0.3 (2012/6/21)
|
|
5
|
+
================================================================================
|
|
6
|
+
|
|
7
|
+
- Upgraded to work with onstomp 1.0.7
|
|
8
|
+
- Fix unsubscribe to accept array of frames that subscribe returns
|
|
9
|
+
|
|
4
10
|
0.0.2 (2012/06/15)
|
|
5
11
|
================================================================================
|
|
6
12
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/lib/klomp.rb
CHANGED
data/lib/klomp/client.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Klomp
|
|
|
7
7
|
|
|
8
8
|
class Client
|
|
9
9
|
attr_reader :read_conn, :write_conn
|
|
10
|
+
attr_accessor :last_connect_exception
|
|
10
11
|
|
|
11
12
|
def initialize(uri, options={})
|
|
12
13
|
@translate_json = options.fetch(:translate_json, true)
|
|
@@ -28,6 +29,23 @@ module Klomp
|
|
|
28
29
|
configure_connections
|
|
29
30
|
end
|
|
30
31
|
|
|
32
|
+
def connect
|
|
33
|
+
@all_conn.each do |conn|
|
|
34
|
+
begin
|
|
35
|
+
attempts = conn.retry_attempts
|
|
36
|
+
conn.retry_attempts = 1
|
|
37
|
+
conn.connect
|
|
38
|
+
rescue OnStomp::Failover::MaximumRetriesExceededError
|
|
39
|
+
location = conn.active_client.uri.dup.tap {|u| u.password = 'REDACTED' }.to_s
|
|
40
|
+
msg = ": #{last_connect_exception.message}" if last_connect_exception
|
|
41
|
+
raise OnStomp::ConnectFailedError, "initial connection failed for #{location}#{msg}"
|
|
42
|
+
ensure
|
|
43
|
+
conn.retry_attempts = attempts
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
31
49
|
def send(*args, &block)
|
|
32
50
|
if @translate_json && args[1].respond_to?(:to_json)
|
|
33
51
|
args[1] = args[1].to_json
|
|
@@ -39,7 +57,6 @@ module Klomp
|
|
|
39
57
|
log.info("[Sending] Destination=#{args[0]} Body=#{args[1]} Headers=#{args[2]}") if log
|
|
40
58
|
@write_conn.send(*args, &block)
|
|
41
59
|
end
|
|
42
|
-
alias puts send
|
|
43
60
|
alias publish send
|
|
44
61
|
|
|
45
62
|
def subscribe(*args, &block)
|
|
@@ -67,6 +84,18 @@ module Klomp
|
|
|
67
84
|
frames
|
|
68
85
|
end
|
|
69
86
|
|
|
87
|
+
def unsubscribe(frames, headers={})
|
|
88
|
+
if !frames.respond_to?(:length) || frames.length != @read_conn.length
|
|
89
|
+
raise ArgumentError,
|
|
90
|
+
"frames is not an array or its length does not match number of connections"
|
|
91
|
+
end
|
|
92
|
+
frames.each_with_index.map {|f,i| @read_conn[i].unsubscribe f, headers }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def subscriptions
|
|
96
|
+
@read_conn.map {|c| c.active_client.subscriptions }
|
|
97
|
+
end
|
|
98
|
+
|
|
70
99
|
def log
|
|
71
100
|
@logger
|
|
72
101
|
end
|
|
@@ -80,18 +109,14 @@ module Klomp
|
|
|
80
109
|
READ_ONLY_METHODS = [
|
|
81
110
|
:ack,
|
|
82
111
|
:nack,
|
|
83
|
-
:unsubscribe,
|
|
84
112
|
]
|
|
85
113
|
|
|
86
114
|
def method_missing(method, *args, &block)
|
|
87
115
|
case method
|
|
88
116
|
when *WRITE_ONLY_METHODS
|
|
89
|
-
@write_conn.
|
|
117
|
+
@write_conn.__send__(method, *args, &block)
|
|
90
118
|
when *READ_ONLY_METHODS
|
|
91
119
|
@read_conn.map {|c| c.__send__(method, *args, &block) }
|
|
92
|
-
when :connect
|
|
93
|
-
@all_conn.each {|c| c.connect}
|
|
94
|
-
self
|
|
95
120
|
else
|
|
96
121
|
@all_conn.map {|c| c.__send__(method, *args) }
|
|
97
122
|
end
|
|
@@ -99,9 +124,10 @@ module Klomp
|
|
|
99
124
|
|
|
100
125
|
private
|
|
101
126
|
def configure_connections
|
|
127
|
+
klomp_client = self
|
|
102
128
|
@all_conn.each do |c|
|
|
103
129
|
c.on_failover_connect_failure do
|
|
104
|
-
|
|
130
|
+
klomp_client.last_connect_exception = $!
|
|
105
131
|
end
|
|
106
132
|
end
|
|
107
133
|
end
|
data/test/test_client.rb
CHANGED
|
@@ -2,9 +2,12 @@ require 'minitest/autorun'
|
|
|
2
2
|
require 'minitest/pride'
|
|
3
3
|
|
|
4
4
|
require 'klomp'
|
|
5
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
6
|
|
|
6
7
|
describe Klomp::Client do
|
|
7
8
|
|
|
9
|
+
include KlompTestHelpers
|
|
10
|
+
|
|
8
11
|
before do
|
|
9
12
|
@uris = [
|
|
10
13
|
'stomp://admin:password@localhost:61613',
|
|
@@ -71,7 +74,7 @@ describe Klomp::Client do
|
|
|
71
74
|
got_message = true if msg.body == body
|
|
72
75
|
client.ack(msg)
|
|
73
76
|
end
|
|
74
|
-
|
|
77
|
+
let_background_processor_run
|
|
75
78
|
assert got_message
|
|
76
79
|
|
|
77
80
|
client.disconnect
|
|
@@ -88,7 +91,7 @@ describe Klomp::Client do
|
|
|
88
91
|
got_message = true if msg.body == reply_to_body
|
|
89
92
|
reply_to_body
|
|
90
93
|
end
|
|
91
|
-
|
|
94
|
+
let_background_processor_run
|
|
92
95
|
assert got_message
|
|
93
96
|
|
|
94
97
|
client.disconnect
|
|
@@ -98,7 +101,11 @@ describe Klomp::Client do
|
|
|
98
101
|
client = Klomp::Client.new(@uris).connect
|
|
99
102
|
|
|
100
103
|
subscribe_frames = client.subscribe(@destination) { |msg| }
|
|
101
|
-
client.unsubscribe(subscribe_frames)
|
|
104
|
+
unsub_frames = client.unsubscribe(subscribe_frames)
|
|
105
|
+
assert_equal subscribe_frames.length, unsub_frames.length
|
|
106
|
+
let_background_processor_run
|
|
107
|
+
|
|
108
|
+
assert client.subscriptions.flatten.empty?, "expected connection to have no subscriptions"
|
|
102
109
|
|
|
103
110
|
client.disconnect
|
|
104
111
|
end
|
data/test/test_helper.rb
ADDED
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: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
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: 2012-06-
|
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: onstomp
|
|
@@ -51,6 +51,7 @@ extensions: []
|
|
|
51
51
|
extra_rdoc_files: []
|
|
52
52
|
files:
|
|
53
53
|
- .gitignore
|
|
54
|
+
- .rvmrc
|
|
54
55
|
- ChangeLog.md
|
|
55
56
|
- Gemfile
|
|
56
57
|
- Gemfile.lock
|
|
@@ -62,6 +63,7 @@ files:
|
|
|
62
63
|
- lib/klomp/client.rb
|
|
63
64
|
- tasks/test_failover.rake
|
|
64
65
|
- test/test_client.rb
|
|
66
|
+
- test/test_helper.rb
|
|
65
67
|
homepage: https://github.com/livingsocial/klomp
|
|
66
68
|
licenses: []
|
|
67
69
|
post_install_message:
|
|
@@ -74,6 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
74
76
|
- - ! '>='
|
|
75
77
|
- !ruby/object:Gem::Version
|
|
76
78
|
version: '0'
|
|
79
|
+
segments:
|
|
80
|
+
- 0
|
|
81
|
+
hash: -1591973809162906904
|
|
77
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
83
|
none: false
|
|
79
84
|
requirements:
|
|
@@ -88,3 +93,4 @@ specification_version: 3
|
|
|
88
93
|
summary: A simple wrapper around the OnStomp library with additional features
|
|
89
94
|
test_files:
|
|
90
95
|
- test/test_client.rb
|
|
96
|
+
- test/test_helper.rb
|