stomp 1.4.4 → 1.4.5
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +13 -0
- data/README.md +96 -100
- data/examples/EXAMPLES.md +251 -0
- data/examples/amqdurasub.rb +14 -17
- data/examples/artemis/cliwaiter_not_reliable.rb +12 -5
- data/examples/artemis/{cliwaiter_reliable.rb → cliwaiter_reliable_hb.rb} +24 -23
- data/examples/client_conndisc.rb +66 -0
- data/examples/client_putget.rb +94 -0
- data/examples/conn_conndisc.rb +102 -0
- data/examples/conn_putget.rb +124 -0
- data/examples/contrib.sh +2 -3
- data/examples/contributors.rb +26 -14
- data/examples/examplogger.rb +1 -1
- data/examples/{consumer.rb → historical/consumer.rb} +0 -0
- data/examples/{publisher.rb → historical/publisher.rb} +0 -0
- data/examples/{topic_consumer.rb → historical/topic_consumer.rb} +0 -0
- data/examples/{topic_publisher.rb → historical/topic_publisher.rb} +0 -0
- data/examples/logexamp.rb +23 -14
- data/examples/putget_file.rb +79 -0
- data/examples/{putget11_rh1.rb → putget_rephdrs.rb} +16 -15
- data/examples/ssl/SSL.md +189 -0
- data/examples/{ssl_ctxoptions.rb → ssl/misc/ssl_ctxoptions.rb} +23 -14
- data/examples/ssl/misc/ssl_newparm.rb +53 -0
- data/examples/ssl/misc/ssl_ucx_default_ciphers.rb +54 -0
- data/examples/ssl/ssl_common.rb +96 -0
- data/examples/ssl/sslexall.sh +17 -0
- data/examples/{ssl_uc1.rb → ssl/uc1/ssl_uc1.rb} +15 -11
- data/examples/ssl/uc1/ssl_uc1_ciphers.rb +60 -0
- data/examples/{ssl_uc2.rb → ssl/uc2/ssl_uc2.rb} +17 -10
- data/examples/ssl/uc2/ssl_uc2_ciphers.rb +67 -0
- data/examples/{ssl_uc3.rb → ssl/uc3/ssl_uc3.rb} +15 -16
- data/examples/ssl/uc3/ssl_uc3_ciphers.rb +65 -0
- data/examples/{ssl_uc4.rb → ssl/uc4/ssl_uc4.rb} +15 -15
- data/examples/ssl/uc4/ssl_uc4_ciphers.rb +66 -0
- data/examples/stomp_common.rb +97 -0
- data/lib/connection/netio.rb +83 -37
- data/lib/connection/utf8.rb +0 -7
- data/lib/connection/utils.rb +4 -1
- data/lib/stomp/client.rb +5 -1
- data/lib/stomp/connection.rb +25 -15
- data/lib/stomp/constants.rb +109 -0
- data/lib/stomp/errors.rb +11 -0
- data/lib/stomp/sslparams.rb +3 -4
- data/lib/stomp/version.rb +2 -2
- data/stomp.gemspec +31 -37
- data/test/test_anonymous.rb +4 -0
- data/test/test_client.rb +2 -0
- data/test/test_connection.rb +4 -0
- data/test/test_connection1p.rb +2 -4
- data/test/test_helper.rb +11 -0
- metadata +30 -36
- data/examples/artemis/artlogger.rb +0 -41
- data/examples/client11_ex1.rb +0 -89
- data/examples/client11_putget1.rb +0 -71
- data/examples/conn11_ex1.rb +0 -112
- data/examples/conn11_ex2.rb +0 -87
- data/examples/conn11_hb1.rb +0 -57
- data/examples/consume_file.rb +0 -63
- data/examples/get11conn_ex1.rb +0 -117
- data/examples/get11conn_ex2.rb +0 -77
- data/examples/lflogger.rb +0 -316
- data/examples/logexamp_ssl.rb +0 -81
- data/examples/publish_file.rb +0 -76
- data/examples/publish_file_conn.rb +0 -75
- data/examples/put11conn_ex1.rb +0 -56
- data/examples/ssl_common.rb +0 -73
- data/examples/ssl_newparm.rb +0 -43
- data/examples/ssl_uc1_ciphers.rb +0 -53
- data/examples/ssl_uc2_ciphers.rb +0 -60
- data/examples/ssl_uc3_ciphers.rb +0 -64
- data/examples/ssl_uc4_ciphers.rb +0 -65
- data/examples/ssl_ucx_default_ciphers.rb +0 -41
- data/examples/stomp11_common.rb +0 -54
data/examples/conn11_ex2.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# The current require dance for different Ruby versions.
|
5
|
-
# Change this to suit your requirements.
|
6
|
-
#
|
7
|
-
if Kernel.respond_to?(:require_relative)
|
8
|
-
require_relative("./stomp11_common")
|
9
|
-
else
|
10
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
11
|
-
require "stomp11_common"
|
12
|
-
end
|
13
|
-
include Stomp11Common
|
14
|
-
|
15
|
-
#
|
16
|
-
# == Stomp 1.1 Connection Example 2
|
17
|
-
#
|
18
|
-
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1.
|
19
|
-
#
|
20
|
-
# This example is like the 'conn11_ex1.rb' example except that a 'hashed'
|
21
|
-
# connect request is made.
|
22
|
-
#
|
23
|
-
class Connection11Example2
|
24
|
-
# Initialize.
|
25
|
-
def initialize
|
26
|
-
end
|
27
|
-
# Run example.
|
28
|
-
def run
|
29
|
-
# Create connection headers
|
30
|
-
# =========================
|
31
|
-
#
|
32
|
-
# The two headers used here are _required_ by the specification.
|
33
|
-
#
|
34
|
-
conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
|
35
|
-
"host" => virt_host, # The 1.1 vhost (could be different than connection host)
|
36
|
-
} # No heartbeats here: there will be none for this connection
|
37
|
-
#
|
38
|
-
# Create the connect hash.
|
39
|
-
# ========================
|
40
|
-
#
|
41
|
-
conn_hash = { :hosts => [
|
42
|
-
{:login => login, :passcode => passcode, :host => host, :port => port},
|
43
|
-
],
|
44
|
-
:reliable => false, # Override default
|
45
|
-
:connect_headers => conn_hdrs,
|
46
|
-
}
|
47
|
-
#
|
48
|
-
# Get a connection
|
49
|
-
# ================
|
50
|
-
#
|
51
|
-
conn = Stomp::Connection.new(conn_hash)
|
52
|
-
puts "Connection complete"
|
53
|
-
#
|
54
|
-
# Let's just do some sanity checks, and look around.
|
55
|
-
#
|
56
|
-
raise "Connection failed!!" unless conn.open?
|
57
|
-
#
|
58
|
-
# Is this really a 1.1 conection? ('protocol' is a read only connection
|
59
|
-
# instance variable. The value will be '1.0' for those types of connections.)
|
60
|
-
#
|
61
|
-
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
62
|
-
#
|
63
|
-
# The broker _could_ have returned an ERROR frame (unlikely).
|
64
|
-
#
|
65
|
-
raise "Connect error: #{conn.connection_frame.body}" if conn.connection_frame.command == Stomp::CMD_ERROR
|
66
|
-
#
|
67
|
-
# Examine the CONNECT response (the connection_frame).
|
68
|
-
#
|
69
|
-
puts "Connected Headers required to be present:"
|
70
|
-
puts "Connect version - \t#{conn.connection_frame.headers['version']}"
|
71
|
-
puts
|
72
|
-
puts "Connected Headers that are optional:"
|
73
|
-
puts "Connect server - \t\t#{conn.connection_frame.headers['server']}"
|
74
|
-
puts "Session ID - \t\t\t#{conn.connection_frame.headers['session']}"
|
75
|
-
puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-beat']}"
|
76
|
-
#
|
77
|
-
# Finally disconnect
|
78
|
-
# ==================
|
79
|
-
#
|
80
|
-
conn.disconnect # Business as usual, just like 1.0
|
81
|
-
puts "Disconnect complete"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
#
|
85
|
-
e = Connection11Example2.new
|
86
|
-
e.run
|
87
|
-
|
data/examples/conn11_hb1.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# The current require dance for different Ruby versions.
|
5
|
-
# Change this to suit your requirements.
|
6
|
-
#
|
7
|
-
if Kernel.respond_to?(:require_relative)
|
8
|
-
require_relative("./stomp11_common")
|
9
|
-
require_relative("./examplogger")
|
10
|
-
else
|
11
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
12
|
-
require "stomp11_common"
|
13
|
-
require "examplogger"
|
14
|
-
end
|
15
|
-
include Stomp11Common
|
16
|
-
|
17
|
-
#
|
18
|
-
# == Stomp 1.1 Heartbeat Example 1
|
19
|
-
#
|
20
|
-
# Purpose: to demonstrate that heart beats can work.
|
21
|
-
#
|
22
|
-
class HeartBeatExample1
|
23
|
-
# Initialize.
|
24
|
-
def initialize
|
25
|
-
end
|
26
|
-
# Run example.
|
27
|
-
def run
|
28
|
-
# Create connection headers
|
29
|
-
# =========================
|
30
|
-
#
|
31
|
-
conn_hdrs = {"accept-version" => "1.1", # 1.1
|
32
|
-
"host" => virt_host, # vhost
|
33
|
-
"heart-beat" => "5000,10000", # heartbeats
|
34
|
-
}
|
35
|
-
# Create a logger for demonstration purposes
|
36
|
-
logger = Slogger.new
|
37
|
-
# Connect - a paramaterized request.
|
38
|
-
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
|
39
|
-
false, # Not reliable, the default for a paramaterized connection
|
40
|
-
5, # Connect redelay, the default for a paramaterized connection
|
41
|
-
conn_hdrs) # The 1.1 connection parameters / headers
|
42
|
-
puts "Connection connect complete"
|
43
|
-
#
|
44
|
-
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
45
|
-
#
|
46
|
-
conn.set_logger(logger) # Connection uses a logger
|
47
|
-
sleep 65
|
48
|
-
conn.set_logger(nil) # No logging
|
49
|
-
#
|
50
|
-
conn.disconnect # Get out
|
51
|
-
puts "Connection disconnect complete"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
#
|
55
|
-
e = HeartBeatExample1.new
|
56
|
-
e.run
|
57
|
-
|
data/examples/consume_file.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'stomp'
|
5
|
-
|
6
|
-
if Kernel.respond_to?(:require_relative)
|
7
|
-
require_relative("./stomp11_common")
|
8
|
-
require_relative("./lflogger")
|
9
|
-
else
|
10
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
11
|
-
require "stomp11_common"
|
12
|
-
require "./lflogger"
|
13
|
-
end
|
14
|
-
include Stomp11Common
|
15
|
-
#
|
16
|
-
# Used primarily for testing performance when receiving "large" messages.
|
17
|
-
# "large" => YMMV
|
18
|
-
#
|
19
|
-
class FileReader
|
20
|
-
# Initialize.
|
21
|
-
def initialize(pto)
|
22
|
-
@parse_timeout = pto
|
23
|
-
end
|
24
|
-
# Run example.
|
25
|
-
def run
|
26
|
-
conlogger = Slogger::new
|
27
|
-
start_time = Time.now.to_f
|
28
|
-
#
|
29
|
-
connection_hdrs = {"accept-version" => "1.1",
|
30
|
-
"host" => virt_host(),
|
31
|
-
}
|
32
|
-
connection_hash = { :hosts => [
|
33
|
-
{:login => login(), :passcode => passcode(),
|
34
|
-
:host => host(), :port => port()},
|
35
|
-
],
|
36
|
-
:connect_headers => connection_hdrs,
|
37
|
-
:logger => conlogger,
|
38
|
-
:reliable => false,
|
39
|
-
:parse_timeout => @parse_timeout,
|
40
|
-
}
|
41
|
-
#
|
42
|
-
# p [ "ch", connection_hash ]
|
43
|
-
connection = Stomp::Connection.new(connection_hash)
|
44
|
-
qname = ENV['STOMP_DEST'] ? ENV['STOMP_DEST'] : "/queue/a.big.file"
|
45
|
-
puts "CONF: Qname is: #{qname}"
|
46
|
-
## connection.subscribe(qname, {:destination => qname}, "bigFileSubscriptionID")
|
47
|
-
connection.subscribe(qname, {:destination => qname}, connection.uuid())
|
48
|
-
## connection.subscribe(qname, {:destination => qname}, "0")
|
49
|
-
msg = connection.receive()
|
50
|
-
puts "CONF: Message Command: #{msg.command}"
|
51
|
-
puts "CONF: Message Headers: #{msg.headers}"
|
52
|
-
body_length_bytes = msg.body.respond_to?(:bytesize) ? msg.body.bytesize : msg.body.length
|
53
|
-
puts "CONF: Received: #{body_length_bytes} bytes"
|
54
|
-
connection.disconnect
|
55
|
-
end_time = Time.now.to_f
|
56
|
-
ppt = sprintf("%20.6f", end_time - start_time)
|
57
|
-
puts "CONF: File consumed: #{ppt} seconds"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
#
|
61
|
-
e = FileReader.new(60)
|
62
|
-
e.run
|
63
|
-
|
data/examples/get11conn_ex1.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# The current require dance for different Ruby versions.
|
5
|
-
# Change this to suit your requirements.
|
6
|
-
#
|
7
|
-
if Kernel.respond_to?(:require_relative)
|
8
|
-
require_relative("./stomp11_common")
|
9
|
-
else
|
10
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
11
|
-
require "stomp11_common"
|
12
|
-
end
|
13
|
-
include Stomp11Common
|
14
|
-
#
|
15
|
-
# == Stomp 1.1 Receive Example 1
|
16
|
-
#
|
17
|
-
# Purpose: to demonstrate receiving messages using Stomp 1.1.
|
18
|
-
#
|
19
|
-
class Receive11Example1
|
20
|
-
# Initialize.
|
21
|
-
def initialize
|
22
|
-
end
|
23
|
-
# Run example.
|
24
|
-
def run
|
25
|
-
conn = get_connection() # Use helper method to obtain a Stomp#connection
|
26
|
-
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
27
|
-
#
|
28
|
-
# To start receiving messages, you must first subscribe. This is similar
|
29
|
-
# to using Stomp 1.0.
|
30
|
-
#
|
31
|
-
# However, with Stomp 1.1:
|
32
|
-
#
|
33
|
-
# * for subscribe, the 'id' header is now _required_
|
34
|
-
# * for unsubscribe, the 'id' header is now _required_
|
35
|
-
#
|
36
|
-
# The 'id' header specifies a 'subscription id' that _must_ be unique for
|
37
|
-
# the current session.
|
38
|
-
#
|
39
|
-
qname = "/queue/nodea.nodeb.nodec"
|
40
|
-
#
|
41
|
-
# Here is an example of allowed functionality in 1.0 that is not allowed in 1.1:
|
42
|
-
#
|
43
|
-
begin
|
44
|
-
conn.subscribe qname
|
45
|
-
rescue RuntimeError => sre
|
46
|
-
puts "Rescue: #{sre}, #{sre.message}"
|
47
|
-
end
|
48
|
-
#
|
49
|
-
# So, you must specify an 'id' header. And it must be unique within the
|
50
|
-
# current session.
|
51
|
-
#
|
52
|
-
# You can build your own unique ids of course. That is a valid option.
|
53
|
-
# In order to provide you with some assistance in generating unique ids,
|
54
|
-
# two convenience methods are provided with the connection:
|
55
|
-
#
|
56
|
-
# * sha1 - generate a sha1 hash of some data you supply. This may be sufficient for many purposes.
|
57
|
-
# * uuid - generate a type 4 UUID. This would be sufficient in all cases.
|
58
|
-
#
|
59
|
-
# Get a sha1:
|
60
|
-
#
|
61
|
-
sha1 = conn.sha1(qname) # sha1 of the queue name perhaps
|
62
|
-
puts "Queue name: #{qname}, sha1: #{sha1}"
|
63
|
-
#
|
64
|
-
# Or perhaps a different sha1:
|
65
|
-
#
|
66
|
-
tn = Time.now.to_f.to_s # Maybe unique itself.
|
67
|
-
sha1 = conn.sha1(tn)
|
68
|
-
puts "Time now: #{tn}, sha1: #{sha1}"
|
69
|
-
#
|
70
|
-
# Or a Type 4 UUID:
|
71
|
-
#
|
72
|
-
uuid = conn.uuid()
|
73
|
-
puts "Type 4 UUID: #{uuid}"
|
74
|
-
#
|
75
|
-
# You can specify the 'id' in the subscribe call in one of two ways:
|
76
|
-
#
|
77
|
-
# a) In the headers parameter
|
78
|
-
# b) In the third positional parameter, the subId
|
79
|
-
#
|
80
|
-
# So, using the 'uuid', either:
|
81
|
-
#
|
82
|
-
# a) conn.subscribe qname, {'id' => uuid}
|
83
|
-
# b) conn.subscribe qname, {}, uuid
|
84
|
-
#
|
85
|
-
conn.subscribe qname, {'id' => uuid} # First style
|
86
|
-
#
|
87
|
-
# Within a session, you may not subscribe to the same subscription id.
|
88
|
-
#
|
89
|
-
begin
|
90
|
-
conn.subscribe qname, {'id' => uuid} # Second time
|
91
|
-
rescue RuntimeError => sre
|
92
|
-
puts "Rescue: #{sre}, #{sre.message}"
|
93
|
-
end
|
94
|
-
#
|
95
|
-
# Once you have subscribed, you may receive as usual
|
96
|
-
#
|
97
|
-
1.upto(nmsgs()) do
|
98
|
-
received = conn.receive
|
99
|
-
puts "Received data: #{received.body}"
|
100
|
-
end
|
101
|
-
#
|
102
|
-
# For unsubscribe, you must use the 'id' you used on subscribe.
|
103
|
-
#
|
104
|
-
# You have the same options for placing this id in the headers or in the 3rd
|
105
|
-
# positional parameter.
|
106
|
-
#
|
107
|
-
conn.unsubscribe qname, {}, uuid # Second style
|
108
|
-
#
|
109
|
-
# And finally, disconnect.
|
110
|
-
#
|
111
|
-
conn.disconnect
|
112
|
-
end
|
113
|
-
end
|
114
|
-
#
|
115
|
-
e = Receive11Example1.new
|
116
|
-
e.run
|
117
|
-
|
data/examples/get11conn_ex2.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# The current require dance for different Ruby versions.
|
5
|
-
# Change this to suit your requirements.
|
6
|
-
#
|
7
|
-
if Kernel.respond_to?(:require_relative)
|
8
|
-
require_relative("./stomp11_common")
|
9
|
-
else
|
10
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
11
|
-
require "stomp11_common"
|
12
|
-
end
|
13
|
-
include Stomp11Common
|
14
|
-
#
|
15
|
-
# == Stomp 1.1 Receive Example 2
|
16
|
-
#
|
17
|
-
# Purpose: to demonstrate receiving messages using Stomp 1.1, and using
|
18
|
-
# 'ack => client'.
|
19
|
-
#
|
20
|
-
class Receive11Example2
|
21
|
-
# Initialize.
|
22
|
-
def initialize
|
23
|
-
end
|
24
|
-
# Run example.
|
25
|
-
def run
|
26
|
-
conn = get_connection() # Use helper method to obtain a Stomp#connection
|
27
|
-
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
|
28
|
-
#
|
29
|
-
qname = "/queue/nodea.nodeb.nodec"
|
30
|
-
#
|
31
|
-
uuid = conn.uuid()
|
32
|
-
puts "Subscribe id: #{uuid}"
|
33
|
-
#
|
34
|
-
# Subscribe with client ack mode
|
35
|
-
#
|
36
|
-
conn.subscribe qname, {'id' => uuid, 'ack' => 'client'} #
|
37
|
-
#
|
38
|
-
# Once you have subscribed, you may receive as usual
|
39
|
-
#
|
40
|
-
1.upto(nmsgs()) do
|
41
|
-
received = conn.receive
|
42
|
-
puts "Received data: #{received.body}"
|
43
|
-
#
|
44
|
-
# We want now to ACK this message. In Stomp 1.0, a 'message-id' header was
|
45
|
-
# required for the ACK. In Stomp 1.1, and additional header is required:
|
46
|
-
#
|
47
|
-
# * 'subscription' => id
|
48
|
-
#
|
49
|
-
msgid = received.headers['message-id']
|
50
|
-
#
|
51
|
-
# What you cannot do:
|
52
|
-
#
|
53
|
-
begin
|
54
|
-
conn.ack msgid
|
55
|
-
rescue RuntimeError => sre
|
56
|
-
puts "Rescue: #{sre}, #{sre.message}"
|
57
|
-
end
|
58
|
-
#
|
59
|
-
# Try a valid 1.1 ACK
|
60
|
-
#
|
61
|
-
conn.ack msgid, {'subscription' => uuid}
|
62
|
-
puts "ACK - msgid: #{msgid}, subscription: #{uuid}"
|
63
|
-
end
|
64
|
-
#
|
65
|
-
# Unsubscribe
|
66
|
-
#
|
67
|
-
conn.unsubscribe qname, {}, uuid # Second style
|
68
|
-
#
|
69
|
-
# And finally, disconnect.
|
70
|
-
#
|
71
|
-
conn.disconnect
|
72
|
-
end
|
73
|
-
end
|
74
|
-
#
|
75
|
-
e = Receive11Example2.new
|
76
|
-
e.run
|
77
|
-
|
data/examples/lflogger.rb
DELETED
@@ -1,316 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'logger' # use the standard Ruby logger .....
|
4
|
-
|
5
|
-
# == Example STOMP call back logger class.
|
6
|
-
#
|
7
|
-
# Optional callback methods:
|
8
|
-
#
|
9
|
-
# * on_connecting: connection starting
|
10
|
-
# * on_connected: successful connect
|
11
|
-
# * on_connectfail: unsuccessful connect (will usually be retried)
|
12
|
-
# * on_disconnect: successful disconnect
|
13
|
-
#
|
14
|
-
# * on_miscerr: on miscellaneous xmit/recv errors
|
15
|
-
#
|
16
|
-
# * on_publish: publish called
|
17
|
-
# * on_subscribe: subscribe called
|
18
|
-
# * on_unsubscribe: unsubscribe called
|
19
|
-
#
|
20
|
-
# * on_begin: begin called
|
21
|
-
# * on_ack: ack called
|
22
|
-
# * on_nack: nack called
|
23
|
-
# * on_commit: commit called
|
24
|
-
# * on_abort: abort called
|
25
|
-
#
|
26
|
-
# * on_receive: receive called and successful
|
27
|
-
#
|
28
|
-
# * on_ssl_connecting: SSL connection starting
|
29
|
-
# * on_ssl_connected: successful SSL connect
|
30
|
-
# * on_ssl_connectfail: unsuccessful SSL connect (will usually be retried)
|
31
|
-
#
|
32
|
-
# * on_hbread_fail: unsuccessful Heartbeat read
|
33
|
-
# * on_hbwrite_fail: unsuccessful Heartbeat write
|
34
|
-
# * on_hbfire: on any send or receive heartbeat
|
35
|
-
#
|
36
|
-
# All methods are optional, at the user's requirements.
|
37
|
-
#
|
38
|
-
# If a method is not provided, it is not called (of course.)
|
39
|
-
#
|
40
|
-
# IMPORTANT NOTE: in general, call back logging methods *SHOULD* not raise exceptions,
|
41
|
-
# otherwise the underlying STOMP connection may fail in mysterious ways.
|
42
|
-
# There are, however, exceptions to this 'rule'.
|
43
|
-
#
|
44
|
-
# Useful exceptions to this rule are:
|
45
|
-
#
|
46
|
-
# * on_connectfail
|
47
|
-
# * on_ssl_connectfail
|
48
|
-
#
|
49
|
-
# These two methods can raise a Stomp::Errors::LoggerConnectionError. If this
|
50
|
-
# exception is raised, it is passed up the chain to the caller.
|
51
|
-
#
|
52
|
-
# Callback parameters: are a copy of the @parameters instance variable for
|
53
|
-
# the Stomp::Connection.
|
54
|
-
#
|
55
|
-
# A logger class may optionally inherit from the provided NullLogger
|
56
|
-
#
|
57
|
-
# # class Slogger < Stomp::NullLogger
|
58
|
-
#
|
59
|
-
class Slogger
|
60
|
-
|
61
|
-
MAX_BODY_LEN = 1024 # Arbitrary
|
62
|
-
|
63
|
-
# Initialize a new callback logger instance.
|
64
|
-
def initialize(init_parms = nil)
|
65
|
-
_init
|
66
|
-
@log.info("Logger initialization complete.")
|
67
|
-
end
|
68
|
-
|
69
|
-
def _init
|
70
|
-
@log = Logger::new(STDOUT) # User preference
|
71
|
-
@log.level = Logger::DEBUG # User preference
|
72
|
-
end
|
73
|
-
|
74
|
-
def marshal_dump
|
75
|
-
[]
|
76
|
-
end
|
77
|
-
|
78
|
-
def marshal_load(array)
|
79
|
-
_init
|
80
|
-
end
|
81
|
-
|
82
|
-
# Log connecting events
|
83
|
-
def on_connecting(parms)
|
84
|
-
begin
|
85
|
-
@log.debug "Connecting: #{info(parms)}"
|
86
|
-
rescue
|
87
|
-
@log.debug "Connecting oops #{$!}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Log connected events
|
92
|
-
def on_connected(parms)
|
93
|
-
begin
|
94
|
-
@log.debug "Connected Info: #{info(parms)}"
|
95
|
-
@log.debug "Connected Parms: #{parms}"
|
96
|
-
rescue
|
97
|
-
@log.debug "Connected oops #{$!}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# Log connectfail events
|
102
|
-
def on_connectfail(parms)
|
103
|
-
begin
|
104
|
-
@log.debug "Connect Fail #{info(parms)}"
|
105
|
-
rescue
|
106
|
-
@log.debug "Connect Fail oops #{$!}"
|
107
|
-
end
|
108
|
-
=begin
|
109
|
-
# An example LoggerConnectionError raise
|
110
|
-
@log.debug "Connect Fail, will raise"
|
111
|
-
raise Stomp::Error::LoggerConnectionError.new("quit from connect fail")
|
112
|
-
=end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Log disconnect events
|
116
|
-
def on_disconnect(parms)
|
117
|
-
begin
|
118
|
-
@log.debug "Disconnected #{info(parms)}"
|
119
|
-
rescue
|
120
|
-
@log.debug "Disconnected oops #{$!}"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Log miscellaneous errors
|
125
|
-
def on_miscerr(parms, errstr)
|
126
|
-
begin
|
127
|
-
@log.debug "Miscellaneous Error Info: #{info(parms)}"
|
128
|
-
@log.debug "Miscellaneous Error String: #{errstr}"
|
129
|
-
@log.debug "Miscellaneous Error Parms: #{parms}"
|
130
|
-
rescue
|
131
|
-
@log.debug "Miscellaneous Error oops #{$!}"
|
132
|
-
# Most clients will want to know about this. YMMV
|
133
|
-
raise
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Log Subscribe
|
138
|
-
def on_subscribe(parms, headers)
|
139
|
-
begin
|
140
|
-
@log.debug "Subscribe Parms #{info(parms)}"
|
141
|
-
@log.debug "Subscribe Headers #{headers}"
|
142
|
-
rescue
|
143
|
-
@log.debug "Subscribe oops #{$!}"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# Log UnSubscribe
|
148
|
-
def on_unsubscribe(parms, headers)
|
149
|
-
begin
|
150
|
-
@log.debug "UnSubscribe Parms #{info(parms)}"
|
151
|
-
@log.debug "UnSubscribe Headers #{headers}"
|
152
|
-
rescue
|
153
|
-
@log.debug "UnSubscribe oops #{$!}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
# Log Publish
|
158
|
-
def on_publish(parms, body, headers)
|
159
|
-
begin
|
160
|
-
@log.debug "Publish Parms #{info(parms)}"
|
161
|
-
body_length_bytes = body.respond_to?(:bytesize) ? body.bytesize : body.length
|
162
|
-
@log.debug "Publish Message Body #{body}" if body_length_bytes <= MAX_BODY_LEN
|
163
|
-
@log.debug "Publish Headers #{headers}"
|
164
|
-
rescue
|
165
|
-
@log.debug "Publish oops #{$!}"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# Log Receive
|
170
|
-
def on_receive(parms, result)
|
171
|
-
begin
|
172
|
-
@log.debug "Receive Parms #{info(parms)}"
|
173
|
-
@log.debug result.is_a? Stomp::Message
|
174
|
-
## @log.debug "Receive Result #{result}"
|
175
|
-
rescue
|
176
|
-
@log.debug "Receive oops #{$!}"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Log Begin
|
181
|
-
def on_begin(parms, headers)
|
182
|
-
begin
|
183
|
-
@log.debug "Begin Parms #{info(parms)}"
|
184
|
-
@log.debug "Begin Result #{headers}"
|
185
|
-
rescue
|
186
|
-
@log.debug "Begin oops #{$!}"
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
# Log Ack
|
191
|
-
def on_ack(parms, headers)
|
192
|
-
begin
|
193
|
-
@log.debug "Ack Parms #{info(parms)}"
|
194
|
-
@log.debug "Ack Result #{headers}"
|
195
|
-
rescue
|
196
|
-
@log.debug "Ack oops #{$!}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Log NAck
|
201
|
-
def on_nack(parms, headers)
|
202
|
-
begin
|
203
|
-
@log.debug "NAck Parms #{info(parms)}"
|
204
|
-
@log.debug "NAck Result #{headers}"
|
205
|
-
rescue
|
206
|
-
@log.debug "NAck oops #{$!}"
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
# Log Commit
|
211
|
-
def on_commit(parms, headers)
|
212
|
-
begin
|
213
|
-
@log.debug "Commit Parms #{info(parms)}"
|
214
|
-
@log.debug "Commit Result #{headers}"
|
215
|
-
rescue
|
216
|
-
@log.debug "Commit oops #{$!}"
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Log Abort
|
221
|
-
def on_abort(parms, headers)
|
222
|
-
begin
|
223
|
-
@log.debug "Abort Parms #{info(parms)}"
|
224
|
-
@log.debug "Abort Result #{headers}"
|
225
|
-
rescue
|
226
|
-
@log.debug "Abort oops #{$!}"
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
# Stomp 1.1+ - heart beat read (receive) failed.
|
231
|
-
def on_hbread_fail(parms, ticker_data = {})
|
232
|
-
begin
|
233
|
-
@log.debug "Hbreadf Parms #{info(parms)}"
|
234
|
-
@log.debug "Hbreadf Result #{ticker_data.inspect}"
|
235
|
-
rescue
|
236
|
-
@log.debug "Hbreadf oops #{$!}"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
# Stomp 1.1+ - heart beat send (transmit) failed.
|
241
|
-
def on_hbwrite_fail(parms, ticker_data = {})
|
242
|
-
begin
|
243
|
-
@log.debug "Hbwritef Parms #{info(parms)}"
|
244
|
-
@log.debug "Hbwritef Result #{ticker_data.inspect}"
|
245
|
-
rescue
|
246
|
-
@log.debug "Hbwritef oops #{$!}"
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
# Log SSL connection start.
|
251
|
-
def on_ssl_connecting(parms)
|
252
|
-
begin
|
253
|
-
@log.debug "SSL Connecting Parms #{info(parms)}"
|
254
|
-
rescue
|
255
|
-
@log.debug "SSL Connecting oops #{$!}"
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
# Log a successful SSL connect.
|
260
|
-
def on_ssl_connected(parms)
|
261
|
-
begin
|
262
|
-
@log.debug "SSL Connected Parms #{info(parms)}"
|
263
|
-
rescue
|
264
|
-
@log.debug "SSL Connected oops #{$!}"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
# Log an unsuccessful SSL connect.
|
269
|
-
def on_ssl_connectfail(parms)
|
270
|
-
begin
|
271
|
-
@log.debug "SSL Connect Fail Parms #{info(parms)}"
|
272
|
-
@log.debug "SSL Connect Fail Exception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
|
273
|
-
rescue
|
274
|
-
@log.debug "SSL Connect Fail oops #{$!}"
|
275
|
-
end
|
276
|
-
=begin
|
277
|
-
# An example LoggerConnectionError raise
|
278
|
-
@log.debug "SSL Connect Fail, will raise"
|
279
|
-
raise Stomp::Error::LoggerConnectionError.new("quit from SSL connect")
|
280
|
-
=end
|
281
|
-
end
|
282
|
-
|
283
|
-
# Log heart beat fires
|
284
|
-
def on_hbfire(parms, srind, firedata = {})
|
285
|
-
begin
|
286
|
-
@log.debug "HeartBeat Fire Parms #{info(parms)}"
|
287
|
-
@log.debug "HeartBeat Fire Send/Receive #{srind}"
|
288
|
-
rescue
|
289
|
-
@log.debug "HeartBeat Fire oops #{$!}"
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
private
|
294
|
-
|
295
|
-
# Example information extract.
|
296
|
-
def info(parms)
|
297
|
-
#
|
298
|
-
# Available in the parms Hash:
|
299
|
-
# parms[:cur_host]
|
300
|
-
# parms[:cur_port]
|
301
|
-
# parms[:cur_login]
|
302
|
-
# parms[:cur_passcode]
|
303
|
-
# parms[:cur_ssl]
|
304
|
-
# parms[:cur_recondelay]
|
305
|
-
# parms[:cur_parseto]
|
306
|
-
# parms[:cur_conattempts]
|
307
|
-
# parms[:cur_failure]
|
308
|
-
# parms[:openstat]
|
309
|
-
#
|
310
|
-
# For the on_ssl_connectfail callback these are also available:
|
311
|
-
# parms[:ssl_exception]
|
312
|
-
#
|
313
|
-
"Host: #{parms[:cur_host]}, Port: #{parms[:cur_port]}, Login: #{parms[:cur_login]}, Passcode: #{parms[:cur_passcode]}, ssl: #{parms[:cur_ssl]}"
|
314
|
-
end
|
315
|
-
end # of class
|
316
|
-
|