stomp 1.1.10 → 1.2.0
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/CHANGELOG.rdoc +17 -0
- data/README.rdoc +11 -3
- data/Rakefile +2 -2
- data/bin/catstomp +3 -3
- data/examples/client11_ex1.rb +78 -0
- data/examples/client11_putget1.rb +57 -0
- data/examples/conn11_ex1.rb +101 -0
- data/examples/conn11_ex2.rb +75 -0
- data/examples/conn11_hb1.rb +46 -0
- data/examples/consumer.rb +2 -0
- data/examples/get11conn_ex1.rb +107 -0
- data/examples/get11conn_ex2.rb +67 -0
- data/examples/logexamp.rb +18 -2
- data/examples/publisher.rb +2 -0
- data/examples/put11conn_ex1.rb +43 -0
- data/examples/putget11_rh1.rb +81 -0
- data/examples/slogger.rb +79 -1
- data/examples/stomp11_common.rb +45 -0
- data/examples/topic_consumer.rb +19 -0
- data/examples/topic_publisher.rb +15 -0
- data/lib/stomp.rb +4 -0
- data/lib/stomp/client.rb +36 -4
- data/lib/stomp/codec.rb +41 -0
- data/lib/stomp/connection.rb +623 -29
- data/lib/stomp/constants.rb +78 -0
- data/lib/stomp/errors.rb +60 -2
- data/lib/stomp/ext/hash.rb +3 -1
- data/lib/stomp/message.rb +32 -3
- data/lib/stomp/version.rb +4 -2
- data/spec/client_shared_examples.rb +2 -0
- data/spec/client_spec.rb +2 -0
- data/spec/connection_spec.rb +30 -9
- data/spec/message_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/stomp.gemspec +25 -24
- data/test/test_client.rb +152 -44
- data/test/test_codec.rb +83 -0
- data/test/test_connection.rb +138 -25
- data/test/test_connection1p.rb +251 -0
- data/test/test_helper.rb +48 -0
- data/test/test_message.rb +69 -19
- data/test/tlogger.rb +155 -0
- metadata +52 -69
@@ -0,0 +1,78 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Stomp
|
4
|
+
|
5
|
+
# Client side
|
6
|
+
CMD_CONNECT = "CONNECT"
|
7
|
+
CMD_STOMP = "STOMP"
|
8
|
+
CMD_DISCONNECT = "DISCONNECT"
|
9
|
+
CMD_SEND = "SEND"
|
10
|
+
CMD_SUBSCRIBE = "SUBSCRIBE"
|
11
|
+
CMD_UNSUBSCRIBE = "UNSUBSCRIBE"
|
12
|
+
CMD_ACK = "ACK"
|
13
|
+
CMD_NACK = "NACK"
|
14
|
+
CMD_BEGIN = "BEGIN"
|
15
|
+
CMD_COMMIT = "COMMIT"
|
16
|
+
CMD_ABORT = "ABORT"
|
17
|
+
|
18
|
+
# Server side
|
19
|
+
CMD_CONNECTED = "CONNECTED"
|
20
|
+
CMD_MESSAGE = "MESSAGE"
|
21
|
+
CMD_RECEIPT = "RECEIPT"
|
22
|
+
CMD_ERROR = "ERROR"
|
23
|
+
|
24
|
+
# Protocols
|
25
|
+
SPL_10 = "1.0"
|
26
|
+
SPL_11 = "1.1"
|
27
|
+
|
28
|
+
# To be: No 1.1 yet
|
29
|
+
SUPPORTED = [SPL_10, SPL_11]
|
30
|
+
|
31
|
+
# 1.9 Encoding Name
|
32
|
+
UTF8 = "UTF-8"
|
33
|
+
#
|
34
|
+
# Octet 0
|
35
|
+
#
|
36
|
+
NULL = "\0"
|
37
|
+
#
|
38
|
+
# New line
|
39
|
+
#
|
40
|
+
NL = "\n"
|
41
|
+
NL_ASCII = 0x0a
|
42
|
+
#
|
43
|
+
# Back Slash
|
44
|
+
#
|
45
|
+
BACK_SLASH = "\\"
|
46
|
+
BACK_SLASH_ASCII = 0x5c
|
47
|
+
#
|
48
|
+
# Literal colon
|
49
|
+
#
|
50
|
+
LITERAL_COLON = ":"
|
51
|
+
COLON_ASCII = 0x3a
|
52
|
+
#
|
53
|
+
# Literal letter c
|
54
|
+
#
|
55
|
+
LITERAL_C = "c"
|
56
|
+
C_ASCII = 0x63
|
57
|
+
#
|
58
|
+
# Literal letter n
|
59
|
+
#
|
60
|
+
LITERAL_N = "n"
|
61
|
+
N_ASCII = 0x6e
|
62
|
+
#
|
63
|
+
# Codec from/to values.
|
64
|
+
#
|
65
|
+
ENCODE_VALUES = [
|
66
|
+
"\\\\", "\\", # encoded, decoded
|
67
|
+
"\\" + "n", "\n",
|
68
|
+
"\\c", ":",
|
69
|
+
]
|
70
|
+
|
71
|
+
#
|
72
|
+
DECODE_VALUES = [
|
73
|
+
"\\\\\\\\", "\\", # encoded, decoded
|
74
|
+
"\\" + "n", "\n",
|
75
|
+
"\\c", ":",
|
76
|
+
]
|
77
|
+
|
78
|
+
end
|
data/lib/stomp/errors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
module Stomp
|
2
4
|
module Error
|
3
5
|
class InvalidFormat < RuntimeError
|
@@ -23,11 +25,67 @@ module Stomp
|
|
23
25
|
"Packet parsing timeout"
|
24
26
|
end
|
25
27
|
end
|
28
|
+
|
29
|
+
class SocketOpenTimeout < RuntimeError
|
30
|
+
def message
|
31
|
+
"Socket open timeout"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class NoCurrentConnection < RuntimeError
|
36
|
+
def message
|
37
|
+
"no current connection exists"
|
38
|
+
end
|
39
|
+
end
|
26
40
|
|
27
41
|
class MaxReconnectAttempts < RuntimeError
|
28
42
|
def message
|
29
43
|
"Maximum number of reconnection attempts reached"
|
30
44
|
end
|
31
45
|
end
|
32
|
-
|
33
|
-
|
46
|
+
|
47
|
+
class DuplicateSubscription < RuntimeError
|
48
|
+
def message
|
49
|
+
"duplicate subscriptions are disallowed"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class ProtocolErrorConnect < RuntimeError
|
54
|
+
def message
|
55
|
+
"protocol error on CONNECT"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class UnsupportedProtocolError < RuntimeError
|
60
|
+
def message
|
61
|
+
"unsupported protocol level(s)"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class InvalidHeartBeatHeaderError < RuntimeError
|
66
|
+
def message
|
67
|
+
"heart-beat header value is malformed"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class SubscriptionRequiredError < RuntimeError
|
72
|
+
def message
|
73
|
+
"a valid subscription id header is required"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class UTF8ValidationError < RuntimeError
|
78
|
+
def message
|
79
|
+
"header is invalid UTF8"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class MessageIDRequiredError < RuntimeError
|
84
|
+
def message
|
85
|
+
"a valid message id is required for ACK/NACK"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end # module Error
|
90
|
+
end # module Stomp
|
91
|
+
|
data/lib/stomp/ext/hash.rb
CHANGED
data/lib/stomp/message.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
module Stomp
|
2
4
|
|
3
5
|
# Container class for frames, misnamed technically
|
@@ -6,8 +8,8 @@ module Stomp
|
|
6
8
|
|
7
9
|
@@allowed_commands = [ 'CONNECTED', 'MESSAGE', 'RECEIPT', 'ERROR' ]
|
8
10
|
|
9
|
-
def initialize(frame)
|
10
|
-
# p frame
|
11
|
+
def initialize(frame, protocol11p = false)
|
12
|
+
# p [ "00", frame, frame.encoding ]
|
11
13
|
# Set default empty values
|
12
14
|
self.command = ''
|
13
15
|
self.headers = {}
|
@@ -34,11 +36,38 @@ module Stomp
|
|
34
36
|
work_body = frame[headers_index+2..lastnull_index-1]
|
35
37
|
raise Stomp::Error::InvalidFormat, 'nil body' unless work_body
|
36
38
|
# Set the frame values
|
39
|
+
if protocol11p
|
40
|
+
work_command.force_encoding(Stomp::UTF8) if work_command.respond_to?(:force_encoding)
|
41
|
+
end
|
37
42
|
self.command = work_command
|
38
43
|
work_headers.split("\n").map do |value|
|
39
44
|
parsed_value = value.match /^([\w|-]*):(.*)$/
|
40
45
|
raise Stomp::Error::InvalidFormat, 'parsed header value' unless parsed_value
|
41
|
-
|
46
|
+
#
|
47
|
+
pk = parsed_value[1]
|
48
|
+
pv = parsed_value[2]
|
49
|
+
#
|
50
|
+
if protocol11p
|
51
|
+
pk.force_encoding(Stomp::UTF8) if pk.respond_to?(:force_encoding)
|
52
|
+
pv.force_encoding(Stomp::UTF8) if pv.respond_to?(:force_encoding)
|
53
|
+
# Stomp 1.1+ - Servers may put multiple values for a single key on the wire.
|
54
|
+
# If so, we support reading those, and passing them to the user.
|
55
|
+
if self.headers[pk]
|
56
|
+
if self.headers[pk].is_a?(Array) # The 3rd and any subsequent ones for this key
|
57
|
+
self.headers[pk] << pv
|
58
|
+
else
|
59
|
+
# The 2nd one for this key
|
60
|
+
tv = self.headers[pk] + ""
|
61
|
+
self.headers[pk] = []
|
62
|
+
self.headers[pk] << tv << pv
|
63
|
+
end
|
64
|
+
else
|
65
|
+
self.headers[pk] = pv # The 1st one for this key
|
66
|
+
end
|
67
|
+
else
|
68
|
+
# Stomp 1.0
|
69
|
+
self.headers[pk.strip] = pv.strip unless self.headers[pk.strip] # Only receive the 1st one
|
70
|
+
end
|
42
71
|
end
|
43
72
|
|
44
73
|
body_length = -1
|
data/lib/stomp/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# encoding:
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Stomp::Connection do
|
@@ -9,6 +10,7 @@ describe Stomp::Connection do
|
|
9
10
|
{:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false},
|
10
11
|
{:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false}
|
11
12
|
],
|
13
|
+
:reliable => true,
|
12
14
|
:initial_reconnect_delay => 0.01,
|
13
15
|
:max_reconnect_delay => 30.0,
|
14
16
|
:use_exponential_back_off => true,
|
@@ -16,7 +18,7 @@ describe Stomp::Connection do
|
|
16
18
|
:max_reconnect_attempts => 0,
|
17
19
|
:randomize => false,
|
18
20
|
:backup => false,
|
19
|
-
:
|
21
|
+
:connect_timeout => 0,
|
20
22
|
:parse_timeout => 5,
|
21
23
|
:connect_headers => {}
|
22
24
|
}
|
@@ -42,6 +44,7 @@ describe Stomp::Connection do
|
|
42
44
|
{:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false},
|
43
45
|
{:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false}
|
44
46
|
],
|
47
|
+
"reliable" => true,
|
45
48
|
"initialReconnectDelay" => 0.01,
|
46
49
|
"maxReconnectDelay" => 30.0,
|
47
50
|
"useExponentialBackOff" => true,
|
@@ -49,17 +52,14 @@ describe Stomp::Connection do
|
|
49
52
|
"maxReconnectAttempts" => 0,
|
50
53
|
"randomize" => false,
|
51
54
|
"backup" => false,
|
52
|
-
"
|
55
|
+
"connect_timeout" => 0,
|
53
56
|
"parse_timeout" => 5,
|
54
57
|
}
|
55
58
|
|
56
59
|
@connection = Stomp::Connection.new(used_hash)
|
57
60
|
@connection.instance_variable_get(:@parameters).should == @parameters
|
58
61
|
end
|
59
|
-
|
60
|
-
it "should be reliable" do
|
61
|
-
@connection.instance_variable_get(:@reliable).should be_true
|
62
|
-
end
|
62
|
+
|
63
63
|
it "should start with first host in array" do
|
64
64
|
@connection.instance_variable_get(:@host).should == "localhost"
|
65
65
|
end
|
@@ -74,6 +74,25 @@ describe Stomp::Connection do
|
|
74
74
|
@connection = Stomp::Connection.new hash
|
75
75
|
@connection.instance_variable_get(:@port).should == 61613
|
76
76
|
end
|
77
|
+
|
78
|
+
context "should be able pass reliable as part of hash" do
|
79
|
+
it "should be false if reliable is set to false" do
|
80
|
+
hash = @parameters.merge({:reliable => false })
|
81
|
+
connection = Stomp::Connection.new(hash)
|
82
|
+
connection.instance_variable_get(:@reliable).should be_false
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be true if reliable is set to true" do
|
86
|
+
hash = @parameters.merge({:reliable => true })
|
87
|
+
connection = Stomp::Connection.new(hash)
|
88
|
+
connection.instance_variable_get(:@reliable).should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should be true if reliable is not set" do
|
92
|
+
connection = Stomp::Connection.new(@parameters)
|
93
|
+
connection.instance_variable_get(:@reliable).should be_true
|
94
|
+
end
|
95
|
+
end
|
77
96
|
|
78
97
|
context "when dealing with content-length header" do
|
79
98
|
it "should not suppress it when receiving :suppress_content_length => false" do
|
@@ -269,6 +288,7 @@ describe Stomp::Connection do
|
|
269
288
|
# Once connected the host is sent to the end of array
|
270
289
|
{:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false}
|
271
290
|
],
|
291
|
+
:reliable => true,
|
272
292
|
:initial_reconnect_delay => 0.01,
|
273
293
|
:max_reconnect_delay => 30.0,
|
274
294
|
:use_exponential_back_off => true,
|
@@ -276,7 +296,7 @@ describe Stomp::Connection do
|
|
276
296
|
:max_reconnect_attempts => 0,
|
277
297
|
:randomize => false,
|
278
298
|
:backup => false,
|
279
|
-
:
|
299
|
+
:connect_timeout => 0,
|
280
300
|
:parse_timeout => 5,
|
281
301
|
:connect_headers => {}
|
282
302
|
}
|
@@ -305,7 +325,8 @@ describe Stomp::Connection do
|
|
305
325
|
:max_reconnect_attempts => 10,
|
306
326
|
:randomize => true,
|
307
327
|
:backup => false,
|
308
|
-
:
|
328
|
+
:reliable => false,
|
329
|
+
:connect_timeout => 0,
|
309
330
|
:parse_timeout => 20,
|
310
331
|
:connect_headers => {:lerolero => "ronaldo"},
|
311
332
|
:dead_letter_queue => "queue/Error",
|
data/spec/message_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/stomp.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.
|
7
|
+
s.name = "stomp"
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
12
|
+
s.date = "2011-12-15"
|
13
|
+
s.description = "Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge."
|
14
14
|
s.email = ["brianm@apache.org", "marius@stones.com", "morellon@gmail.com", "allard.guy.m@gmail.com"]
|
15
15
|
s.executables = ["catstomp", "stompcat"]
|
16
16
|
s.extra_rdoc_files = [
|
@@ -24,13 +24,27 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"bin/catstomp",
|
26
26
|
"bin/stompcat",
|
27
|
+
"examples/client11_ex1.rb",
|
28
|
+
"examples/client11_putget1.rb",
|
29
|
+
"examples/conn11_ex1.rb",
|
30
|
+
"examples/conn11_ex2.rb",
|
31
|
+
"examples/conn11_hb1.rb",
|
27
32
|
"examples/consumer.rb",
|
33
|
+
"examples/get11conn_ex1.rb",
|
34
|
+
"examples/get11conn_ex2.rb",
|
28
35
|
"examples/logexamp.rb",
|
29
36
|
"examples/publisher.rb",
|
37
|
+
"examples/put11conn_ex1.rb",
|
38
|
+
"examples/putget11_rh1.rb",
|
30
39
|
"examples/slogger.rb",
|
40
|
+
"examples/stomp11_common.rb",
|
41
|
+
"examples/topic_consumer.rb",
|
42
|
+
"examples/topic_publisher.rb",
|
31
43
|
"lib/stomp.rb",
|
32
44
|
"lib/stomp/client.rb",
|
45
|
+
"lib/stomp/codec.rb",
|
33
46
|
"lib/stomp/connection.rb",
|
47
|
+
"lib/stomp/constants.rb",
|
34
48
|
"lib/stomp/errors.rb",
|
35
49
|
"lib/stomp/ext/hash.rb",
|
36
50
|
"lib/stomp/message.rb",
|
@@ -42,32 +56,19 @@ Gem::Specification.new do |s|
|
|
42
56
|
"spec/spec_helper.rb",
|
43
57
|
"stomp.gemspec",
|
44
58
|
"test/test_client.rb",
|
59
|
+
"test/test_codec.rb",
|
45
60
|
"test/test_connection.rb",
|
61
|
+
"test/test_connection1p.rb",
|
46
62
|
"test/test_helper.rb",
|
47
|
-
"test/test_message.rb"
|
63
|
+
"test/test_message.rb",
|
64
|
+
"test/tlogger.rb"
|
48
65
|
]
|
49
|
-
s.homepage =
|
66
|
+
s.homepage = "https://github.com/morellon/stomp"
|
50
67
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version =
|
52
|
-
s.summary =
|
53
|
-
s.test_files = [
|
54
|
-
"examples/consumer.rb",
|
55
|
-
"examples/logexamp.rb",
|
56
|
-
"examples/publisher.rb",
|
57
|
-
"examples/slogger.rb",
|
58
|
-
"spec/client_shared_examples.rb",
|
59
|
-
"spec/client_spec.rb",
|
60
|
-
"spec/connection_spec.rb",
|
61
|
-
"spec/message_spec.rb",
|
62
|
-
"spec/spec_helper.rb",
|
63
|
-
"test/test_client.rb",
|
64
|
-
"test/test_connection.rb",
|
65
|
-
"test/test_helper.rb",
|
66
|
-
"test/test_message.rb"
|
67
|
-
]
|
68
|
+
s.rubygems_version = "1.8.11"
|
69
|
+
s.summary = "Ruby client for the Stomp messaging protocol"
|
68
70
|
|
69
71
|
if s.respond_to? :specification_version then
|
70
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
72
|
s.specification_version = 3
|
72
73
|
|
73
74
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|