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.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +96 -100
  4. data/examples/EXAMPLES.md +251 -0
  5. data/examples/amqdurasub.rb +14 -17
  6. data/examples/artemis/cliwaiter_not_reliable.rb +12 -5
  7. data/examples/artemis/{cliwaiter_reliable.rb → cliwaiter_reliable_hb.rb} +24 -23
  8. data/examples/client_conndisc.rb +66 -0
  9. data/examples/client_putget.rb +94 -0
  10. data/examples/conn_conndisc.rb +102 -0
  11. data/examples/conn_putget.rb +124 -0
  12. data/examples/contrib.sh +2 -3
  13. data/examples/contributors.rb +26 -14
  14. data/examples/examplogger.rb +1 -1
  15. data/examples/{consumer.rb → historical/consumer.rb} +0 -0
  16. data/examples/{publisher.rb → historical/publisher.rb} +0 -0
  17. data/examples/{topic_consumer.rb → historical/topic_consumer.rb} +0 -0
  18. data/examples/{topic_publisher.rb → historical/topic_publisher.rb} +0 -0
  19. data/examples/logexamp.rb +23 -14
  20. data/examples/putget_file.rb +79 -0
  21. data/examples/{putget11_rh1.rb → putget_rephdrs.rb} +16 -15
  22. data/examples/ssl/SSL.md +189 -0
  23. data/examples/{ssl_ctxoptions.rb → ssl/misc/ssl_ctxoptions.rb} +23 -14
  24. data/examples/ssl/misc/ssl_newparm.rb +53 -0
  25. data/examples/ssl/misc/ssl_ucx_default_ciphers.rb +54 -0
  26. data/examples/ssl/ssl_common.rb +96 -0
  27. data/examples/ssl/sslexall.sh +17 -0
  28. data/examples/{ssl_uc1.rb → ssl/uc1/ssl_uc1.rb} +15 -11
  29. data/examples/ssl/uc1/ssl_uc1_ciphers.rb +60 -0
  30. data/examples/{ssl_uc2.rb → ssl/uc2/ssl_uc2.rb} +17 -10
  31. data/examples/ssl/uc2/ssl_uc2_ciphers.rb +67 -0
  32. data/examples/{ssl_uc3.rb → ssl/uc3/ssl_uc3.rb} +15 -16
  33. data/examples/ssl/uc3/ssl_uc3_ciphers.rb +65 -0
  34. data/examples/{ssl_uc4.rb → ssl/uc4/ssl_uc4.rb} +15 -15
  35. data/examples/ssl/uc4/ssl_uc4_ciphers.rb +66 -0
  36. data/examples/stomp_common.rb +97 -0
  37. data/lib/connection/netio.rb +83 -37
  38. data/lib/connection/utf8.rb +0 -7
  39. data/lib/connection/utils.rb +4 -1
  40. data/lib/stomp/client.rb +5 -1
  41. data/lib/stomp/connection.rb +25 -15
  42. data/lib/stomp/constants.rb +109 -0
  43. data/lib/stomp/errors.rb +11 -0
  44. data/lib/stomp/sslparams.rb +3 -4
  45. data/lib/stomp/version.rb +2 -2
  46. data/stomp.gemspec +31 -37
  47. data/test/test_anonymous.rb +4 -0
  48. data/test/test_client.rb +2 -0
  49. data/test/test_connection.rb +4 -0
  50. data/test/test_connection1p.rb +2 -4
  51. data/test/test_helper.rb +11 -0
  52. metadata +30 -36
  53. data/examples/artemis/artlogger.rb +0 -41
  54. data/examples/client11_ex1.rb +0 -89
  55. data/examples/client11_putget1.rb +0 -71
  56. data/examples/conn11_ex1.rb +0 -112
  57. data/examples/conn11_ex2.rb +0 -87
  58. data/examples/conn11_hb1.rb +0 -57
  59. data/examples/consume_file.rb +0 -63
  60. data/examples/get11conn_ex1.rb +0 -117
  61. data/examples/get11conn_ex2.rb +0 -77
  62. data/examples/lflogger.rb +0 -316
  63. data/examples/logexamp_ssl.rb +0 -81
  64. data/examples/publish_file.rb +0 -76
  65. data/examples/publish_file_conn.rb +0 -75
  66. data/examples/put11conn_ex1.rb +0 -56
  67. data/examples/ssl_common.rb +0 -73
  68. data/examples/ssl_newparm.rb +0 -43
  69. data/examples/ssl_uc1_ciphers.rb +0 -53
  70. data/examples/ssl_uc2_ciphers.rb +0 -60
  71. data/examples/ssl_uc3_ciphers.rb +0 -64
  72. data/examples/ssl_uc4_ciphers.rb +0 -65
  73. data/examples/ssl_ucx_default_ciphers.rb +0 -41
  74. data/examples/stomp11_common.rb +0 -54
@@ -0,0 +1,251 @@
1
+ # stomp gem examples
2
+
3
+ This is to describe the existing stomp gem examples.
4
+
5
+ ## Environment Variables
6
+
7
+ You will likely need to use supported environment variables to
8
+ define example related data elements for your system. See example
9
+ stomp_common.rb for details of support of this functionality.
10
+
11
+ <table border="2" style="width:100%;border: 2px solid black;">
12
+ <tr>
13
+ <th style="border: 2px solid black;padding-left: 10px;" >
14
+ Environment Variable
15
+ </th>
16
+ <th style="border: 2px solid black;padding-left: 10px;" >
17
+ Description
18
+ </th>
19
+ </tr>
20
+ <!-- -->
21
+ <tr>
22
+ <td style="border: 2px solid black;padding-left: 10px;" >
23
+ STOMP_LOGIN
24
+ </td>
25
+ <td style="border: 2px solid black;padding-left: 10px;" >
26
+ The user ID when connecting to a broker.<br/>
27
+ Default: guest.
28
+ </td>
29
+ </tr>
30
+ <!-- -->
31
+ <tr>
32
+ <td style="border: 2px solid black;padding-left: 10px;" >
33
+ STOMP_PASSCODE
34
+ </td>
35
+ <td style="border: 2px solid black;padding-left: 10px;" >
36
+ The user password when connecting to a broker.<br/>
37
+ Deault: guest.
38
+ </td>
39
+ </tr>
40
+ <!-- -->
41
+ <tr>
42
+ <td style="border: 2px solid black;padding-left: 10px;" >
43
+ STOMP_HOST
44
+ </td>
45
+ <td style="border: 2px solid black;padding-left: 10px;" >
46
+ The broker host name.<br/>
47
+ Default: localhost.
48
+ </td>
49
+ </tr>
50
+ <!-- -->
51
+ <tr>
52
+ <td style="border: 2px solid black;padding-left: 10px;" >
53
+ STOMP_PORT
54
+ </td>
55
+ <td style="border: 2px solid black;padding-left: 10px;" >
56
+ The broker port number.<br/>
57
+ Default: 61613.
58
+ </td>
59
+ </tr>
60
+ <!-- -->
61
+ <tr>
62
+ <td style="border: 2px solid black;padding-left: 10px;" >
63
+ STOMP_VHOST
64
+ </td>
65
+ <td style="border: 2px solid black;padding-left: 10px;" >
66
+ The name of the broker's virtual host for 1.1+ connections.<br/>
67
+ Default: localhost.
68
+ </td>
69
+ </tr>
70
+ <!-- -->
71
+ <tr>
72
+ <td style="border: 2px solid black;padding-left: 10px;" >
73
+ STOMP_PROTOCOL
74
+ </td>
75
+ <td style="border: 2px solid black;padding-left: 10px;" >
76
+ The Stomp protocol level to use.<br/>
77
+ Default: 1.2.
78
+ </td>
79
+ </tr>
80
+ <!-- -->
81
+ <tr>
82
+ <td style="border: 2px solid black;padding-left: 10px;" >
83
+ STOMP_HEARTBEATS
84
+ </td>
85
+ <td style="border: 2px solid black;padding-left: 10px;" >
86
+ The Stomp heart beat parameters to use.<br/>
87
+ Default: nil/none.
88
+ </td>
89
+ </tr>
90
+ <!-- -->
91
+ <tr>
92
+ <td style="border: 2px solid black;padding-left: 10px;" >
93
+ STOMP_NMSGS
94
+ </td>
95
+ <td style="border: 2px solid black;padding-left: 10px;" >
96
+ The number of messages to put and/or get.<br/>
97
+ Default: 1.
98
+ </td>
99
+ </tr>
100
+ <!-- -->
101
+ <tr>
102
+ <td style="border: 2px solid black;padding-left: 10px;" >
103
+ STOMP_DEST
104
+ </td>
105
+ <td style="border: 2px solid black;padding-left: 10px;" >
106
+ The default name of a Stomp destination.<br/>
107
+ Default: /queue/(time-stamp).
108
+ </td>
109
+ </tr>
110
+ <!-- -->
111
+ <tr>
112
+ <td style="border: 2px solid black;padding-left: 10px;" >
113
+ STOMP_SUPPRESS_CL
114
+ </td>
115
+ <td style="border: 2px solid black;padding-left: 10px;" >
116
+ Whether to include a 'suppress_content_length' header in a message.<br/>
117
+ Default: false.
118
+ </td>
119
+ </tr>
120
+ <!-- -->
121
+ <tr>
122
+ <td style="border: 2px solid black;padding-left: 10px;" >
123
+ STOMP_SSL
124
+ </td>
125
+ <td style="border: 2px solid black;padding-left: 10px;" >
126
+ Whether to use an SSL connection.<br/>
127
+ Default: false.
128
+ </td>
129
+ </tr>
130
+ </table>
131
+
132
+ ## General Examples
133
+
134
+ Note: you will need a running broker to use these examples.
135
+
136
+ ### examples/client_conndisc.rb
137
+
138
+ A plain example of using a `Stomp#Client` to:
139
+
140
+ * Connect to a broker
141
+ * Disconnect from the broker
142
+
143
+ ### examples/client_putget.rb
144
+
145
+ An example of using a `Stomp#Client` to:
146
+
147
+ * Connect to a broker
148
+ * Send and receive some message(s)
149
+ * Disconnect from the broker
150
+
151
+ ### examples/conn_conndisc.rb
152
+
153
+ A plain example of using a `Stomp#Connection` to connect to:
154
+
155
+ * Connect to a broker
156
+ * Disconnect from the broker
157
+
158
+ ### examples/conn_putget.rb
159
+
160
+ An example of using a `Stomp#Connection` to:
161
+
162
+ * Connect to a broker
163
+ * Send and receive some message(s)
164
+ * Disconnect from the broker
165
+
166
+ ### examples/examplogger.rb
167
+
168
+ This example shows how to write a Stomp gem callback logger.
169
+
170
+ A callback logger can be used to greatly enhance understanding of
171
+ application flow, and the gem actions resulting from that flow.
172
+
173
+ ### examples/logexamp.rb
174
+
175
+ This example shows how to use the example callback logger in
176
+ 'examples/examplogger.rb'.
177
+
178
+ ### examples/putget_file.rb
179
+
180
+ This example is primarily meant to measure performance when sending
181
+ (possibly) large messages.
182
+
183
+ This example show how to:
184
+
185
+ * Open a file
186
+ * Read the entire file into a buffer
187
+ * Close the file
188
+ * Connect to a broker
189
+ * Send the entire file as a single message
190
+ * Disconnect from the broker
191
+
192
+ ### examples/putget_rephdrs.rb
193
+
194
+ The Stomp 1.1+ specifications describe functionality for supporting multiple user supplied
195
+ headers with the same header key.
196
+
197
+ Experience shows that various real world brokers support this functionality
198
+ in a variety of ways.
199
+
200
+ The gem supports multiple headers with the same key. This example
201
+ demonstrates that support.
202
+
203
+ However, given the variety of broker support, this example works only with the
204
+ (now defunct?) Apache Apollo broker.
205
+
206
+ You should modify the example to work with other brokers.
207
+
208
+ ## Artemis Specific Examples
209
+
210
+ The Apache Artemis broker exhibits some behavior that is unusual for a
211
+ Stomp broker.
212
+
213
+ This behavior is to sever connections fairly quickly if there is no
214
+ activity on the connection. The current default is 1 minute of
215
+ inactivity.
216
+
217
+ There are several approaches that a client can use to 'bypass' this
218
+ behavior.
219
+
220
+ ### examples/artemis/cliwaiter_not_reliable.rb
221
+
222
+ This example uses a `Stomp#Client` that specifies `:reliable => false` in the
223
+ connection parameters.
224
+
225
+ ### examples/artemis/cliwaiter_reliable_hb.rb
226
+
227
+ This example uses a `Stomp#Client` that specifies `:reliable => true` in the
228
+ connection parameters and also uses Stomp heart beats to help keep a connection
229
+ alive.
230
+
231
+
232
+ ## Historical Examples
233
+
234
+ These are examples that are bing kept for historical reasons. They
235
+ have been part of the gem's history since very early days of development.
236
+
237
+ ### examples/historical/consumer.rb
238
+
239
+ The classical message consumer.
240
+
241
+ ### examples/historical/producer.rb
242
+
243
+ The classical message producer.
244
+
245
+ ### examples/historical/topic_consumer.rb
246
+
247
+ The classical message consumer (from a topic).
248
+
249
+ ### examples/historical/topic_producer.rb
250
+
251
+ The classical message producer (to a topic).
@@ -5,12 +5,12 @@
5
5
  # Change this to suit your requirements.
6
6
  #
7
7
  if Kernel.respond_to?(:require_relative)
8
- require_relative("./stomp11_common")
8
+ require_relative("./stomp_common")
9
9
  else
10
10
  $LOAD_PATH << File.dirname(__FILE__)
11
- require "stomp11_common"
11
+ require "stomp_common"
12
12
  end
13
-
13
+ include Stomp1xCommon
14
14
  =begin
15
15
 
16
16
  A recent experience suggested that we might provide an example of how
@@ -34,18 +34,19 @@ end
34
34
  subscription(s).
35
35
  Done by providing a "cilent-id" CONNECT header.
36
36
 
37
- 2) On SUBSCRIBE, indicate an AMQ specific (uniqie) subscription ID. Done
37
+ 2) On SUBSCRIBE, indicate an AMQ specific (unique) subscription ID. Done
38
38
  by providing a "activemq.subscriptionName" header to SUBSCRIBE.
39
39
 
40
40
  =end
41
41
 
42
42
  # login hash
43
43
  hash = { :hosts => [
44
- {:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61613, :ssl => false}, # AMQ
44
+ {:login => login(), :passcode => passcode(), :host => host(), :port => port(),
45
+ :ssl => usessl()}, #
45
46
  ],
46
47
  :reliable => true,
47
48
  :closed_check => false,
48
- :connect_headers => {:host => "localhost", :"accept-version" => "1.0",
49
+ :connect_headers => {:host => "localhost", :"accept-version" => "1.2",
49
50
  # Requirement 1, name should be unique.
50
51
  :"client-id" => "dursubcli01", # REF the 1st AMQ link above
51
52
  }
@@ -61,21 +62,17 @@ sh = { "activemq.subscriptionName" => "subname01" } # REF the 1st AMQ link above
61
62
  cli.subscribe(topic, sh) do |msg|
62
63
  puts "msg: #{msg}"
63
64
  end
64
- # Wait for a very long time, usually exit via ^C
65
- puts "Press ^C to exit"
66
- sleep 1000000
67
- puts "Done yet?"
68
-
69
65
  =begin
70
66
  At this point open your AMQ admin console (port 8161 usually), and examine
71
67
  the 'subscribers' section. You should see an instance of this client
72
68
  displayed in the "Active Durable Topic Subscribers" section.
73
-
74
- When you press ^C to exit this program, return to the AMQ console and
69
+ =end
70
+ # Wait for a very long time, usually exit via ^C
71
+ puts "Open AMQ console and examing the 'subscribers' section"
72
+ puts "Wne done, press ^C to exit, and reexamine the 'subscribers' section"
73
+ sleep 1000000
74
+ =begin
75
+ After you press ^C to exit this program, return to the AMQ console and
75
76
  refresh the display. (Do not restart AMQ). You should see this client in the
76
77
  "Offline Durable Topic Subscribers" section.
77
78
  =end
78
-
79
-
80
-
81
-
@@ -2,6 +2,11 @@
2
2
  #
3
3
  require 'stomp'
4
4
  #
5
+ # Artemis will summarily close down connections if there is no traffic for some
6
+ # time. This code demonstrates running with a gem connetion parameter of
7
+ # :reliable => false (the gem will not retry). The code demonstrates handling
8
+ # your own retries a certain number of times (3 to be axact).
9
+ #
5
10
  class CliWaiter
6
11
 
7
12
  @@retry_num = 0
@@ -14,7 +19,7 @@ class CliWaiter
14
19
  @port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 31613 # Artemis here
15
20
  @slt = 75
16
21
  @ver = ENV['STOMP_PROTOCOL'] ? ENV['STOMP_PROTOCOL'] : "1.2"
17
- @hbdata = ENV['STOMP_HEARTBEATS'] ? ENV['STOMP_HEARTBEATS'] : "0,0"
22
+ @hbdata = "0,0" # Force no heartbeats for this example
18
23
  @conn_hdrs = {"accept-version" => @ver, # version
19
24
  "host" => "localhost", # vhost
20
25
  "heart-beat" => @hbdata, # heartbeats
@@ -27,10 +32,10 @@ class CliWaiter
27
32
  :connect_headers => @conn_hdrs,
28
33
  }
29
34
  p [ "DB1", @hash ]
30
- @do_retry=true # Retry ourself, gem code will not because of :reliable =>
35
+ @do_retry=true # Retry ourself, gem code will not because of :reliable => false
31
36
  end
32
37
  # Run example.
33
- def run
38
+ def run()
34
39
  begin
35
40
  @@retry_num += 1
36
41
  puts "Try Number: #{@@retry_num}"
@@ -52,8 +57,10 @@ class CliWaiter
52
57
  puts "The gory details:"
53
58
  print ex.backtrace.join("\n")
54
59
  if @do_retry && @@retry_num < @@max_retries
60
+ puts "Will retry"
55
61
  retry
56
62
  else
63
+ puts "Will re-raise"
57
64
  raise
58
65
  end
59
66
  end
@@ -62,5 +69,5 @@ end
62
69
  #
63
70
 
64
71
  #
65
- e = CliWaiter.new
66
- e.run
72
+ e = CliWaiter.new()
73
+ e.run()
@@ -1,61 +1,62 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  #
3
3
  require 'stomp'
4
- #
5
4
  if Kernel.respond_to?(:require_relative)
6
- require_relative("artlogger")
7
- else
8
- $LOAD_PATH << File.dirname(__FILE__)
9
- require "artlogger"
10
- end
5
+ require_relative("../examplogger")
6
+ else
7
+ $LOAD_PATH << File.dirname(__FILE__)
8
+ require "../examplogger"
9
+ end
10
+ #
11
+ # Artemis will summarily close down connections if there is no traffic for some
12
+ # time. This code demonstrates running with a gem connetion parameter using
13
+ # heartbeats to totally avoid this Artemis behavior.
11
14
  #
12
15
  class CliWaiter
13
16
 
14
17
  # Initialize.
15
18
  def initialize # Change the following as needed.
16
- #
17
- mylog = Slogger::new # a stomp callback logger
18
- #
19
19
  @gem_retries = true
20
20
  @host = ENV['STOMP_HOST'] ? ENV['STOMP_HOST'] : "localhost"
21
21
  @port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 31613 # Artemis here
22
22
  @slt = 75
23
23
  @ver = ENV['STOMP_PROTOCOL'] ? ENV['STOMP_PROTOCOL'] : "1.2"
24
- @hbdata = ENV['STOMP_HEARTBEATS'] ? ENV['STOMP_HEARTBEATS'] : "0,0"
24
+ # The Artemis artificial default is to sever after 1 minute of inactivity.
25
+ # The default heart-beat parameters here are chosen just to avoid this
26
+ # Artemis specific behavior. YMMV.
27
+ @hbdata = ENV['STOMP_HEARTBEATS'] ? ENV['STOMP_HEARTBEATS'] : "59000,59000"
25
28
  @conn_hdrs = {"accept-version" => @ver, # version
26
29
  "host" => "localhost", # vhost
27
- "heart-beat" => @hbdata, # heartbeats
30
+ "heart-beat" => @hbdata, # heartbeats
28
31
  }
32
+ mylog = Slogger::new() # The client provided STOMP callback logger
29
33
  @hash = { :hosts => [
30
34
  {:login => 'guest', :passcode => 'guest', :host => @host, :port => @port},
31
35
  ],
32
36
  :reliable => @gem_retries, # reliable controls retries by the gem
33
- :logger => mylog, # This enables callback logging!
34
37
  :autoflush => true,
35
38
  :connect_headers => @conn_hdrs,
36
- :initial_reconnect_delay => 1.0, # initial delay before reconnect (secs)
37
- :use_exponential_back_off => false, # don't backoff
38
- :max_reconnect_attempts => 3, # retry 3 times
39
+ :logger => mylog, # This enables callback logging!
39
40
  }
40
41
  end
41
42
  # Run example.
42
- def run
43
- puts "Connect host: #{@host}, port: #{@port}"
44
- puts "Connect hash: #{@hash}"
45
- #
43
+ def run()
46
44
  puts "CliWaiter Starts"
45
+ puts "Connect Hash is: #{@hash}"
47
46
  c = Stomp::Client.new(@hash)
48
47
  #
49
- while true
48
+ while true
49
+ # This should run forever.
50
50
  puts "CliWaiter Sleeps: #{@slt} seconds"
51
51
  sleep @slt
52
52
  end
53
53
  #
54
- c.close
54
+ c.close()
55
+ puts "CliWaiter Ends"
55
56
  end
56
57
  end
57
58
  #
58
59
 
59
60
  #
60
- e = CliWaiter.new
61
- e.run
61
+ e = CliWaiter.new()
62
+ e.run()