stomp 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +11 -0
- data/README.rdoc +38 -26
- data/Rakefile +3 -0
- data/bin/catstomp +34 -34
- data/bin/stompcat +36 -36
- data/examples/client11_ex1.rb +64 -55
- data/examples/client11_putget1.rb +47 -35
- data/examples/conn11_ex1.rb +59 -51
- data/examples/conn11_ex2.rb +59 -50
- data/examples/conn11_hb1.rb +35 -26
- data/examples/consumer.rb +25 -12
- data/examples/get11conn_ex1.rb +97 -89
- data/examples/get11conn_ex2.rb +55 -47
- data/examples/logexamp.rb +66 -52
- data/examples/logexamp_ssl.rb +66 -52
- data/examples/publisher.rb +21 -10
- data/examples/put11conn_ex1.rb +35 -24
- data/examples/putget11_rh1.rb +66 -56
- data/examples/slogger.rb +65 -52
- data/examples/ssl_uc1.rb +24 -13
- data/examples/ssl_uc1_ciphers.rb +28 -15
- data/examples/ssl_uc2.rb +26 -16
- data/examples/ssl_uc2_ciphers.rb +31 -18
- data/examples/ssl_uc3.rb +25 -14
- data/examples/ssl_uc3_ciphers.rb +31 -18
- data/examples/ssl_uc4.rb +26 -15
- data/examples/ssl_uc4_ciphers.rb +32 -19
- data/examples/ssl_ucx_default_ciphers.rb +25 -12
- data/examples/stomp11_common.rb +16 -15
- data/examples/topic_consumer.rb +23 -10
- data/examples/topic_publisher.rb +22 -8
- data/lib/client/utils.rb +116 -0
- data/lib/connection/heartbeats.rb +173 -0
- data/lib/connection/netio.rb +322 -0
- data/lib/connection/utf8.rb +294 -0
- data/lib/connection/utils.rb +104 -0
- data/lib/stomp/client.rb +127 -179
- data/lib/stomp/codec.rb +5 -2
- data/lib/stomp/connection.rb +109 -865
- data/lib/stomp/constants.rb +52 -33
- data/lib/stomp/errors.rb +56 -5
- data/lib/stomp/ext/hash.rb +4 -0
- data/lib/stomp/message.rb +49 -29
- data/lib/stomp/sslparams.rb +83 -71
- data/lib/stomp/version.rb +3 -1
- data/lib/stomp.rb +18 -9
- data/stomp.gemspec +58 -3
- data/test/test_client.rb +28 -1
- data/test/test_codec.rb +8 -2
- data/test/test_connection.rb +29 -0
- data/test/test_connection1p.rb +31 -16
- data/test/test_helper.rb +20 -3
- data/test/test_message.rb +8 -3
- data/test/test_ssl.rb +10 -4
- data/test/tlogger.rb +16 -15
- metadata +59 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.2.5 20120804
|
2
|
+
|
3
|
+
* Issue #48 any forks with modifications will be affected!
|
4
|
+
* Source code restructured into individual files
|
5
|
+
* Common indentation used throughout the source
|
6
|
+
* Many method comments have been added
|
7
|
+
* See notes in source regarding making methods private in the next release
|
8
|
+
* See notes in source regarding removal of methods in the next release
|
9
|
+
* Include examples and tests in rdoc generated during install
|
10
|
+
* Issue #47 socket is open during retries
|
11
|
+
|
1
12
|
== 1.2.4 20120625
|
2
13
|
|
3
14
|
* Add ability for client to request flush on write to the connection (Issue #45)
|
data/README.rdoc
CHANGED
@@ -10,35 +10,16 @@ An implementation of the Stomp protocol for Ruby. See:
|
|
10
10
|
|
11
11
|
===New
|
12
12
|
|
13
|
-
* Gem version 1.2.
|
14
|
-
* Gem version 1.2.
|
15
|
-
* Gem version 1.2.
|
13
|
+
* Gem version 1.2.5. Restructure. Forks with modifcations will be affected. See _CHANGELOG.rdoc_ for details.
|
14
|
+
* Gem version 1.2.4. Stomp 1.1 heartbeat fix, autoflush capability, miscellaneous fixes.
|
15
|
+
* Gem version 1.2.3. Miscellaneous fixes, see changelog for details.
|
16
|
+
* Gem version 1.2.2. Performance and more SSL enhancements.
|
16
17
|
* Full support of SSL certificates is announced as of gem version 1.2.1.
|
17
18
|
* Support of Stomp protocol level 1.1 is announced as of gem version 1.2.0.
|
18
19
|
|
19
|
-
See
|
20
|
+
See _CHANGELOG.rdoc_ for details.
|
20
21
|
|
21
|
-
===Example Usage
|
22
|
-
|
23
|
-
client = Stomp::Client.new("test", "user", "localhost", 61613)
|
24
|
-
client.send("/queue/mine", "hello world!")
|
25
|
-
client.subscribe("/queue/mine") do |msg|
|
26
|
-
p msg
|
27
|
-
end
|
28
|
-
|
29
|
-
===Failover + SSL Example URL Usage
|
30
|
-
|
31
|
-
options = "initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false"
|
32
|
-
|
33
|
-
# remotehost1 uses SSL, remotehost2 doesn't
|
34
|
-
client = Stomp::Client.new("failover:(stomp+ssl://login1:passcode1@remotehost1:61612,stomp://login2:passcode2@remotehost2:61613)?#{options}")
|
35
|
-
|
36
|
-
client.publish("/queue/mine", "hello world!")
|
37
|
-
client.subscribe("/queue/mine") do |msg|
|
38
|
-
p msg
|
39
|
-
end
|
40
|
-
|
41
|
-
===Hash Login Example Usage
|
22
|
+
===Hash Login Example Usage (this is the recommended login technique)
|
42
23
|
|
43
24
|
hash = {
|
44
25
|
:hosts => [
|
@@ -67,8 +48,39 @@ See the change log for details.
|
|
67
48
|
# for connection
|
68
49
|
connection = Stomp::Connection.new(hash)
|
69
50
|
|
51
|
+
===Positional Parameter Usage
|
52
|
+
|
53
|
+
client = Stomp::Client.new("test", "user", "localhost", 61613)
|
54
|
+
client.send("/queue/mine", "hello world!")
|
55
|
+
client.subscribe("/queue/mine") do |msg|
|
56
|
+
p msg
|
57
|
+
end
|
58
|
+
|
59
|
+
===Stomp URL Usage
|
60
|
+
|
61
|
+
# Stomp URL :
|
62
|
+
A Stomp URL must begin with 'stomp://' and can be in one of the following forms:
|
63
|
+
|
64
|
+
stomp://host:port
|
65
|
+
stomp://host.domain.tld:port
|
66
|
+
stomp://login:passcode@host:port
|
67
|
+
stomp://login:passcode@host.domain.tld:port
|
68
|
+
|
69
|
+
e.g. c = Stomp::Client.new(urlstring)
|
70
|
+
|
71
|
+
===Failover + SSL Example URL Usage
|
72
|
+
|
73
|
+
options = "initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false"
|
74
|
+
|
75
|
+
# remotehost1 uses SSL, remotehost2 doesn't
|
76
|
+
client = Stomp::Client.new("failover:(stomp+ssl://login1:passcode1@remotehost1:61612,stomp://login2:passcode2@remotehost2:61613)?#{options}")
|
77
|
+
|
78
|
+
client.publish("/queue/mine", "hello world!")
|
79
|
+
client.subscribe("/queue/mine") do |msg|
|
80
|
+
p msg
|
81
|
+
end
|
70
82
|
|
71
|
-
===
|
83
|
+
===Historical Information
|
72
84
|
|
73
85
|
Up until March 2009 the project was maintained and primarily developed by Brian McCallister.
|
74
86
|
|
data/Rakefile
CHANGED
@@ -37,6 +37,9 @@ begin
|
|
37
37
|
gem.authors = ["Brian McCallister", 'Marius Mathiesen', 'Thiago Morello',
|
38
38
|
'Guy M. Allard']
|
39
39
|
gem.add_development_dependency "rspec", '>= 2.3'
|
40
|
+
gem.extra_rdoc_files = [ "README.rdoc", "CHANGELOG.rdoc", "LICENSE",
|
41
|
+
"lib/**/*.rb", "examples/**/*.rb",
|
42
|
+
"test/**/*.rb" ]
|
40
43
|
end
|
41
44
|
Jeweler::GemcutterTasks.new
|
42
45
|
rescue LoadError
|
data/bin/catstomp
CHANGED
@@ -28,46 +28,46 @@ require 'stomp'
|
|
28
28
|
#
|
29
29
|
begin
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
if ARGV[0] == '-h' || ARGV[0] == '--help'
|
32
|
+
$stdout.puts
|
33
|
+
$stdout.puts 'Usage: catstomp DESTINATION'
|
34
|
+
$stdout.puts
|
35
|
+
$stdout.puts 'Publishes STDIN to the desired stomp destination'
|
36
|
+
$stdout.puts
|
37
|
+
$stdout.puts 'Example: ls | catstomp /topic/foo'
|
38
|
+
$stdout.puts
|
39
|
+
$stdout.puts 'Defaults:'
|
40
|
+
$stdout.puts "DESTINATION\t/topic/default"
|
41
|
+
$stdout.puts "STOMP_HOST\tlocalhost"
|
42
|
+
$stdout.puts "STOMP_PORT\t61613"
|
43
|
+
$stdout.puts "STOMP_USER"
|
44
|
+
$stdout.puts "STOMP_PASSWORD"
|
45
|
+
$stdout.puts
|
46
|
+
$stdout.puts 'You can override the stomp host, port, user, or password through environment variables'
|
47
|
+
exit 0
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
@port = 61613
|
51
|
+
@host = "localhost"
|
52
|
+
@user = ENV["STOMP_USER"];
|
53
|
+
@password = ENV["STOMP_PASSWORD"]
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
@host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil
|
56
|
+
@port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
@destination = "/topic/default"
|
59
|
+
@destination = $*[0] if $*[0] != nil
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
|
62
|
+
@conn = Stomp::Connection.open(@user, @password, @host, @port, true)
|
63
|
+
$stderr.print "Sending input to #{@destination}\n"
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
@headers = {'persistent'=>'false'}
|
66
|
+
@headers['reply-to'] = $*[1] if $*[1] != nil
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
STDIN.each_line { |line|
|
69
|
+
@conn.publish @destination, line, @headers
|
70
|
+
}
|
71
71
|
|
72
72
|
rescue
|
73
73
|
end
|
data/bin/stompcat
CHANGED
@@ -28,47 +28,47 @@ require 'stomp'
|
|
28
28
|
#
|
29
29
|
begin
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
if ARGV[0] == '-h' || ARGV[0] == '--help'
|
32
|
+
$stdout.puts
|
33
|
+
$stdout.puts 'Usage: stompcat DESTINATION'
|
34
|
+
$stdout.puts
|
35
|
+
$stdout.puts 'Receives data from a stomp destination and outputs it to STDOUT'
|
36
|
+
$stdout.puts
|
37
|
+
$stdout.puts 'Example: stompcat /topic/foo'
|
38
|
+
$stdout.puts
|
39
|
+
$stdout.puts 'Defaults:'
|
40
|
+
$stdout.puts "DESTINATION\t/topic/default"
|
41
|
+
$stdout.puts "STOMP_HOST\tlocalhost"
|
42
|
+
$stdout.puts "STOMP_PORT\t61613"
|
43
|
+
$stdout.puts "STOMP_USER\t"
|
44
|
+
$stdout.puts "STOMP_PASSWORD\t"
|
45
|
+
$stdout.puts
|
46
|
+
$stdout.puts 'You can override the host, port, user, or password through environment variables'
|
47
|
+
exit 0
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
@port = 61613
|
51
|
+
@host = "localhost"
|
52
|
+
@user = ENV["STOMP_USER"];
|
53
|
+
@password = ENV["STOMP_PASSWORD"]
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
@host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil
|
56
|
+
@port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
@destination = "/topic/default"
|
59
|
+
@destination = $*[0] if $*[0] != nil
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
|
62
|
+
@conn = Stomp::Connection.open(@user, @password, @host, @port, true)
|
63
|
+
$stderr.print "Getting output from #{@destination}\n"
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
@conn.subscribe(@destination, { :ack =>"client" })
|
66
|
+
while true
|
67
|
+
@msg = @conn.receive
|
68
|
+
$stdout.print @msg.body
|
69
|
+
$stdout.flush
|
70
|
+
@conn.ack @msg.headers["message-id"]
|
71
|
+
end
|
72
72
|
|
73
73
|
rescue
|
74
74
|
end
|
data/examples/client11_ex1.rb
CHANGED
@@ -11,70 +11,79 @@ else
|
|
11
11
|
require "stomp11_common"
|
12
12
|
end
|
13
13
|
include Stomp11Common
|
14
|
+
|
14
15
|
#
|
15
|
-
# Stomp 1.1 Client Example 1
|
16
|
-
# ==============================
|
16
|
+
# == Stomp 1.1 Client Example 1
|
17
17
|
#
|
18
18
|
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1
|
19
19
|
# with the Stomp#Client interface.
|
20
20
|
#
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
21
|
+
class Client11Example1
|
22
|
+
# Initialize.
|
23
|
+
def initialize
|
24
|
+
end
|
25
|
+
# Run example.
|
26
|
+
def run
|
27
|
+
# Note: Stomp#Client does not provide a positional set of parameters that
|
28
|
+
# contain a 'connect_headers' parameter. To use the Stomp#Client interface
|
29
|
+
# you _must_ use a 'hashed' set of parameters.
|
30
|
+
#
|
31
|
+
# Create connection headers
|
32
|
+
# =========================
|
33
|
+
#
|
34
|
+
# The two headers used here are _required_ by the specification.
|
35
|
+
#
|
36
|
+
client_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
|
31
37
|
"host" => virt_host, # The 1.1 vhost (could be different than connection host)
|
32
38
|
} # No heartbeats here: there will be none for this connection
|
33
|
-
#
|
34
|
-
# Create the connect hash.
|
35
|
-
# ========================
|
36
|
-
#
|
37
|
-
client_hash = { :hosts => [
|
38
|
-
|
39
|
+
#
|
40
|
+
# Create the connect hash.
|
41
|
+
# ========================
|
42
|
+
#
|
43
|
+
client_hash = { :hosts => [
|
44
|
+
{:login => login, :passcode => passcode, :host => host, :port => port},
|
39
45
|
],
|
40
46
|
:connect_headers => client_hdrs,
|
41
47
|
}
|
48
|
+
#
|
49
|
+
# Get a connection
|
50
|
+
# ================
|
51
|
+
#
|
52
|
+
client = Stomp::Client.new(client_hash)
|
53
|
+
puts "Client Connect complete"
|
54
|
+
#
|
55
|
+
# Let's just do some sanity checks, and look around.
|
56
|
+
#
|
57
|
+
raise "Connection failed!!" unless client.open?
|
58
|
+
#
|
59
|
+
# Is this really a 1.1 conection? (For clients, 'protocol' is a public method.
|
60
|
+
# The value will be '1.0' for those types of connections.)
|
61
|
+
#
|
62
|
+
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
|
63
|
+
#
|
64
|
+
# The broker _could_ have returned an ERROR frame (unlikely).
|
65
|
+
# For clients, 'connection_frame' is a public method.
|
66
|
+
#
|
67
|
+
raise "Connect error: #{client.connection_frame().body}" if client.connection_frame().command == Stomp::CMD_ERROR
|
68
|
+
#
|
69
|
+
# Examine the CONNECT response (the connection_frame()).
|
70
|
+
#
|
71
|
+
puts "Connected Headers required to be present:"
|
72
|
+
puts "Connect version - \t#{client.connection_frame().headers['version']}"
|
73
|
+
puts
|
74
|
+
puts "Connected Headers that are optional:"
|
75
|
+
puts "Connect server - \t\t#{client.connection_frame().headers['server']}"
|
76
|
+
puts "Session ID - \t\t\t#{client.connection_frame().headers['session']}"
|
77
|
+
puts "Server requested heartbeats - \t#{client.connection_frame().headers['heart-beat']}"
|
78
|
+
#
|
79
|
+
# Finally close
|
80
|
+
# =============
|
81
|
+
#
|
82
|
+
client.close # Business as usual, just like 1.0
|
83
|
+
puts "Client close complete"
|
84
|
+
end
|
85
|
+
end
|
42
86
|
#
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
client = Stomp::Client.new(client_hash)
|
47
|
-
puts "Client Connect complete"
|
48
|
-
#
|
49
|
-
# Let's just do some sanity checks, and look around.
|
50
|
-
#
|
51
|
-
raise "Connection failed!!" unless client.open?
|
52
|
-
#
|
53
|
-
# Is this really a 1.1 conection? (For clients, 'protocol' is a public method.
|
54
|
-
# The value will be '1.0' for those types of connections.)
|
55
|
-
#
|
56
|
-
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
|
57
|
-
#
|
58
|
-
# The broker _could_ have returned an ERROR frame (unlikely).
|
59
|
-
# For clients, 'connection_frame' is a public method.
|
60
|
-
#
|
61
|
-
raise "Connect error: #{client.connection_frame().body}" if client.connection_frame().command == Stomp::CMD_ERROR
|
62
|
-
#
|
63
|
-
# Examine the CONNECT response (the connection_frame()).
|
64
|
-
#
|
65
|
-
puts "Connected Headers required to be present:"
|
66
|
-
puts "Connect version - \t#{client.connection_frame().headers['version']}"
|
67
|
-
puts
|
68
|
-
puts "Connected Headers that are optional:"
|
69
|
-
puts "Connect broker - \t\t#{client.connection_frame().headers['broker']}"
|
70
|
-
puts "Session ID - \t\t\t#{client.connection_frame().headers['session']}"
|
71
|
-
puts "Server requested heartbeats - \t#{client.connection_frame().headers['heart-beat']}"
|
72
|
-
#
|
73
|
-
# Finally close
|
74
|
-
# =============
|
75
|
-
#
|
76
|
-
client.close # Business as usual, just like 1.0
|
77
|
-
puts "Client close complete"
|
78
|
-
|
79
|
-
|
87
|
+
e = Client11Example1.new
|
88
|
+
e.run
|
80
89
|
|
@@ -11,49 +11,61 @@ else
|
|
11
11
|
require "stomp11_common"
|
12
12
|
end
|
13
13
|
include Stomp11Common
|
14
|
+
|
14
15
|
#
|
15
|
-
# Stomp 1.1 Client Putter/Getter Example 1
|
16
|
-
# ========================================
|
16
|
+
# == Stomp 1.1 Client Putter/Getter Example 1
|
17
17
|
#
|
18
18
|
# This is much like sending and receiving with a Stomp::Connection.
|
19
19
|
#
|
20
|
-
|
20
|
+
class Client11PutGet1
|
21
|
+
# Initialize.
|
22
|
+
def initialize
|
23
|
+
end
|
24
|
+
# Run example.
|
25
|
+
def run
|
26
|
+
#
|
27
|
+
client_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
|
21
28
|
"host" => virt_host, # The 1.1 vhost (could be different than connection host)
|
22
29
|
} # No heartbeats here: there will be none for this connection
|
23
|
-
#
|
24
|
-
client_hash = { :hosts => [
|
25
|
-
|
30
|
+
#
|
31
|
+
client_hash = { :hosts => [
|
32
|
+
{:login => login, :passcode => passcode, :host => host, :port => port},
|
26
33
|
],
|
27
34
|
:connect_headers => client_hdrs,
|
28
35
|
}
|
36
|
+
#
|
37
|
+
client = Stomp::Client.new(client_hash)
|
38
|
+
puts "Client Connect complete"
|
39
|
+
#
|
40
|
+
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
|
41
|
+
#
|
42
|
+
qname = "/queue/client.nodea.nodeb.nodec"
|
43
|
+
data = "message payload: #{Time.now.to_f}"
|
44
|
+
headers = {}
|
45
|
+
# Send it
|
46
|
+
client.publish qname, data
|
47
|
+
puts "Publish complete"
|
48
|
+
# Receive
|
49
|
+
uuid = client.uuid() # uuid for Stomp::Client is a public method
|
50
|
+
message = nil
|
51
|
+
# Clients must pass a receive block. This is business as usual, required for 1.0.
|
52
|
+
# For 1.1, a unique subscription id is required.
|
53
|
+
client.subscribe(qname, {'id' => uuid}) {|m|
|
54
|
+
message = m
|
55
|
+
}
|
56
|
+
sleep 0.1 until message # Wait for completion
|
57
|
+
puts "Subscribe and receive complete"
|
58
|
+
# Unsubscribe, with the unique id
|
59
|
+
client.unsubscribe qname, {'id' => uuid}
|
60
|
+
# Sanity checks for this example ....
|
61
|
+
raise "Unexpected data" if data != message.body
|
62
|
+
raise "Bad subscription header" if uuid != message.headers['subscription']
|
63
|
+
#
|
64
|
+
client.close # Business as usual, just like 1.0
|
65
|
+
puts "Client close complete"
|
66
|
+
end
|
67
|
+
end
|
29
68
|
#
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
|
34
|
-
#
|
35
|
-
qname = "/queue/client.nodea.nodeb.nodec"
|
36
|
-
data = "message payload: #{Time.now.to_f}"
|
37
|
-
headers = {}
|
38
|
-
# Send it
|
39
|
-
client.publish qname, data
|
40
|
-
# Receive
|
41
|
-
uuid = client.uuid() # uuid for Stomp::Client is a public method
|
42
|
-
message = nil
|
43
|
-
# Clients must pass a receive block. This is business as usual, required for 1.0.
|
44
|
-
# For 1.1, a unique subscription id is required.
|
45
|
-
client.subscribe(qname, {'id' => uuid}) {|m|
|
46
|
-
message = m
|
47
|
-
}
|
48
|
-
sleep 0.1 until message # Wait for completion
|
49
|
-
# Unsubscribe, with the unique id
|
50
|
-
client.unsubscribe qname, {'id' => uuid}
|
51
|
-
# Sanity checks for this example ....
|
52
|
-
raise "Unexpected data" if data != message.body
|
53
|
-
raise "Bad subscription header" if uuid != message.headers['subscription']
|
54
|
-
#
|
55
|
-
client.close # Business as usual, just like 1.0
|
56
|
-
puts "Client close complete"
|
57
|
-
|
58
|
-
|
69
|
+
e = Client11PutGet1.new
|
70
|
+
e.run
|
59
71
|
|
data/examples/conn11_ex1.rb
CHANGED
@@ -11,13 +11,13 @@ else
|
|
11
11
|
require "stomp11_common"
|
12
12
|
end
|
13
13
|
include Stomp11Common
|
14
|
+
|
14
15
|
#
|
15
|
-
# Stomp 1.1 Connection Example 1
|
16
|
-
# ==============================
|
16
|
+
# == Stomp 1.1 Connection Example 1
|
17
17
|
#
|
18
18
|
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1.
|
19
19
|
#
|
20
|
-
# Note: this example assumes that you have at least the 1.2.0 gem release
|
20
|
+
# Note: this example assumes that you have at least the 1.2.0 gem release
|
21
21
|
# installed.
|
22
22
|
#
|
23
23
|
# When you:
|
@@ -48,57 +48,65 @@ include Stomp11Common
|
|
48
48
|
# * heartbeat request
|
49
49
|
#
|
50
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
|
51
|
+
# parameter or a paramaterized connection request. This example uses a
|
52
52
|
# parameterized request.
|
53
53
|
#
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
|
60
|
-
#
|
61
|
-
|
54
|
+
class Connection11Example1
|
55
|
+
# Initialize
|
56
|
+
def initialize
|
57
|
+
end
|
58
|
+
# Run example
|
59
|
+
def run
|
60
|
+
#
|
61
|
+
# Create connection headers
|
62
|
+
# =========================
|
63
|
+
#
|
64
|
+
# The two headers used here are _required_ by the specification.
|
65
|
+
#
|
66
|
+
conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
|
62
67
|
"host" => virt_host, # The 1.1 vhost (could be different than connection host)
|
63
68
|
} # No heartbeats here: there will be none for this connection
|
69
|
+
#
|
70
|
+
# Get a connection
|
71
|
+
# ================
|
72
|
+
#
|
73
|
+
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
|
74
|
+
false, # Not reliable, the default for a parameter connection
|
75
|
+
5, # Connect redelay, the default
|
76
|
+
conn_hdrs) # The 1.1 connection parameters
|
77
|
+
puts "Connection connect complete"
|
78
|
+
#
|
79
|
+
# Let's just do some sanity checks, and look around.
|
80
|
+
#
|
81
|
+
raise "Connection failed!!" unless conn.open?
|
82
|
+
#
|
83
|
+
# Is this really a 1.1 conection? ('protocol' is a read only connection
|
84
|
+
# instance variable. The value will be '1.0' for those types of connections.)
|
85
|
+
#
|
86
|
+
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
87
|
+
#
|
88
|
+
# The broker _could_ have returned an ERROR frame (unlikely).
|
89
|
+
#
|
90
|
+
raise "Connect error: #{conn.connection_frame.body}" if conn.connection_frame.command == Stomp::CMD_ERROR
|
91
|
+
#
|
92
|
+
# Examine the CONNECT response (the connection_frame).
|
93
|
+
#
|
94
|
+
puts "Connected Headers required to be present:"
|
95
|
+
puts "Connect version - \t#{conn.connection_frame.headers['version']}"
|
96
|
+
puts
|
97
|
+
puts "Connected Headers that are optional:"
|
98
|
+
puts "Connect server - \t\t#{conn.connection_frame.headers['server']}"
|
99
|
+
puts "Session ID - \t\t\t#{conn.connection_frame.headers['session']}"
|
100
|
+
puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-beat']}"
|
101
|
+
#
|
102
|
+
# Finally disconnect
|
103
|
+
# ==================
|
104
|
+
#
|
105
|
+
conn.disconnect # Business as usual, just like 1.0
|
106
|
+
puts "Connection disconnect complete"
|
107
|
+
end
|
108
|
+
end
|
64
109
|
#
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
|
69
|
-
false, # Not reliable, the default for a parameter connection
|
70
|
-
5, # Connect redelay, the default
|
71
|
-
conn_hdrs) # The 1.1 connection parameters
|
72
|
-
puts "Connection connect complete"
|
73
|
-
#
|
74
|
-
# Let's just do some sanity checks, and look around.
|
75
|
-
#
|
76
|
-
raise "Connection failed!!" unless conn.open?
|
77
|
-
#
|
78
|
-
# Is this really a 1.1 conection? ('protocol' is a read only connection
|
79
|
-
# instance variable. The value will be '1.0' for those types of connections.)
|
80
|
-
#
|
81
|
-
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
82
|
-
#
|
83
|
-
# The broker _could_ have returned an ERROR frame (unlikely).
|
84
|
-
#
|
85
|
-
raise "Connect error: #{conn.connection_frame.body}" if conn.connection_frame.command == Stomp::CMD_ERROR
|
86
|
-
#
|
87
|
-
# Examine the CONNECT response (the connection_frame).
|
88
|
-
#
|
89
|
-
puts "Connected Headers required to be present:"
|
90
|
-
puts "Connect version - \t#{conn.connection_frame.headers['version']}"
|
91
|
-
puts
|
92
|
-
puts "Connected Headers that are optional:"
|
93
|
-
puts "Connect broker - \t\t#{conn.connection_frame.headers['broker']}"
|
94
|
-
puts "Session ID - \t\t\t#{conn.connection_frame.headers['session']}"
|
95
|
-
puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-beat']}"
|
96
|
-
#
|
97
|
-
# Finally disconnect
|
98
|
-
# ==================
|
99
|
-
#
|
100
|
-
conn.disconnect # Business as usual, just like 1.0
|
101
|
-
puts "Connection disconnect complete"
|
102
|
-
|
103
|
-
|
110
|
+
e = Connection11Example1.new
|
111
|
+
e.run
|
104
112
|
|