stomp 1.2.16 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -113,7 +113,7 @@ module Stomp
113
113
  @parameters = nil
114
114
  @parse_timeout = 5 # To override, use hashed parameters
115
115
  @connect_timeout = 0 # To override, use hashed parameters
116
- @logger = nil # To override, use hashed parameters
116
+ @logger = Stomp::NullLogger.new # To override, use hashed parameters
117
117
  @autoflush = false # To override, use hashed parameters or setter
118
118
  @closed_check = true # Run closed check in each protocol method
119
119
  @hbser = false # Raise if heartbeat send exception
@@ -142,14 +142,13 @@ module Stomp
142
142
  # hashed_initialize prepares a new connection with a Hash of initialization
143
143
  # parameters.
144
144
  def hashed_initialize(params)
145
-
146
145
  @parameters = refine_params(params)
147
146
  @reliable = @parameters[:reliable]
148
147
  @reconnect_delay = @parameters[:initial_reconnect_delay]
149
148
  @connect_headers = @parameters[:connect_headers]
150
149
  @parse_timeout = @parameters[:parse_timeout]
151
150
  @connect_timeout = @parameters[:connect_timeout]
152
- @logger = @parameters[:logger]
151
+ @logger = @parameters[:logger] || Stomp::NullLogger.new
153
152
  @autoflush = @parameters[:autoflush]
154
153
  @closed_check = @parameters[:closed_check]
155
154
  @hbser = @parameters[:hbser]
@@ -184,9 +183,7 @@ module Stomp
184
183
  headers = headers.symbolize_keys
185
184
  headers[:transaction] = name
186
185
  _headerCheck(headers)
187
- if @logger && @logger.respond_to?(:on_begin)
188
- @logger.on_begin(log_params, headers)
189
- end
186
+ @logger.on_begin(log_params, headers)
190
187
  transmit(Stomp::CMD_BEGIN, headers)
191
188
  end
192
189
 
@@ -217,9 +214,7 @@ module Stomp
217
214
  headers[:'message-id'] = message_id
218
215
  end
219
216
  _headerCheck(headers)
220
- if @logger && @logger.respond_to?(:on_ack)
221
- @logger.on_ack(log_params, headers)
222
- end
217
+ @logger.on_ack(log_params, headers)
223
218
  transmit(Stomp::CMD_ACK, headers)
224
219
  end
225
220
 
@@ -243,9 +238,7 @@ module Stomp
243
238
  raise Stomp::Error::SubscriptionRequiredError unless headers[:subscription]
244
239
  end
245
240
  _headerCheck(headers)
246
- if @logger && @logger.respond_to?(:on_nack)
247
- @logger.on_nack(log_params, headers)
248
- end
241
+ @logger.on_nack(log_params, headers)
249
242
  transmit(Stomp::CMD_NACK, headers)
250
243
  end
251
244
 
@@ -255,9 +248,7 @@ module Stomp
255
248
  headers = headers.symbolize_keys
256
249
  headers[:transaction] = name
257
250
  _headerCheck(headers)
258
- if @logger && @logger.respond_to?(:on_commit)
259
- @logger.on_commit(log_params, headers)
260
- end
251
+ @logger.on_commit(log_params, headers)
261
252
  transmit(Stomp::CMD_COMMIT, headers)
262
253
  end
263
254
 
@@ -267,9 +258,7 @@ module Stomp
267
258
  headers = headers.symbolize_keys
268
259
  headers[:transaction] = name
269
260
  _headerCheck(headers)
270
- if @logger && @logger.respond_to?(:on_abort)
271
- @logger.on_abort(log_params, headers)
272
- end
261
+ @logger.on_abort(log_params, headers)
273
262
  transmit(Stomp::CMD_ABORT, headers)
274
263
  end
275
264
 
@@ -284,9 +273,7 @@ module Stomp
284
273
  headers[:id] = subId if headers[:id].nil?
285
274
  end
286
275
  _headerCheck(headers)
287
- if @logger && @logger.respond_to?(:on_subscribe)
288
- @logger.on_subscribe(log_params, headers)
289
- end
276
+ @logger.on_subscribe(log_params, headers)
290
277
 
291
278
  # Store the subscription so that we can replay if we reconnect.
292
279
  if @reliable
@@ -309,9 +296,7 @@ module Stomp
309
296
  headers[:id] = subId unless headers[:id]
310
297
  end
311
298
  _headerCheck(headers)
312
- if @logger && @logger.respond_to?(:on_unsubscribe)
313
- @logger.on_unsubscribe(log_params, headers)
314
- end
299
+ @logger.on_unsubscribe(log_params, headers)
315
300
  transmit(Stomp::CMD_UNSUBSCRIBE, headers)
316
301
  if @reliable
317
302
  subId = dest if subId.nil?
@@ -327,9 +312,7 @@ module Stomp
327
312
  headers = headers.symbolize_keys
328
313
  headers[:destination] = destination
329
314
  _headerCheck(headers)
330
- if @logger && @logger.respond_to?(:on_publish)
331
- @logger.on_publish(log_params, message, headers)
332
- end
315
+ @logger.on_publish(log_params, message, headers)
333
316
  transmit(Stomp::CMD_SEND, headers, message)
334
317
  end
335
318
 
@@ -392,9 +375,7 @@ module Stomp
392
375
  end
393
376
  transmit(Stomp::CMD_DISCONNECT, headers)
394
377
  @disconnect_receipt = receive if headers[:receipt]
395
- if @logger && @logger.respond_to?(:on_disconnect)
396
- @logger.on_disconnect(log_params)
397
- end
378
+ @logger.on_disconnect(log_params)
398
379
  close_socket
399
380
  end
400
381
 
@@ -417,11 +398,9 @@ module Stomp
417
398
  super_result = __old_receive()
418
399
  if super_result.nil? && @reliable && !closed?
419
400
  errstr = "connection.receive returning EOF as nil - resetting connection.\n"
420
- if @logger && @logger.respond_to?(:on_miscerr)
421
- @logger.on_miscerr(log_params, "es_recv: " + errstr)
422
- else
423
- $stderr.print errstr
424
- end
401
+ @logger.on_miscerr(log_params, "es_recv: " + errstr)
402
+ $stderr.print errstr
403
+
425
404
  # !!! This initiates a re-connect !!!
426
405
  # The call to __old_receive() will in turn call socket(). Before
427
406
  # that we should change the target host, otherwise the host that
@@ -438,9 +417,7 @@ module Stomp
438
417
  @closed = true
439
418
  warn 'warning: broker sent EOF, and connection not reliable' unless defined?(Test)
440
419
  end
441
- if @logger && @logger.respond_to?(:on_receive)
442
- @logger.on_receive(log_params, super_result)
443
- end
420
+ @logger.on_receive(log_params, super_result)
444
421
  return super_result
445
422
  end
446
423
 
@@ -221,6 +221,57 @@ module Stomp
221
221
  end
222
222
  end
223
223
 
224
+ class StompException < RuntimeError; end
225
+
226
+ class BrokerException < StompException
227
+ attr_reader :headers, :message, :receipt_id, :broker_backtrace
228
+
229
+ def initialize(message)
230
+ @message = message.headers.delete('message')
231
+ @receipt_id = message.headers.delete('receipt-id') || 'no receipt id'
232
+ @headers = message.headers
233
+ @broker_backtrace = message.body
234
+ end
235
+ end
236
+
237
+ class ProducerFlowControlException < BrokerException
238
+ attr_reader :producer_id, :dest_name
239
+
240
+ def initialize(message)
241
+ super(message)
242
+ msg_headers = /.*producer\s+\((.*)\).*to\s+prevent\s+flooding\s+([^\s]*)\.\s+/i.match(@message)
243
+
244
+ @producer_id = msg_headers && msg_headers[1]
245
+ @dest_name = msg_headers && msg_headers[2]
246
+ end
247
+ end
248
+
249
+ class ProtocolException < BrokerException
250
+ def initialize(message)
251
+ super(message)
252
+ end
253
+ end
254
+
255
+ class StartTimeoutException < StompException
256
+ def initialize(timeout)
257
+ @timeout = timeout
258
+ end
259
+
260
+ def message
261
+ "Client failed to start in #{@timeout} seconds"
262
+ end
263
+ end
264
+
265
+ class ReadReceiptTimeoutException < StompException
266
+ def initialize(timeout)
267
+ @timeout = timeout
268
+ end
269
+
270
+ def message
271
+ "Read receipt not received after #{@timeout} seconds"
272
+ end
273
+ end
274
+
224
275
  end # module Error
225
276
 
226
277
  end # module Stomp
@@ -0,0 +1,28 @@
1
+ module Stomp
2
+ class NullLogger
3
+ def on_miscerr(parms, error_msg)
4
+ $stderr.print parms
5
+ $stderr.print error_msg
6
+ end
7
+
8
+ def on_connecting(parms); end
9
+ def on_connected(parms); end
10
+ def on_connectfail(parms); end
11
+ def on_disconnect(parms); end
12
+ def on_subscribe(parms, headers); end
13
+ def on_unsubscribe(parms, headers); end
14
+ def on_publish(parms, message, headers); end
15
+ def on_receive(parms, result); end
16
+ def on_begin(parms, headers); end
17
+ def on_ack(parms, headers); end
18
+ def on_nack(parms, headers); end
19
+ def on_commit(parms, headers); end
20
+ def on_abort(parms, headers); end
21
+ def on_hbread_fail(parms, ticker_data); end
22
+ def on_hbwrite_fail(parms, ticker_data); end
23
+ def on_ssl_connecting(parms); end
24
+ def on_ssl_connected(parms); end
25
+ def on_ssl_connectfail(parms); end
26
+ def on_hbfire(parms, srind, curt); end
27
+ end
28
+ end
@@ -51,13 +51,25 @@ require 'logger' # use the standard Ruby logger .....
51
51
  # Callback parameters: are a copy of the @parameters instance variable for
52
52
  # the Stomp::Connection.
53
53
  #
54
- class Slogger
54
+ class Slogger < Stomp::NullLogger
55
55
 
56
56
  # Initialize a new callback logger instance.
57
57
  def initialize(init_parms = nil)
58
+ _init
59
+ @log.info("Logger initialization complete.")
60
+ end
61
+
62
+ def _init
58
63
  @log = Logger::new(STDOUT) # User preference
59
64
  @log.level = Logger::DEBUG # User preference
60
- @log.info("Logger initialization complete.")
65
+ end
66
+
67
+ def marshal_dump
68
+ []
69
+ end
70
+
71
+ def marshal_load(array)
72
+ _init
61
73
  end
62
74
 
63
75
  # Log connecting events
@@ -5,8 +5,8 @@ module Stomp
5
5
  # Define the gem version.
6
6
  module Version #:nodoc: all
7
7
  MAJOR = 1
8
- MINOR = 2
9
- PATCH = 16
8
+ MINOR = 3
9
+ PATCH = 0
10
10
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
11
11
  end
12
12
  end
@@ -5,8 +5,10 @@ require 'client_shared_examples'
5
5
 
6
6
 
7
7
  describe Stomp::Client do
8
+ let(:null_logger) { double("mock Stomp::NullLogger") }
8
9
 
9
10
  before(:each) do
11
+ Stomp::NullLogger.stub(:new).and_return(null_logger)
10
12
  @mock_connection = double('connection', :autoflush= => true)
11
13
  Stomp::Connection.stub(:new).and_return(@mock_connection)
12
14
  end
@@ -130,6 +132,7 @@ describe Stomp::Client do
130
132
  :passcode => 'testpassword',
131
133
  :host => 'localhost',
132
134
  :port => 12345}],
135
+ :logger => null_logger,
133
136
  :reliable => false)
134
137
  Stomp::Client.new('testlogin', 'testpassword', 'localhost', '12345', false)
135
138
  end
@@ -139,7 +142,6 @@ describe Stomp::Client do
139
142
  end
140
143
 
141
144
  describe "(created with non-authenticating stomp:// URL and non-TLD host)" do
142
-
143
145
  before(:each) do
144
146
  @client = Stomp::Client.new('stomp://foobar:12345')
145
147
  end
@@ -149,6 +151,7 @@ describe Stomp::Client do
149
151
  :passcode => '',
150
152
  :host => 'foobar',
151
153
  :port => 12345}],
154
+ :logger => null_logger,
152
155
  :reliable => false)
153
156
  Stomp::Client.new('stomp://foobar:12345')
154
157
  end
@@ -168,6 +171,7 @@ describe Stomp::Client do
168
171
  :passcode => '',
169
172
  :host => 'foo-bar',
170
173
  :port => 12345}],
174
+ :logger => null_logger,
171
175
  :reliable => false)
172
176
  Stomp::Client.new('stomp://foo-bar:12345')
173
177
  end
@@ -187,6 +191,7 @@ describe Stomp::Client do
187
191
  :passcode => 'testpasscode',
188
192
  :host => 'foobar',
189
193
  :port => 12345}],
194
+ :logger => null_logger,
190
195
  :reliable => false)
191
196
  Stomp::Client.new('stomp://test-login:testpasscode@foobar:12345')
192
197
  end
@@ -206,6 +211,7 @@ describe Stomp::Client do
206
211
  :passcode => 'testpasscode',
207
212
  :host => 'foo-bar',
208
213
  :port => 12345}],
214
+ :logger => null_logger,
209
215
  :reliable => false)
210
216
  Stomp::Client.new('stomp://test-login:testpasscode@foo-bar:12345')
211
217
  end
@@ -228,6 +234,7 @@ describe Stomp::Client do
228
234
  :passcode => '',
229
235
  :host => 'host.foobar.com',
230
236
  :port => 12345}],
237
+ :logger => null_logger,
231
238
  :reliable => false)
232
239
  Stomp::Client.new('stomp://host.foobar.com:12345')
233
240
  end
@@ -247,6 +254,7 @@ describe Stomp::Client do
247
254
  :passcode => 'testpasscode',
248
255
  :host => 'host.foobar.com',
249
256
  :port => 12345}],
257
+ :logger => null_logger,
250
258
  :reliable => false)
251
259
  Stomp::Client.new('stomp://testlogin:testpasscode@host.foobar.com:12345')
252
260
  end
@@ -276,6 +284,8 @@ describe Stomp::Client do
276
284
  {:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false},
277
285
  {:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false}
278
286
  ]
287
+
288
+ @parameters.merge!({:logger => null_logger})
279
289
 
280
290
  Stomp::Connection.should_receive(:new).with(@parameters)
281
291
 
@@ -292,6 +302,8 @@ describe Stomp::Client do
292
302
  {:login => "login3", :passcode => "passcode3", :host => "remotehost2", :port => 61618, :ssl => false}
293
303
  ]
294
304
 
305
+ @parameters.merge!({:logger => null_logger})
306
+
295
307
  Stomp::Connection.should_receive(:new).with(@parameters)
296
308
 
297
309
  client = Stomp::Client.new(url)
@@ -306,6 +318,8 @@ describe Stomp::Client do
306
318
  {:login => "", :passcode => "", :host => "remotehost", :port => 61617, :ssl => false}
307
319
  ]
308
320
 
321
+ @parameters.merge!({:logger => null_logger})
322
+
309
323
  Stomp::Connection.should_receive(:new).with(@parameters)
310
324
 
311
325
  client = Stomp::Client.new(url)
@@ -320,6 +334,8 @@ describe Stomp::Client do
320
334
  {:login => "", :passcode => "", :host => "remotehost", :port => 61617, :ssl => false}
321
335
  ]
322
336
 
337
+ @parameters.merge!({:logger => null_logger})
338
+
323
339
  Stomp::Connection.should_receive(:new).with(@parameters)
324
340
 
325
341
  client = Stomp::Client.new(url)
@@ -349,6 +365,8 @@ describe Stomp::Client do
349
365
  {:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false}
350
366
  ]
351
367
 
368
+ @parameters.merge!({:logger => null_logger})
369
+
352
370
  Stomp::Connection.should_receive(:new).with(@parameters)
353
371
 
354
372
  client = Stomp::Client.new(url)
@@ -357,4 +375,24 @@ describe Stomp::Client do
357
375
 
358
376
  end
359
377
 
378
+
379
+ describe '#error_listener' do
380
+ context 'on getting a ResourceAllocationException' do
381
+ let(:message) do
382
+ message = Stomp::Message.new('')
383
+ message.body = "javax.jms.ResourceAllocationException: Usage"
384
+ message.headers = {'message' => %q{message = "Usage Manager Memory Limit reached. Stopping producer (ID:producer) to prevent flooding queue://errors. See } }
385
+ message.command = Stomp::CMD_ERROR
386
+ message
387
+ end
388
+
389
+ it 'should handle ProducerFlowControlException errors by raising' do
390
+ expect do
391
+ @client = Stomp::Client.new
392
+ @error_listener = @client.instance_variable_get(:@error_listener)
393
+ @error_listener.call(message)
394
+ end.to raise_exception(Stomp::Error::ProducerFlowControlException)
395
+ end
396
+ end
397
+ end
360
398
  end
@@ -29,6 +29,7 @@ describe Stomp::Connection do
29
29
  :max_hbrlck_fails => 0,
30
30
  :fast_hbs_adjust => 0.0,
31
31
  :connread_timeout => 0,
32
+ :tcp_nodelay => true,
32
33
  }
33
34
 
34
35
  #POG:
@@ -353,6 +354,7 @@ describe Stomp::Connection do
353
354
  :max_hbrlck_fails => 0,
354
355
  :fast_hbs_adjust => 0.0,
355
356
  :connread_timeout => 0,
357
+ :tcp_nodelay => true,
356
358
  }
357
359
 
358
360
  used_hash = {
@@ -393,6 +395,7 @@ describe Stomp::Connection do
393
395
  :max_hbrlck_fails => 456,
394
396
  :fast_hbs_adjust => 0.2,
395
397
  :connread_timeout => 42,
398
+ :tcp_nodelay => true,
396
399
  }
397
400
 
398
401
  @connection = Stomp::Connection.new(used_hash)
@@ -4,14 +4,13 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{stomp}
8
- s.version = "1.2.16"
9
- s.license = "Apache 2.0"
7
+ s.name = "stomp"
8
+ s.version = "1.3.0"
10
9
 
11
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
11
  s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
13
- s.date = %q{2013-08-19}
14
- s.description = %q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
12
+ s.date = "2013-09-30"
13
+ s.description = "Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge."
15
14
  s.email = ["brianm@apache.org", "marius@stones.com", "morellon@gmail.com", "allard.guy.m@gmail.com"]
16
15
  s.executables = ["catstomp", "stompcat"]
17
16
  s.extra_rdoc_files = [
@@ -31,7 +30,6 @@ Gem::Specification.new do |s|
31
30
  "examples/publisher.rb",
32
31
  "examples/put11conn_ex1.rb",
33
32
  "examples/putget11_rh1.rb",
34
- "examples/slogger.rb",
35
33
  "examples/ssl_uc1.rb",
36
34
  "examples/ssl_uc1_ciphers.rb",
37
35
  "examples/ssl_uc2.rb",
@@ -57,8 +55,11 @@ Gem::Specification.new do |s|
57
55
  "lib/stomp/errors.rb",
58
56
  "lib/stomp/ext/hash.rb",
59
57
  "lib/stomp/message.rb",
58
+ "lib/stomp/null_logger.rb",
59
+ "lib/stomp/slogger.rb",
60
60
  "lib/stomp/sslparams.rb",
61
61
  "lib/stomp/version.rb",
62
+ "test/test_anonymous.rb",
62
63
  "test/test_client.rb",
63
64
  "test/test_codec.rb",
64
65
  "test/test_connection.rb",
@@ -89,7 +90,6 @@ Gem::Specification.new do |s|
89
90
  "examples/publisher.rb",
90
91
  "examples/put11conn_ex1.rb",
91
92
  "examples/putget11_rh1.rb",
92
- "examples/slogger.rb",
93
93
  "examples/ssl_uc1.rb",
94
94
  "examples/ssl_uc1_ciphers.rb",
95
95
  "examples/ssl_uc2.rb",
@@ -115,6 +115,8 @@ Gem::Specification.new do |s|
115
115
  "lib/stomp/errors.rb",
116
116
  "lib/stomp/ext/hash.rb",
117
117
  "lib/stomp/message.rb",
118
+ "lib/stomp/null_logger.rb",
119
+ "lib/stomp/slogger.rb",
118
120
  "lib/stomp/sslparams.rb",
119
121
  "lib/stomp/version.rb",
120
122
  "notes/heartbeat_readme.txt",
@@ -124,6 +126,7 @@ Gem::Specification.new do |s|
124
126
  "spec/message_spec.rb",
125
127
  "spec/spec_helper.rb",
126
128
  "stomp.gemspec",
129
+ "test/test_anonymous.rb",
127
130
  "test/test_client.rb",
128
131
  "test/test_codec.rb",
129
132
  "test/test_connection.rb",
@@ -134,14 +137,14 @@ Gem::Specification.new do |s|
134
137
  "test/test_urlogin.rb",
135
138
  "test/tlogger.rb"
136
139
  ]
137
- s.homepage = %q{https://github.com/stompgem/stomp}
140
+ s.homepage = "https://github.com/stompgem/stomp"
141
+ s.licenses = ["Apache 2.0"]
138
142
  s.require_paths = ["lib"]
139
- s.rubygems_version = %q{1.3.7}
140
- s.summary = %q{Ruby client for the Stomp messaging protocol}
143
+ s.rubygems_version = "2.0.5"
144
+ s.summary = "Ruby client for the Stomp messaging protocol"
141
145
 
142
146
  if s.respond_to? :specification_version then
143
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
144
- s.specification_version = 3
147
+ s.specification_version = 4
145
148
 
146
149
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
147
150
  s.add_development_dependency(%q<rspec>, [">= 2.3"])