stomp 1.2.3 → 1.2.4
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 +8 -0
- data/README.rdoc +2 -0
- data/examples/client11_ex1.rb +10 -8
- data/examples/client11_putget1.rb +4 -2
- data/examples/conn11_ex1.rb +9 -6
- data/examples/conn11_ex2.rb +3 -0
- data/examples/conn11_hb1.rb +8 -6
- data/examples/get11conn_ex1.rb +3 -1
- data/examples/get11conn_ex2.rb +2 -0
- data/examples/logexamp.rb +3 -2
- data/examples/logexamp_ssl.rb +3 -2
- data/examples/put11conn_ex1.rb +2 -0
- data/examples/putget11_rh1.rb +2 -0
- data/examples/ssl_uc1.rb +2 -0
- data/examples/ssl_uc1_ciphers.rb +2 -0
- data/examples/ssl_uc2.rb +2 -0
- data/examples/ssl_uc2_ciphers.rb +2 -0
- data/examples/ssl_uc3.rb +2 -0
- data/examples/ssl_uc3_ciphers.rb +2 -0
- data/examples/ssl_uc4.rb +2 -0
- data/examples/ssl_uc4_ciphers.rb +2 -0
- data/examples/ssl_ucx_default_ciphers.rb +2 -0
- data/examples/stomp11_common.rb +2 -0
- data/lib/stomp/client.rb +30 -2
- data/lib/stomp/connection.rb +58 -16
- data/lib/stomp/version.rb +1 -1
- data/spec/client_spec.rb +18 -1
- data/spec/connection_spec.rb +37 -4
- data/stomp.gemspec +2 -2
- data/test/test_client.rb +5 -5
- data/test/test_connection.rb +1 -1
- data/test/test_connection1p.rb +89 -2
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.2.4 20120625
|
2
|
+
|
3
|
+
* Add ability for client to request flush on write to the connection (Issue #45)
|
4
|
+
* Add ability for client to retrieve heartbeat intervals and counters
|
5
|
+
* Fix I/O errors with heartbeats and multithreaded clients (Issue #46)
|
6
|
+
* Enhance tests for heartbeats
|
7
|
+
* Correct typos and clarify comments in many examples
|
8
|
+
|
1
9
|
== 1.2.3 20120616
|
2
10
|
|
3
11
|
* Fix UnsupportedProtocol on connect to a 1.0 broker
|
data/README.rdoc
CHANGED
@@ -10,6 +10,7 @@ An implementation of the Stomp protocol for Ruby. See:
|
|
10
10
|
|
11
11
|
===New
|
12
12
|
|
13
|
+
* Gem version 1.2.2. Stomp 1.1 heartbeat fix, autoflush capability, miscellaneous fixes
|
13
14
|
* Gem version 1.2.3. Miscellaneous fixes, see changelog for details.
|
14
15
|
* Gem version 1.2.2. Performance and more SSL enhancements.
|
15
16
|
* Full support of SSL certificates is announced as of gem version 1.2.1.
|
@@ -106,4 +107,5 @@ The following people have contributed to Stomp:
|
|
106
107
|
* James Pearson
|
107
108
|
* Craig
|
108
109
|
* Tommy Bishop
|
110
|
+
* Jeremy Gailor
|
109
111
|
|
data/examples/client11_ex1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -13,11 +15,11 @@ include Stomp11Common
|
|
13
15
|
# Stomp 1.1 Client Example 1
|
14
16
|
# ==============================
|
15
17
|
#
|
16
|
-
# Purpose: to demonstrate a
|
17
|
-
# with the Stomp#
|
18
|
+
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1
|
19
|
+
# with the Stomp#Client interface.
|
18
20
|
#
|
19
|
-
# Note: Stomp#
|
20
|
-
# contain a '
|
21
|
+
# Note: Stomp#Client does not provide a positional set of parameters that
|
22
|
+
# contain a 'connect_headers' parameter. To use the Stomp#Client interface
|
21
23
|
# you _must_ use a 'hashed' set of parameters.
|
22
24
|
#
|
23
25
|
# Create connection headers
|
@@ -26,8 +28,8 @@ include Stomp11Common
|
|
26
28
|
# The two headers used here are _required_ by the specification.
|
27
29
|
#
|
28
30
|
client_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
|
29
|
-
"host" => virt_host,
|
30
|
-
}
|
31
|
+
"host" => virt_host, # The 1.1 vhost (could be different than connection host)
|
32
|
+
} # No heartbeats here: there will be none for this connection
|
31
33
|
#
|
32
34
|
# Create the connect hash.
|
33
35
|
# ========================
|
@@ -42,7 +44,7 @@ client_hash = { :hosts => [
|
|
42
44
|
# ================
|
43
45
|
#
|
44
46
|
client = Stomp::Client.new(client_hash)
|
45
|
-
puts "
|
47
|
+
puts "Client Connect complete"
|
46
48
|
#
|
47
49
|
# Let's just do some sanity checks, and look around.
|
48
50
|
#
|
@@ -72,7 +74,7 @@ puts "Server requested heartbeats - \t#{client.connection_frame().headers['heart
|
|
72
74
|
# =============
|
73
75
|
#
|
74
76
|
client.close # Business as usual, just like 1.0
|
75
|
-
puts "
|
77
|
+
puts "Client close complete"
|
76
78
|
|
77
79
|
|
78
80
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -26,7 +28,7 @@ client_hash = { :hosts => [
|
|
26
28
|
}
|
27
29
|
#
|
28
30
|
client = Stomp::Client.new(client_hash)
|
29
|
-
puts "
|
31
|
+
puts "Client Connect complete"
|
30
32
|
#
|
31
33
|
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
|
32
34
|
#
|
@@ -51,7 +53,7 @@ raise "Unexpected data" if data != message.body
|
|
51
53
|
raise "Bad subscription header" if uuid != message.headers['subscription']
|
52
54
|
#
|
53
55
|
client.close # Business as usual, just like 1.0
|
54
|
-
puts "
|
56
|
+
puts "Client close complete"
|
55
57
|
|
56
58
|
|
57
59
|
|
data/examples/conn11_ex1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -15,7 +17,7 @@ include Stomp11Common
|
|
15
17
|
#
|
16
18
|
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1.
|
17
19
|
#
|
18
|
-
# Note: this example assumes that you have at least the 1.
|
20
|
+
# Note: this example assumes that you have at least the 1.2.0 gem release
|
19
21
|
# installed.
|
20
22
|
#
|
21
23
|
# When you:
|
@@ -45,8 +47,9 @@ include Stomp11Common
|
|
45
47
|
#
|
46
48
|
# * heartbeat request
|
47
49
|
#
|
48
|
-
# Using the stomp gem, you specify this data in the "connect_headers" Hash
|
49
|
-
# parameter.
|
50
|
+
# Using the stomp gem, you can specify this data in the "connect_headers" Hash
|
51
|
+
# parameter or a paramaterized connection request. This example uses a
|
52
|
+
# parameterized request.
|
50
53
|
#
|
51
54
|
# So .........
|
52
55
|
#
|
@@ -63,10 +66,10 @@ conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV
|
|
63
66
|
# ================
|
64
67
|
#
|
65
68
|
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
|
66
|
-
false, # Not reliable, the default
|
69
|
+
false, # Not reliable, the default for a parameter connection
|
67
70
|
5, # Connect redelay, the default
|
68
71
|
conn_hdrs) # The 1.1 connection parameters
|
69
|
-
puts "Connection complete"
|
72
|
+
puts "Connection connect complete"
|
70
73
|
#
|
71
74
|
# Let's just do some sanity checks, and look around.
|
72
75
|
#
|
@@ -95,7 +98,7 @@ puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-bea
|
|
95
98
|
# ==================
|
96
99
|
#
|
97
100
|
conn.disconnect # Business as usual, just like 1.0
|
98
|
-
puts "
|
101
|
+
puts "Connection disconnect complete"
|
99
102
|
|
100
103
|
|
101
104
|
|
data/examples/conn11_ex2.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -33,6 +35,7 @@ conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV
|
|
33
35
|
conn_hash = { :hosts => [
|
34
36
|
{:login => login, :passcode => passcode, :host => host, :port => port},
|
35
37
|
],
|
38
|
+
:reliable => false, # Override default
|
36
39
|
:connect_headers => conn_hdrs,
|
37
40
|
}
|
38
41
|
#
|
data/examples/conn11_hb1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -26,12 +28,12 @@ conn_hdrs = {"accept-version" => "1.1", # 1.1
|
|
26
28
|
}
|
27
29
|
# Create a logger for demonstration purposes
|
28
30
|
logger = Slogger.new
|
29
|
-
# Connect
|
31
|
+
# Connect - a paramaterized request.
|
30
32
|
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
|
31
|
-
false, # Not reliable, the default
|
32
|
-
5, # Connect redelay, the default
|
33
|
-
conn_hdrs) # The 1.1 connection parameters
|
34
|
-
puts "Connection complete"
|
33
|
+
false, # Not reliable, the default for a paramaterized connection
|
34
|
+
5, # Connect redelay, the default for a paramaterized connection
|
35
|
+
conn_hdrs) # The 1.1 connection parameters / headers
|
36
|
+
puts "Connection connect complete"
|
35
37
|
#
|
36
38
|
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
37
39
|
#
|
@@ -40,7 +42,7 @@ sleep 65
|
|
40
42
|
conn.set_logger(nil) # No logging
|
41
43
|
#
|
42
44
|
conn.disconnect # Get out
|
43
|
-
puts "
|
45
|
+
puts "Connection disconnect complete"
|
44
46
|
|
45
47
|
|
46
48
|
|
data/examples/get11conn_ex1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
#
|
2
4
|
# The current require dance for different Ruby versions.
|
3
5
|
# Change this to suit your requirements.
|
@@ -26,7 +28,7 @@ raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
|
26
28
|
# * for subscribe, the 'id' header is now _required_
|
27
29
|
# * for unsubscribe, the 'id' header is now _required_
|
28
30
|
#
|
29
|
-
# The 'id' header specifies a 'subscription id' that
|
31
|
+
# The 'id' header specifies a 'subscription id' that _must_ be unique for
|
30
32
|
# the current session.
|
31
33
|
#
|
32
34
|
qname = "/queue/nodea.nodeb.nodec"
|
data/examples/get11conn_ex2.rb
CHANGED
data/examples/logexamp.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'stomp'
|
3
5
|
require 'logger' # for the 'local' logger
|
@@ -6,7 +8,7 @@ $:.unshift(File.dirname(__FILE__))
|
|
6
8
|
#
|
7
9
|
require 'slogger'
|
8
10
|
#
|
9
|
-
# A STOMP
|
11
|
+
# A STOMP::Connection program which uses the callback logging facility.
|
10
12
|
#
|
11
13
|
llog = Logger::new(STDOUT)
|
12
14
|
llog.level = Logger::DEBUG
|
@@ -14,7 +16,6 @@ llog.debug "LE Starting"
|
|
14
16
|
|
15
17
|
# //////////////////////////////////////////////////////////////////////////////
|
16
18
|
mylog = Slogger::new # The client provided STOMP callback logger
|
17
|
-
# -*- encoding: utf-8 -*-
|
18
19
|
|
19
20
|
# //////////////////////////////////////////////////////////////////////////////
|
20
21
|
user = ENV['STOMP_USER'] ? ENV['STOMP_USER'] : 'guest'
|
data/examples/logexamp_ssl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'stomp'
|
3
5
|
require 'logger' # for the 'local' logger
|
@@ -6,7 +8,7 @@ $:.unshift(File.dirname(__FILE__))
|
|
6
8
|
#
|
7
9
|
require 'slogger'
|
8
10
|
#
|
9
|
-
# A STOMP
|
11
|
+
# A STOMP::Connection program which uses the callback logging facility.
|
10
12
|
#
|
11
13
|
llog = Logger::new(STDOUT)
|
12
14
|
llog.level = Logger::DEBUG
|
@@ -14,7 +16,6 @@ llog.debug "LESSL Starting"
|
|
14
16
|
|
15
17
|
# //////////////////////////////////////////////////////////////////////////////
|
16
18
|
mylog = Slogger::new # The client provided STOMP callback logger
|
17
|
-
# -*- encoding: utf-8 -*-
|
18
19
|
|
19
20
|
# //////////////////////////////////////////////////////////////////////////////
|
20
21
|
user = ENV['STOMP_USER'] ? ENV['STOMP_USER'] : 'guest'
|
data/examples/put11conn_ex1.rb
CHANGED
data/examples/putget11_rh1.rb
CHANGED
data/examples/ssl_uc1.rb
CHANGED
data/examples/ssl_uc1_ciphers.rb
CHANGED
data/examples/ssl_uc2.rb
CHANGED
data/examples/ssl_uc2_ciphers.rb
CHANGED
data/examples/ssl_uc3.rb
CHANGED
data/examples/ssl_uc3_ciphers.rb
CHANGED
data/examples/ssl_uc4.rb
CHANGED
data/examples/ssl_uc4_ciphers.rb
CHANGED
data/examples/stomp11_common.rb
CHANGED
data/lib/stomp/client.rb
CHANGED
@@ -35,7 +35,7 @@ module Stomp
|
|
35
35
|
# stomp://login:passcode@host:port
|
36
36
|
# stomp://login:passcode@host.domain.tld:port
|
37
37
|
#
|
38
|
-
def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
|
38
|
+
def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, autoflush = false)
|
39
39
|
|
40
40
|
# Parse stomp:// URL's or set params
|
41
41
|
if login.is_a?(Hash)
|
@@ -49,7 +49,6 @@ module Stomp
|
|
49
49
|
@port = first_host[:port] || Connection::default_port(first_host[:ssl])
|
50
50
|
|
51
51
|
@reliable = true
|
52
|
-
|
53
52
|
elsif login =~ /^stomp:\/\/#{url_regex}/ # e.g. stomp://login:passcode@host:port or stomp://host:port
|
54
53
|
@login = $2 || ""
|
55
54
|
@passcode = $3 || ""
|
@@ -94,6 +93,7 @@ module Stomp
|
|
94
93
|
@connection = Connection.new(@parameters)
|
95
94
|
else
|
96
95
|
@connection = Connection.new(@login, @passcode, @host, @port, @reliable)
|
96
|
+
@connection.autoflush = autoflush
|
97
97
|
end
|
98
98
|
|
99
99
|
start_listeners
|
@@ -265,12 +265,40 @@ module Stomp
|
|
265
265
|
@connection.uuid()
|
266
266
|
end
|
267
267
|
|
268
|
+
# Retrieve heartbeat send interval
|
269
|
+
def hbsend_interval
|
270
|
+
@connection.hbsend_interval
|
271
|
+
end
|
272
|
+
|
273
|
+
# Retrieve heartbeat receive interval
|
274
|
+
def hbrecv_interval
|
275
|
+
@connection.hbrecv_interval
|
276
|
+
end
|
277
|
+
|
278
|
+
# Retrieve heartbeat send count
|
279
|
+
def hbsend_count
|
280
|
+
@connection.hbsend_count
|
281
|
+
end
|
282
|
+
|
283
|
+
# Retrieve heartbeat receive count
|
284
|
+
def hbrecv_count
|
285
|
+
@connection.hbrecv_count
|
286
|
+
end
|
287
|
+
|
268
288
|
# Poll for asynchronous messages issued by broker.
|
269
289
|
# Return nil of no message available, else the message
|
270
290
|
def poll
|
271
291
|
@connection.poll
|
272
292
|
end
|
273
293
|
|
294
|
+
def autoflush=(af)
|
295
|
+
@connection.autoflush = af
|
296
|
+
end
|
297
|
+
|
298
|
+
def autoflush
|
299
|
+
@connection.autoflush
|
300
|
+
end
|
301
|
+
|
274
302
|
private
|
275
303
|
# Set a subscription id in the headers hash if one does not already exist.
|
276
304
|
# For simplicities sake, all subscriptions have a subscription ID.
|
data/lib/stomp/connection.rb
CHANGED
@@ -10,12 +10,13 @@ module Stomp
|
|
10
10
|
# Low level connection which maps commands and supports
|
11
11
|
# synchronous receives
|
12
12
|
class Connection
|
13
|
-
attr_reader
|
14
|
-
attr_reader
|
15
|
-
attr_reader
|
16
|
-
attr_reader
|
17
|
-
attr_reader
|
18
|
-
attr_reader
|
13
|
+
attr_reader :connection_frame
|
14
|
+
attr_reader :disconnect_receipt
|
15
|
+
attr_reader :protocol
|
16
|
+
attr_reader :session
|
17
|
+
attr_reader :hb_received # Heartbeat received on time
|
18
|
+
attr_reader :hb_sent # Heartbeat sent successfully
|
19
|
+
attr_accessor :autoflush
|
19
20
|
#alias :obj_send :send
|
20
21
|
|
21
22
|
def self.default_port(ssl)
|
@@ -87,6 +88,7 @@ module Stomp
|
|
87
88
|
@parse_timeout = 5 # To override, use hashed parameters
|
88
89
|
@connect_timeout = 0 # To override, use hashed parameters
|
89
90
|
@logger = nil # To override, use hashed parameters
|
91
|
+
@autoflush = false # To override, use hashed parameters or setter
|
90
92
|
warn "login looks like a URL, do you have the correct parameters?" if @login =~ /:\/\//
|
91
93
|
end
|
92
94
|
|
@@ -112,6 +114,7 @@ module Stomp
|
|
112
114
|
@parse_timeout = @parameters[:parse_timeout]
|
113
115
|
@connect_timeout = @parameters[:connect_timeout]
|
114
116
|
@logger = @parameters[:logger]
|
117
|
+
@autoflush = @parameters[:autoflush]
|
115
118
|
#sets the first host to connect
|
116
119
|
change_host
|
117
120
|
end
|
@@ -488,6 +491,30 @@ module Stomp
|
|
488
491
|
rs
|
489
492
|
end
|
490
493
|
|
494
|
+
# Retrieve heartbeat send interval
|
495
|
+
def hbsend_interval
|
496
|
+
return 0 unless @hbsend_interval
|
497
|
+
@hbsend_interval / 1000.0 # ms
|
498
|
+
end
|
499
|
+
|
500
|
+
# Retrieve heartbeat receive interval
|
501
|
+
def hbrecv_interval
|
502
|
+
return 0 unless @hbrecv_interval
|
503
|
+
@hbrecv_interval / 1000.0 # ms
|
504
|
+
end
|
505
|
+
|
506
|
+
# Retrieve heartbeat send count
|
507
|
+
def hbsend_count
|
508
|
+
return 0 unless @hbsend_count
|
509
|
+
@hbsend_count
|
510
|
+
end
|
511
|
+
|
512
|
+
# Retrieve heartbeat receive count
|
513
|
+
def hbrecv_count
|
514
|
+
return 0 unless @hbrecv_count
|
515
|
+
@hbrecv_count
|
516
|
+
end
|
517
|
+
|
491
518
|
private
|
492
519
|
|
493
520
|
def _expand_hosts(hash)
|
@@ -516,7 +543,17 @@ module Stomp
|
|
516
543
|
|
517
544
|
def _receive( read_socket )
|
518
545
|
@read_semaphore.synchronize do
|
519
|
-
line =
|
546
|
+
line = ''
|
547
|
+
if @protocol == Stomp::SPL_10 || (@protocol >= Stomp::SPL_11 && !@hbr)
|
548
|
+
line = read_socket.gets # The old way
|
549
|
+
else # We are >= 1.1 and receiving heartbeats.
|
550
|
+
while true
|
551
|
+
line = read_socket.gets # Data from wire
|
552
|
+
break unless line == "\n"
|
553
|
+
line = ''
|
554
|
+
@lr = Time.now.to_f
|
555
|
+
end
|
556
|
+
end
|
520
557
|
return nil if line.nil?
|
521
558
|
# If the reading hangs for more than X seconds, abort the parsing process.
|
522
559
|
# X defaults to 5. Override allowed in connection hash parameters.
|
@@ -638,6 +675,7 @@ module Stomp
|
|
638
675
|
used_socket.puts
|
639
676
|
used_socket.write body
|
640
677
|
used_socket.write "\0"
|
678
|
+
used_socket.flush if autoflush
|
641
679
|
|
642
680
|
if @protocol >= Stomp::SPL_11
|
643
681
|
@ls = Time.now.to_f if @hbs
|
@@ -870,7 +908,9 @@ module Stomp
|
|
870
908
|
#
|
871
909
|
@cx = @cy = @sx = @sy = 0, # Variable names as in spec
|
872
910
|
#
|
873
|
-
@
|
911
|
+
@hbsend_interval = @hbrecv_interval = 0.0 # Send/Receive ticker interval.
|
912
|
+
#
|
913
|
+
@hbsend_count = @hbrecv_count = 0 # Send/Receive ticker counts.
|
874
914
|
#
|
875
915
|
@ls = @lr = -1.0 # Last send/receive time (from Time.now.to_f)
|
876
916
|
#
|
@@ -899,7 +939,7 @@ module Stomp
|
|
899
939
|
# If sending
|
900
940
|
if @hbs
|
901
941
|
sm = @cx >= @sy ? @cx : @sy # ticker interval, ms
|
902
|
-
@
|
942
|
+
@hbsend_interval = 1000.0 * sm # ticker interval, μs
|
903
943
|
@ls = Time.now.to_f # best guess at start
|
904
944
|
_start_send_ticker
|
905
945
|
end
|
@@ -907,7 +947,7 @@ module Stomp
|
|
907
947
|
# If receiving
|
908
948
|
if @hbr
|
909
949
|
rm = @sx >= @cy ? @sx : @cy # ticker interval, ms
|
910
|
-
@
|
950
|
+
@hbrecv_interval = 1000.0 * rm # ticker interval, μs
|
911
951
|
@lr = Time.now.to_f # best guess at start
|
912
952
|
_start_receive_ticker
|
913
953
|
end
|
@@ -915,7 +955,7 @@ module Stomp
|
|
915
955
|
end
|
916
956
|
|
917
957
|
def _start_send_ticker
|
918
|
-
sleeptime = @
|
958
|
+
sleeptime = @hbsend_interval / 1000000.0 # Sleep time secs
|
919
959
|
@st = Thread.new {
|
920
960
|
while true do
|
921
961
|
sleep sleeptime
|
@@ -924,7 +964,7 @@ module Stomp
|
|
924
964
|
@logger.on_hbfire(log_params, "send_fire", curt)
|
925
965
|
end
|
926
966
|
delta = curt - @ls
|
927
|
-
if delta > (@
|
967
|
+
if delta > (@hbsend_interval - (@hbsend_interval/5.0)) / 1000000.0 # Be tolerant (minus)
|
928
968
|
if @logger && @logger.respond_to?(:on_hbfire)
|
929
969
|
@logger.on_hbfire(log_params, "send_heartbeat", curt)
|
930
970
|
end
|
@@ -934,10 +974,11 @@ module Stomp
|
|
934
974
|
@socket.puts
|
935
975
|
@ls = curt # Update last send
|
936
976
|
@hb_sent = true # Reset if necessary
|
977
|
+
@hbsend_count += 1
|
937
978
|
rescue Exception => sendex
|
938
979
|
@hb_sent = false # Set the warning flag
|
939
980
|
if @logger && @logger.respond_to?(:on_hbwrite_fail)
|
940
|
-
@logger.on_hbwrite_fail(log_params, {"ticker_interval" => @
|
981
|
+
@logger.on_hbwrite_fail(log_params, {"ticker_interval" => @hbsend_interval,
|
941
982
|
"exception" => sendex})
|
942
983
|
end
|
943
984
|
raise # Re-raise. What else could be done here?
|
@@ -950,7 +991,7 @@ module Stomp
|
|
950
991
|
end
|
951
992
|
|
952
993
|
def _start_receive_ticker
|
953
|
-
sleeptime = @
|
994
|
+
sleeptime = @hbrecv_interval / 1000000.0 # Sleep time secs
|
954
995
|
@rt = Thread.new {
|
955
996
|
while true do
|
956
997
|
sleep sleeptime
|
@@ -959,7 +1000,7 @@ module Stomp
|
|
959
1000
|
@logger.on_hbfire(log_params, "receive_fire", curt)
|
960
1001
|
end
|
961
1002
|
delta = curt - @lr
|
962
|
-
if delta > ((@
|
1003
|
+
if delta > ((@hbrecv_interval + (@hbrecv_interval/5.0)) / 1000000.0) # Be tolerant (plus)
|
963
1004
|
if @logger && @logger.respond_to?(:on_hbfire)
|
964
1005
|
@logger.on_hbfire(log_params, "receive_heartbeat", curt)
|
965
1006
|
end
|
@@ -975,11 +1016,12 @@ module Stomp
|
|
975
1016
|
@socket.ungetc(last_char)
|
976
1017
|
end
|
977
1018
|
@read_semaphore.unlock
|
1019
|
+
@hbrecv_count += 1
|
978
1020
|
else
|
979
1021
|
# Shrug. Have not received one. Just set warning flag.
|
980
1022
|
@hb_received = false
|
981
1023
|
if @logger && @logger.respond_to?(:on_hbread_fail)
|
982
|
-
@logger.on_hbread_fail(log_params, {"ticker_interval" => @
|
1024
|
+
@logger.on_hbread_fail(log_params, {"ticker_interval" => @hbrecv_interval})
|
983
1025
|
end
|
984
1026
|
end
|
985
1027
|
else
|
data/lib/stomp/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -7,7 +7,7 @@ require 'client_shared_examples'
|
|
7
7
|
describe Stomp::Client do
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
@mock_connection = mock('connection')
|
10
|
+
@mock_connection = mock('connection', :autoflush= => true)
|
11
11
|
Stomp::Connection.stub!(:new).and_return(@mock_connection)
|
12
12
|
end
|
13
13
|
|
@@ -33,6 +33,23 @@ describe Stomp::Client do
|
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
+
describe "(autoflush)" do
|
37
|
+
it "should delegate to the connection for accessing the autoflush property" do
|
38
|
+
@mock_connection.should_receive(:autoflush)
|
39
|
+
Stomp::Client.new.autoflush
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should delegate to the connection for setting the autoflush property" do
|
43
|
+
@mock_connection.should_receive(:autoflush=).with(true)
|
44
|
+
Stomp::Client.new.autoflush = true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the autoflush property on the connection when passing in autoflush as a parameter to the Stomp::Client" do
|
48
|
+
@mock_connection.should_receive(:autoflush=).with(true)
|
49
|
+
Stomp::Client.new("login", "password", 'localhost', 61613, false, true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
36
53
|
describe "(created with invalid params)" do
|
37
54
|
|
38
55
|
it "should return ArgumentError if host is nil" do
|
data/spec/connection_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Stomp::Connection do
|
|
21
21
|
:connect_timeout => 0,
|
22
22
|
:parse_timeout => 5,
|
23
23
|
:connect_headers => {},
|
24
|
-
:dmh => false
|
24
|
+
:dmh => false
|
25
25
|
}
|
26
26
|
|
27
27
|
#POG:
|
@@ -33,10 +33,43 @@ describe Stomp::Connection do
|
|
33
33
|
# clone() does a shallow copy, we want a deep one so we can garantee the hosts order
|
34
34
|
normal_parameters = Marshal::load(Marshal::dump(@parameters))
|
35
35
|
|
36
|
-
@tcp_socket = mock(:tcp_socket, :close => nil, :puts => nil, :write => nil, :setsockopt => nil)
|
36
|
+
@tcp_socket = mock(:tcp_socket, :close => nil, :puts => nil, :write => nil, :setsockopt => nil, :flush => true)
|
37
37
|
TCPSocket.stub!(:open).and_return @tcp_socket
|
38
38
|
@connection = Stomp::Connection.new(normal_parameters)
|
39
39
|
end
|
40
|
+
|
41
|
+
describe "autoflush" do
|
42
|
+
let(:parameter_hash) {
|
43
|
+
{
|
44
|
+
"hosts" => [
|
45
|
+
{:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false},
|
46
|
+
{:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false}
|
47
|
+
],
|
48
|
+
"reliable" => true,
|
49
|
+
"initialReconnectDelay" => 0.01,
|
50
|
+
"maxReconnectDelay" => 30.0,
|
51
|
+
"useExponentialBackOff" => true,
|
52
|
+
"backOffMultiplier" => 2,
|
53
|
+
"maxReconnectAttempts" => 0,
|
54
|
+
"randomize" => false,
|
55
|
+
"backup" => false,
|
56
|
+
"connect_timeout" => 0,
|
57
|
+
"parse_timeout" => 5,
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
it "should call flush on the socket when autoflush is true" do
|
62
|
+
@tcp_socket.should_receive(:flush)
|
63
|
+
@connection = Stomp::Connection.new(parameter_hash.merge("autoflush" => true))
|
64
|
+
@connection.publish "/queue", "message", :suppress_content_length => false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not call flush on the socket when autoflush is false" do
|
68
|
+
@tcp_socket.should_not_receive(:flush)
|
69
|
+
@connection = Stomp::Connection.new(parameter_hash)
|
70
|
+
@connection.publish "/queue", "message", :suppress_content_length => false
|
71
|
+
end
|
72
|
+
end
|
40
73
|
|
41
74
|
describe "(created using a hash)" do
|
42
75
|
it "should uncamelize and symbolize the main hash keys" do
|
@@ -54,7 +87,7 @@ describe Stomp::Connection do
|
|
54
87
|
"randomize" => false,
|
55
88
|
"backup" => false,
|
56
89
|
"connect_timeout" => 0,
|
57
|
-
"parse_timeout" => 5
|
90
|
+
"parse_timeout" => 5
|
58
91
|
}
|
59
92
|
|
60
93
|
@connection = Stomp::Connection.new(used_hash)
|
@@ -233,7 +266,7 @@ describe Stomp::Connection do
|
|
233
266
|
|
234
267
|
before(:each) do
|
235
268
|
ssl_parameters = {:hosts => [{:login => "login2", :passcode => "passcode2", :host => "remotehost", :ssl => true}]}
|
236
|
-
@ssl_socket = mock(:ssl_socket, :puts => nil, :write => nil, :setsockopt => nil)
|
269
|
+
@ssl_socket = mock(:ssl_socket, :puts => nil, :write => nil, :setsockopt => nil, :flush => true)
|
237
270
|
|
238
271
|
TCPSocket.should_receive(:open).and_return @tcp_socket
|
239
272
|
OpenSSL::SSL::SSLSocket.should_receive(:new).and_return(@ssl_socket)
|
data/stomp.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stomp}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.4"
|
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 = %q{2012-06-
|
12
|
+
s.date = %q{2012-06-25}
|
13
13
|
s.description = %q{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"]
|
data/test/test_client.rb
CHANGED
@@ -69,7 +69,7 @@ class TestClient < Test::Unit::TestCase
|
|
69
69
|
assert_equal message_text, received2.body
|
70
70
|
assert_equal received.body, received2.body
|
71
71
|
assert_equal received.headers['message-id'], received2.headers['message-id'] unless ENV['STOMP_RABBIT']
|
72
|
-
end
|
72
|
+
end unless RUBY_ENGINE =~ /jruby/
|
73
73
|
|
74
74
|
def test_receipts
|
75
75
|
receipt = false
|
@@ -104,7 +104,7 @@ class TestClient < Test::Unit::TestCase
|
|
104
104
|
assert_raise(RuntimeError) do
|
105
105
|
@client.subscribe make_destination
|
106
106
|
end
|
107
|
-
end
|
107
|
+
end unless RUBY_ENGINE =~ /jruby/
|
108
108
|
|
109
109
|
def test_transactional_publish
|
110
110
|
@client.begin 'tx1'
|
@@ -131,7 +131,7 @@ class TestClient < Test::Unit::TestCase
|
|
131
131
|
@client.subscribe(make_destination) {|m| message = m}
|
132
132
|
sleep 0.01 until message
|
133
133
|
assert_equal "second_message", message.body
|
134
|
-
end
|
134
|
+
end unless RUBY_ENGINE =~ /jruby/
|
135
135
|
|
136
136
|
def test_transaction_ack_rollback_with_new_client
|
137
137
|
@client.publish make_destination, message_text
|
@@ -312,7 +312,7 @@ class TestClient < Test::Unit::TestCase
|
|
312
312
|
|
313
313
|
def test_connection_frame
|
314
314
|
assert_not_nil @client.connection_frame
|
315
|
-
end
|
315
|
+
end unless RUBY_ENGINE =~ /jruby/
|
316
316
|
|
317
317
|
def test_unsubscribe
|
318
318
|
message = nil
|
@@ -372,7 +372,7 @@ class TestClient < Test::Unit::TestCase
|
|
372
372
|
@client.publish(dest, message_text)
|
373
373
|
sleep 1
|
374
374
|
assert_not_nil msg
|
375
|
-
end
|
375
|
+
end unless RUBY_ENGINE =~ /jruby/
|
376
376
|
|
377
377
|
def test_thread_multi_subscribe
|
378
378
|
#
|
data/test/test_connection.rb
CHANGED
@@ -382,7 +382,7 @@ class TestConnection < Test::Unit::TestCase
|
|
382
382
|
msg2 = @conn.receive
|
383
383
|
assert_equal smsg, msg2.body
|
384
384
|
end
|
385
|
-
end
|
385
|
+
end unless ENV['STOMP_AMQ11'] # AMQ sends NACK'd messages to a DLQ
|
386
386
|
|
387
387
|
# Test to illustrate Issue #44. Prior to a fix for #44, these tests would
|
388
388
|
# fail only when connecting to a pure STOMP 1.0 server that does not
|
data/test/test_connection1p.rb
CHANGED
@@ -102,6 +102,8 @@ class TestConnection1P < Test::Unit::TestCase
|
|
102
102
|
conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
|
103
103
|
conn.disconnect
|
104
104
|
end
|
105
|
+
assert conn.hbsend_interval > 0
|
106
|
+
assert conn.hbrecv_interval > 0
|
105
107
|
end
|
106
108
|
|
107
109
|
#
|
@@ -109,7 +111,7 @@ class TestConnection1P < Test::Unit::TestCase
|
|
109
111
|
#
|
110
112
|
cha = {:host => "localhost", "accept-version" => "1.1"}
|
111
113
|
cha[:host] = "/" if ENV['STOMP_RABBIT']
|
112
|
-
cha["heart-beat"] = "
|
114
|
+
cha["heart-beat"] = "10000,0" # Valid heart beat headers, send only
|
113
115
|
conn = nil
|
114
116
|
logger = Tlogger.new
|
115
117
|
assert_nothing_raised do
|
@@ -119,6 +121,7 @@ class TestConnection1P < Test::Unit::TestCase
|
|
119
121
|
conn.set_logger(nil)
|
120
122
|
conn.disconnect
|
121
123
|
end
|
124
|
+
hb_asserts_send(conn)
|
122
125
|
end if ENV['STOMP_HB11LONG']
|
123
126
|
|
124
127
|
#
|
@@ -126,7 +129,7 @@ class TestConnection1P < Test::Unit::TestCase
|
|
126
129
|
#
|
127
130
|
cha = {:host => "localhost", "accept-version" => "1.1"}
|
128
131
|
cha[:host] = "/" if ENV['STOMP_RABBIT']
|
129
|
-
cha["heart-beat"] = "0,
|
132
|
+
cha["heart-beat"] = "0,6000" # Valid heart beat headers, receive only
|
130
133
|
conn = nil
|
131
134
|
logger = Tlogger.new
|
132
135
|
assert_nothing_raised do
|
@@ -137,6 +140,7 @@ class TestConnection1P < Test::Unit::TestCase
|
|
137
140
|
conn.set_logger(nil)
|
138
141
|
conn.disconnect
|
139
142
|
end
|
143
|
+
hb_asserts_recv(conn)
|
140
144
|
end if ENV['STOMP_HB11LONG']
|
141
145
|
|
142
146
|
#
|
@@ -155,7 +159,9 @@ class TestConnection1P < Test::Unit::TestCase
|
|
155
159
|
conn.set_logger(nil)
|
156
160
|
conn.disconnect
|
157
161
|
end
|
162
|
+
hb_asserts_both(conn)
|
158
163
|
end if ENV['STOMP_HB11LONG']
|
164
|
+
|
159
165
|
#
|
160
166
|
def test_conn_1p_0110
|
161
167
|
#
|
@@ -255,5 +261,86 @@ class TestConnection1P < Test::Unit::TestCase
|
|
255
261
|
@conn.subscribe dest, :id => sid
|
256
262
|
}
|
257
263
|
end
|
264
|
+
|
265
|
+
#
|
266
|
+
def test_conn_1p_0130
|
267
|
+
#
|
268
|
+
cha = {:host => "localhost", "accept-version" => "1.1"}
|
269
|
+
cha[:host] = "/" if ENV['STOMP_RABBIT']
|
270
|
+
cha["heart-beat"] = "10000,6000" # Valid heart beat headers, send and receive
|
271
|
+
conn = nil
|
272
|
+
logger = Tlogger.new
|
273
|
+
assert_nothing_raised do
|
274
|
+
conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
|
275
|
+
# m = conn.receive # This will hang forever .....
|
276
|
+
conn.set_logger(logger)
|
277
|
+
sleep 65
|
278
|
+
conn.set_logger(nil)
|
279
|
+
conn.disconnect
|
280
|
+
end
|
281
|
+
hb_asserts_both(conn)
|
282
|
+
end if ENV['STOMP_HB11LONG']
|
283
|
+
|
284
|
+
#
|
285
|
+
def test_conn_1p_0130
|
286
|
+
#
|
287
|
+
cha = {:host => "localhost", "accept-version" => "1.1"}
|
288
|
+
cha[:host] = "/" if ENV['STOMP_RABBIT']
|
289
|
+
cha["heart-beat"] = "10000,1000" # Valid heart beat headers, send and receive
|
290
|
+
conn = nil
|
291
|
+
logger = Tlogger.new
|
292
|
+
assert_nothing_raised do
|
293
|
+
conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
|
294
|
+
# m = conn.receive # This will hang forever .....
|
295
|
+
conn.set_logger(logger)
|
296
|
+
sleep 65
|
297
|
+
conn.set_logger(nil)
|
298
|
+
conn.disconnect
|
299
|
+
end
|
300
|
+
hb_asserts_both(conn)
|
301
|
+
end if ENV['STOMP_HB11LONG']
|
302
|
+
|
303
|
+
#
|
304
|
+
def test_conn_1p_0140
|
305
|
+
#
|
306
|
+
cha = {:host => "localhost", "accept-version" => "1.1"}
|
307
|
+
cha[:host] = "/" if ENV['STOMP_RABBIT']
|
308
|
+
cha["heart-beat"] = "1000,10000" # Valid heart beat headers, send and receive
|
309
|
+
conn = nil
|
310
|
+
logger = Tlogger.new
|
311
|
+
assert_nothing_raised do
|
312
|
+
conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
|
313
|
+
# m = conn.receive # This will hang forever .....
|
314
|
+
conn.set_logger(logger)
|
315
|
+
sleep 65
|
316
|
+
conn.set_logger(nil)
|
317
|
+
conn.disconnect
|
318
|
+
end
|
319
|
+
hb_asserts_both(conn)
|
320
|
+
end if ENV['STOMP_HB11LONG']
|
321
|
+
|
322
|
+
private
|
323
|
+
|
324
|
+
def hb_asserts_both(conn)
|
325
|
+
assert conn.hbsend_interval > 0
|
326
|
+
assert conn.hbrecv_interval > 0
|
327
|
+
assert conn.hbsend_count > 0
|
328
|
+
assert conn.hbrecv_count > 0
|
329
|
+
end
|
330
|
+
|
331
|
+
def hb_asserts_send(conn)
|
332
|
+
assert conn.hbsend_interval > 0
|
333
|
+
assert conn.hbrecv_interval == 0
|
334
|
+
assert conn.hbsend_count > 0
|
335
|
+
assert conn.hbrecv_count == 0
|
336
|
+
end
|
337
|
+
|
338
|
+
def hb_asserts_recv(conn)
|
339
|
+
assert conn.hbsend_interval == 0
|
340
|
+
assert conn.hbrecv_interval > 0
|
341
|
+
assert conn.hbsend_count == 0
|
342
|
+
assert conn.hbrecv_count > 0
|
343
|
+
end
|
344
|
+
|
258
345
|
end if ENV['STOMP_TEST11']
|
259
346
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 4
|
10
|
+
version: 1.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian McCallister
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2012-06-
|
21
|
+
date: 2012-06-25 00:00:00 -04:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|