jruby-jms 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +9 -1
- data/Rakefile +1 -1
- data/examples/consumer.rb +1 -1
- data/examples/performance/consumer.rb +1 -1
- data/examples/performance/producer.rb +1 -1
- data/examples/producer.rb +1 -1
- data/lib/jms/connection.rb +19 -19
- data/lib/jms/javax_jms_message.rb +8 -8
- data/lib/jms/javax_jms_message_consumer.rb +7 -7
- data/lib/jms/javax_jms_queue_browser.rb +1 -1
- data/lib/jms/javax_jms_session.rb +38 -38
- data/lib/jms/logging.rb +15 -10
- data/lib/jms/message_listener.rb +2 -2
- data/test/connection_test.rb +4 -4
- data/test/message_test.rb +131 -0
- data/test/session_test.rb +0 -44
- metadata +4 -4
- data/lib/jms/logger.rb +0 -4
data/HISTORY.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.10.1 (2011-02-21)
|
2
|
+
|
3
|
+
* Fix persistence typo and add message test cases
|
4
|
+
|
5
|
+
## 0.10.0 (2011-02-10)
|
6
|
+
|
7
|
+
* Refactoring interface
|
8
|
+
|
1
9
|
## 0.9.0 (2011-01-23)
|
2
10
|
|
3
11
|
* Revised API with cleaner interface
|
@@ -10,4 +18,4 @@
|
|
10
18
|
## 2008, 2009, 2010
|
11
19
|
|
12
20
|
* Previously known as jms4jruby
|
13
|
-
* Running in production at an enterprise processing a million messages a day
|
21
|
+
* Running in production at an enterprise processing a million messages a day
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ desc "Build gem"
|
|
9
9
|
task :gem do |t|
|
10
10
|
gemspec = Gem::Specification.new do |s|
|
11
11
|
s.name = 'jruby-jms'
|
12
|
-
s.version = '0.10.
|
12
|
+
s.version = '0.10.1'
|
13
13
|
s.author = 'Reid Morrison'
|
14
14
|
s.email = 'rubywmq@gmail.com'
|
15
15
|
s.homepage = 'https://github.com/reidmorrison/jruby-jms'
|
data/examples/consumer.rb
CHANGED
@@ -17,7 +17,7 @@ config = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))[jms_provid
|
|
17
17
|
raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
|
18
18
|
|
19
19
|
JMS::Connection.session(config) do |session|
|
20
|
-
session.consume(:
|
20
|
+
session.consume(:queue_name => 'ExampleQueue', :timeout=>1000) do |message|
|
21
21
|
p message
|
22
22
|
end
|
23
23
|
end
|
@@ -17,7 +17,7 @@ config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_
|
|
17
17
|
raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
|
18
18
|
|
19
19
|
JMS::Connection.session(config) do |session|
|
20
|
-
session.consumer(:
|
20
|
+
session.consumer(:queue_name => 'ExampleQueue') do |consumer|
|
21
21
|
stats = consumer.each(:statistics => true) do |message|
|
22
22
|
puts "=================================="
|
23
23
|
p message
|
@@ -20,7 +20,7 @@ raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless con
|
|
20
20
|
JMS::Connection.session(config) do |session|
|
21
21
|
start_time = Time.now
|
22
22
|
|
23
|
-
session.producer(:
|
23
|
+
session.producer(:queue_name => 'ExampleQueue') do |producer|
|
24
24
|
count.times do |i|
|
25
25
|
producer.send(session.message("Hello Producer #{i}"))
|
26
26
|
end
|
data/examples/producer.rb
CHANGED
@@ -17,7 +17,7 @@ config = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))[jms_provid
|
|
17
17
|
raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
|
18
18
|
|
19
19
|
JMS::Connection.session(config) do |session|
|
20
|
-
session.producer(:
|
20
|
+
session.producer(:queue_name => 'ExampleQueue') do |producer|
|
21
21
|
producer.send(session.message("Hello World"))
|
22
22
|
end
|
23
23
|
end
|
data/lib/jms/connection.rb
CHANGED
@@ -40,7 +40,7 @@ module JMS
|
|
40
40
|
# :transport_type => com.ibm.mq.jms.JMSC::MQJMS_TP_CLIENT_MQ_TCPIP,
|
41
41
|
# :username => 'mqm'
|
42
42
|
# ) do |session|
|
43
|
-
# session.consumer(:
|
43
|
+
# session.consumer(:queue_name=>'TEST', :mode=>:input) do |consumer|
|
44
44
|
# if message = consumer.receive_no_wait
|
45
45
|
# puts "Data Received: #{message.data}"
|
46
46
|
# else
|
@@ -59,9 +59,9 @@ module JMS
|
|
59
59
|
# call the supplied code block, then close the connection upon completion
|
60
60
|
#
|
61
61
|
# Returns the result of the supplied block
|
62
|
-
def self.start(
|
62
|
+
def self.start(params = {}, &proc)
|
63
63
|
raise "Missing mandatory Block when calling JMS::Connection.start" unless proc
|
64
|
-
connection = Connection.new(
|
64
|
+
connection = Connection.new(params)
|
65
65
|
connection.start
|
66
66
|
begin
|
67
67
|
proc.call(connection)
|
@@ -77,9 +77,9 @@ module JMS
|
|
77
77
|
# Useful when only a single session is required in the current thread
|
78
78
|
#
|
79
79
|
# Note: It is important that each thread have its own session to support transactions
|
80
|
-
def self.session(
|
81
|
-
self.start(
|
82
|
-
connection.session(
|
80
|
+
def self.session(params = {}, &proc)
|
81
|
+
self.start(params) do |connection|
|
82
|
+
connection.session(params, &proc)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -287,9 +287,9 @@ module JMS
|
|
287
287
|
# :options => any of the javax.jms.Session constants
|
288
288
|
# Default: javax.jms.Session::AUTO_ACKNOWLEDGE
|
289
289
|
#
|
290
|
-
def session(
|
290
|
+
def session(params={}, &proc)
|
291
291
|
raise "Missing mandatory Block when calling JMS::Connection#session" unless proc
|
292
|
-
session = self.create_session(
|
292
|
+
session = self.create_session(params)
|
293
293
|
begin
|
294
294
|
proc.call(session)
|
295
295
|
ensure
|
@@ -328,9 +328,9 @@ module JMS
|
|
328
328
|
# session is transacted.
|
329
329
|
# Default: javax.jms.Session::AUTO_ACKNOWLEDGE
|
330
330
|
#
|
331
|
-
def create_session(
|
332
|
-
transacted =
|
333
|
-
options =
|
331
|
+
def create_session(params={})
|
332
|
+
transacted = params[:transacted] || false
|
333
|
+
options = params[:options] || javax.jms.Session::AUTO_ACKNOWLEDGE
|
334
334
|
@jms_connection.create_session(transacted, options)
|
335
335
|
end
|
336
336
|
|
@@ -425,13 +425,13 @@ module JMS
|
|
425
425
|
# Default: 1
|
426
426
|
#
|
427
427
|
# Consumer Parameters:
|
428
|
-
# :
|
428
|
+
# :queue_name => String: Name of the Queue to return
|
429
429
|
# Symbol: :temporary => Create temporary queue
|
430
430
|
# Mandatory unless :topic_name is supplied
|
431
431
|
# Or,
|
432
432
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
433
433
|
# Symbol: :temporary => Create temporary topic
|
434
|
-
# Mandatory unless :
|
434
|
+
# Mandatory unless :queue_name is supplied
|
435
435
|
# Or,
|
436
436
|
# :destination=> Explicit javaxJms::Destination to use
|
437
437
|
#
|
@@ -461,15 +461,15 @@ module JMS
|
|
461
461
|
# Note: Also supply connection::on_exception so that connection failures can be handled
|
462
462
|
#
|
463
463
|
#
|
464
|
-
def on_message(
|
464
|
+
def on_message(params, &proc)
|
465
465
|
raise "JMS::Connection must be connected prior to calling JMS::Connection::on_message" unless @sessions && @consumers
|
466
466
|
|
467
|
-
consumer_count =
|
467
|
+
consumer_count = params[:session_count] || 1
|
468
468
|
consumer_count.times do
|
469
|
-
session = self.create_session(
|
470
|
-
consumer = session.consumer(
|
469
|
+
session = self.create_session(params)
|
470
|
+
consumer = session.consumer(params)
|
471
471
|
if session.transacted?
|
472
|
-
consumer.on_message(
|
472
|
+
consumer.on_message(params) do |message|
|
473
473
|
begin
|
474
474
|
proc.call(message) ? session.commit : session.rollback
|
475
475
|
rescue => exc
|
@@ -478,7 +478,7 @@ module JMS
|
|
478
478
|
end
|
479
479
|
end
|
480
480
|
else
|
481
|
-
consumer.on_message(
|
481
|
+
consumer.on_message(params, &proc)
|
482
482
|
end
|
483
483
|
@consumers << consumer
|
484
484
|
@sessions << session
|
@@ -57,15 +57,15 @@ module javax.jms::Message
|
|
57
57
|
# Header Fields - Attributes of the message
|
58
58
|
|
59
59
|
# Return the JMS Delivery Mode as a symbol
|
60
|
-
# :
|
61
|
-
# :
|
60
|
+
# :persistent
|
61
|
+
# :non_persistent
|
62
62
|
# other: Value from javax.jms.DeliveryMode
|
63
63
|
def jms_delivery_mode
|
64
64
|
case getJMSDeliveryMode
|
65
65
|
when javax.jms.DeliveryMode::PERSISTENT
|
66
|
-
:
|
66
|
+
:persistent
|
67
67
|
when javax.jms.DeliveryMode::NON_PERSISTENT
|
68
|
-
:
|
68
|
+
:non_persistent
|
69
69
|
else
|
70
70
|
getJMSDeliveryMode
|
71
71
|
end
|
@@ -73,14 +73,14 @@ module javax.jms::Message
|
|
73
73
|
|
74
74
|
# Set the JMS Delivery Mode
|
75
75
|
# Valid values for mode
|
76
|
-
# :
|
77
|
-
# :
|
76
|
+
# :persistent
|
77
|
+
# :non_persistent
|
78
78
|
# other: Any constant from javax.jms.DeliveryMode
|
79
79
|
def jms_delivery_mode=(mode)
|
80
80
|
val = case mode
|
81
|
-
when :
|
81
|
+
when :persistent
|
82
82
|
javax.jms.DeliveryMode::PERSISTENT
|
83
|
-
when :
|
83
|
+
when :non_persistent
|
84
84
|
javax.jms.DeliveryMode::NON_PERSISTENT
|
85
85
|
else
|
86
86
|
mode
|
@@ -24,8 +24,8 @@ module javax.jms::MessageConsumer
|
|
24
24
|
# Note: Messages may still be on the queue, but the broker has not supplied any messages
|
25
25
|
# in the time interval specified
|
26
26
|
# Default: 0
|
27
|
-
def get(
|
28
|
-
timeout =
|
27
|
+
def get(params={})
|
28
|
+
timeout = params[:timeout] || 0
|
29
29
|
if timeout == -1
|
30
30
|
self.receive
|
31
31
|
elsif timeout == 0
|
@@ -54,19 +54,19 @@ module javax.jms::MessageConsumer
|
|
54
54
|
# with :statistics => true
|
55
55
|
#
|
56
56
|
# The statistics gathered are returned when :statistics => true and :async => false
|
57
|
-
def each(
|
57
|
+
def each(params={}, &proc)
|
58
58
|
raise "Destination::each requires a code block to be executed for each message received" unless proc
|
59
59
|
|
60
60
|
message_count = nil
|
61
61
|
start_time = nil
|
62
62
|
|
63
|
-
if
|
63
|
+
if params[:statistics]
|
64
64
|
message_count = 0
|
65
65
|
start_time = Time.now
|
66
66
|
end
|
67
67
|
|
68
68
|
# Receive messages according to timeout
|
69
|
-
while message = self.get(
|
69
|
+
while message = self.get(params) do
|
70
70
|
proc.call(message)
|
71
71
|
message_count += 1 if message_count
|
72
72
|
end
|
@@ -97,10 +97,10 @@ module javax.jms::MessageConsumer
|
|
97
97
|
#
|
98
98
|
# The statistics gathered are returned when :statistics => true and :async => false
|
99
99
|
#
|
100
|
-
def on_message(
|
100
|
+
def on_message(params={}, &proc)
|
101
101
|
raise "MessageConsumer::on_message requires a code block to be executed for each message received" unless proc
|
102
102
|
|
103
|
-
@listener = JMS::MessageListener.new(
|
103
|
+
@listener = JMS::MessageListener.new(params,&proc)
|
104
104
|
self.setMessageListener @listener
|
105
105
|
end
|
106
106
|
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
module javax.jms::QueueBrowser
|
18
18
|
# For each message on the queue call the supplied Proc
|
19
|
-
def each(
|
19
|
+
def each(params={}, &proc)
|
20
20
|
raise "javax.jms.QueueBrowser::each requires a code block to be executed for each message received" unless proc
|
21
21
|
|
22
22
|
e = self.getEnumeration
|
@@ -161,19 +161,19 @@ module javax.jms::Session
|
|
161
161
|
# Or,
|
162
162
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
163
163
|
# Symbol: :temporary => Create temporary topic
|
164
|
-
# Mandatory unless :
|
164
|
+
# Mandatory unless :queue_name is supplied
|
165
165
|
# Or,
|
166
166
|
# :destination=> Explicit javaxJms::Destination to use
|
167
167
|
#
|
168
168
|
# Returns the result of the supplied block
|
169
|
-
def create_destination(
|
169
|
+
def create_destination(params)
|
170
170
|
# Allow a Java JMS destination object to be passed in
|
171
|
-
return
|
171
|
+
return params[:destination] if params[:destination] && params[:destination].java_kind_of?(javax.jms::Destination)
|
172
172
|
|
173
|
-
# :
|
174
|
-
queue_name =
|
175
|
-
topic_name =
|
176
|
-
raise "Missing mandatory parameter :
|
173
|
+
# :queue_name is deprecated
|
174
|
+
queue_name = params[:queue_name] || params[:queue_name]
|
175
|
+
topic_name = params[:topic_name]
|
176
|
+
raise "Missing mandatory parameter :queue_name or :topic_name to Session::producer, Session::consumer, or Session::browser" unless queue_name || topic_name
|
177
177
|
|
178
178
|
if queue_name
|
179
179
|
queue_name == :temporary ? create_temporary_queue : create_queue(queue_name)
|
@@ -208,16 +208,16 @@ module javax.jms::Session
|
|
208
208
|
# Or,
|
209
209
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
210
210
|
# Symbol: :temporary => Create temporary topic
|
211
|
-
# Mandatory unless :
|
211
|
+
# Mandatory unless :queue_name is supplied
|
212
212
|
# Or,
|
213
213
|
# :destination=> Explicit javaxJms::Destination to use
|
214
214
|
#
|
215
215
|
# Returns the result of the supplied block
|
216
|
-
def destination(
|
216
|
+
def destination(params={}, &block)
|
217
217
|
raise "Missing mandatory Block when calling JMS::Session#destination" unless block
|
218
218
|
dest = nil
|
219
219
|
begin
|
220
|
-
dest = create_destination(
|
220
|
+
dest = create_destination(params)
|
221
221
|
block.call(dest)
|
222
222
|
ensure
|
223
223
|
# Delete Temporary Queue / Topic
|
@@ -283,17 +283,17 @@ module javax.jms::Session
|
|
283
283
|
# Call the Proc if supplied, then automatically close the producer
|
284
284
|
#
|
285
285
|
# Parameters:
|
286
|
-
# :
|
286
|
+
# :queue_name => String: Name of the Queue to return
|
287
287
|
# Symbol: :temporary => Create temporary queue
|
288
288
|
# Mandatory unless :topic_name is supplied
|
289
289
|
# Or,
|
290
290
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
291
291
|
# Symbol: :temporary => Create temporary topic
|
292
|
-
# Mandatory unless :
|
292
|
+
# Mandatory unless :queue_name is supplied
|
293
293
|
# Or,
|
294
294
|
# :destination=> Explicit javax.jms::Destination to use
|
295
|
-
def producer(
|
296
|
-
destination = create_destination(
|
295
|
+
def producer(params, &proc)
|
296
|
+
destination = create_destination(params)
|
297
297
|
# Call original java method with this destination
|
298
298
|
#p = java_send :create_producer, [javax.jms::Destination], destination
|
299
299
|
p = create_producer(destination)
|
@@ -314,13 +314,13 @@ module javax.jms::Session
|
|
314
314
|
# Call the Proc if supplied, then automatically close the consumer
|
315
315
|
#
|
316
316
|
# Parameters:
|
317
|
-
# :
|
317
|
+
# :queue_name => String: Name of the Queue to return
|
318
318
|
# Symbol: :temporary => Create temporary queue
|
319
319
|
# Mandatory unless :topic_name is supplied
|
320
320
|
# Or,
|
321
321
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
322
322
|
# Symbol: :temporary => Create temporary topic
|
323
|
-
# Mandatory unless :
|
323
|
+
# Mandatory unless :queue_name is supplied
|
324
324
|
# Or,
|
325
325
|
# :destination=> Explicit javaxJms::Destination to use
|
326
326
|
#
|
@@ -329,13 +329,13 @@ module javax.jms::Session
|
|
329
329
|
# :no_local => Determine whether messages published by its own connection
|
330
330
|
# should be delivered to it
|
331
331
|
# Default: false
|
332
|
-
def consumer(
|
333
|
-
destination = create_destination(
|
332
|
+
def consumer(params, &proc)
|
333
|
+
destination = create_destination(params)
|
334
334
|
c = nil
|
335
|
-
if
|
336
|
-
c = create_consumer(destination,
|
337
|
-
elsif
|
338
|
-
c = create_consumer(destination,
|
335
|
+
if params[:no_local]
|
336
|
+
c = create_consumer(destination, params[:selector] || '', params[:no_local])
|
337
|
+
elsif params[:selector]
|
338
|
+
c = create_consumer(destination, params[:selector])
|
339
339
|
else
|
340
340
|
c = create_consumer(destination)
|
341
341
|
end
|
@@ -355,13 +355,13 @@ module javax.jms::Session
|
|
355
355
|
# A consumer can read messages from the queue or topic
|
356
356
|
#
|
357
357
|
# Parameters:
|
358
|
-
# :
|
358
|
+
# :queue_name => String: Name of the Queue to return
|
359
359
|
# Symbol: :temporary => Create temporary queue
|
360
360
|
# Mandatory unless :topic_name is supplied
|
361
361
|
# Or,
|
362
362
|
# :topic_name => String: Name of the Topic to write to or subscribe to
|
363
363
|
# Symbol: :temporary => Create temporary topic
|
364
|
-
# Mandatory unless :
|
364
|
+
# Mandatory unless :queue_name is supplied
|
365
365
|
# Or,
|
366
366
|
# :destination=> Explicit javaxJms::Destination to use
|
367
367
|
#
|
@@ -379,10 +379,10 @@ module javax.jms::Session
|
|
379
379
|
# in the time interval specified
|
380
380
|
# Default: 0
|
381
381
|
#
|
382
|
-
def consume(
|
383
|
-
c = self.consumer(
|
382
|
+
def consume(params, &proc)
|
383
|
+
c = self.consumer(params)
|
384
384
|
begin
|
385
|
-
c.each(
|
385
|
+
c.each(params, &proc)
|
386
386
|
ensure
|
387
387
|
c.close
|
388
388
|
end
|
@@ -395,7 +395,7 @@ module javax.jms::Session
|
|
395
395
|
# Call the Proc if supplied, then automatically close the consumer
|
396
396
|
#
|
397
397
|
# Parameters:
|
398
|
-
# :
|
398
|
+
# :queue_name => String: Name of the Queue to return
|
399
399
|
# Symbol: :temporary => Create temporary queue
|
400
400
|
# Mandatory unless :topic_name is supplied
|
401
401
|
# Or,
|
@@ -403,13 +403,13 @@ module javax.jms::Session
|
|
403
403
|
#
|
404
404
|
# :selector => Filter which messages should be returned from the queue
|
405
405
|
# Default: All messages
|
406
|
-
def browser(
|
406
|
+
def browser(params, &proc)
|
407
407
|
raise "Session::browser requires a code block to be executed" unless proc
|
408
408
|
|
409
|
-
destination = create_destination(
|
409
|
+
destination = create_destination(params)
|
410
410
|
b = nil
|
411
|
-
if
|
412
|
-
b = create_browser(destination,
|
411
|
+
if params[:selector]
|
412
|
+
b = create_browser(destination, params[:selector])
|
413
413
|
else
|
414
414
|
b = create_browser(destination)
|
415
415
|
end
|
@@ -428,7 +428,7 @@ module javax.jms::Session
|
|
428
428
|
# Browse the specified queue, calling the Proc supplied for each message found
|
429
429
|
#
|
430
430
|
# Parameters:
|
431
|
-
# :
|
431
|
+
# :queue_name => String: Name of the Queue to return
|
432
432
|
# Symbol: :temporary => Create temporary queue
|
433
433
|
# Mandatory unless :topic_name is supplied
|
434
434
|
# Or,
|
@@ -436,19 +436,19 @@ module javax.jms::Session
|
|
436
436
|
#
|
437
437
|
# :selector => Filter which messages should be returned from the queue
|
438
438
|
# Default: All messages
|
439
|
-
def browse(
|
440
|
-
self.browser(
|
439
|
+
def browse(params={}, &proc)
|
440
|
+
self.browser(params) {|b| b.each(params, &proc)}
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
444
444
|
# Workaround for IBM MQ JMS implementation that implements an undocumented consume method
|
445
445
|
if defined? com.ibm.mq.jms::MQSession
|
446
446
|
class com.ibm.mq.jms::MQSession
|
447
|
-
def consume(
|
447
|
+
def consume(params, &proc)
|
448
448
|
result = nil
|
449
|
-
c = self.consumer(
|
449
|
+
c = self.consumer(params)
|
450
450
|
begin
|
451
|
-
result = c.each(
|
451
|
+
result = c.each(params, &proc)
|
452
452
|
ensure
|
453
453
|
c.close
|
454
454
|
end
|
data/lib/jms/logging.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
module JMS
|
3
3
|
|
4
4
|
# Returns the logger being used by jruby-jms
|
5
|
+
# Unless previously set, it will try to use the Rails logger and if it
|
6
|
+
# is not present, it will return a new Ruby logger
|
5
7
|
def self.logger
|
6
|
-
@logger ||= (rails_logger ||
|
8
|
+
@logger ||= (self.rails_logger || self.ruby_logger)
|
7
9
|
end
|
8
10
|
|
9
11
|
# Replace the logger for jruby-jms
|
@@ -11,19 +13,22 @@ module JMS
|
|
11
13
|
@logger = logger
|
12
14
|
end
|
13
15
|
|
16
|
+
# Use the ruby logger, but add needed trace level logging which will result
|
17
|
+
# in debug log entries
|
18
|
+
def self.ruby_logger(level=nil, target=STDOUT)
|
19
|
+
require 'logger'
|
20
|
+
|
21
|
+
l = ::Logger.new(target)
|
22
|
+
l.instance_eval "alias :trace :debug"
|
23
|
+
l.instance_eval "alias :trace? :debug?"
|
24
|
+
l.level = level || ::Logger::INFO
|
25
|
+
l
|
26
|
+
end
|
27
|
+
|
14
28
|
private
|
15
29
|
def self.rails_logger
|
16
30
|
(defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
|
17
31
|
(defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
|
18
32
|
end
|
19
33
|
|
20
|
-
# By default we use the standard Ruby Logger
|
21
|
-
def self.default_logger
|
22
|
-
require 'logger'
|
23
|
-
require 'jms/logger'
|
24
|
-
l = Logger.new(STDOUT)
|
25
|
-
l.level = Logger::INFO
|
26
|
-
l
|
27
|
-
end
|
28
|
-
|
29
34
|
end
|
data/lib/jms/message_listener.rb
CHANGED
@@ -32,10 +32,10 @@ module JMS
|
|
32
32
|
# is called again with :statistics => true
|
33
33
|
#
|
34
34
|
# The statistics gathered are returned when :statistics => true and :async => false
|
35
|
-
def initialize(
|
35
|
+
def initialize(params={}, &proc)
|
36
36
|
@proc = proc
|
37
37
|
|
38
|
-
if
|
38
|
+
if params[:statistics]
|
39
39
|
@message_count = 0
|
40
40
|
@start_time = Time.now
|
41
41
|
end
|
data/test/connection_test.rb
CHANGED
@@ -86,7 +86,7 @@ class JMSTest < Test::Unit::TestCase
|
|
86
86
|
assert_nil connection.close
|
87
87
|
end
|
88
88
|
|
89
|
-
should 'Create a session from the connection with
|
89
|
+
should 'Create a session from the connection with params' do
|
90
90
|
connection = JMS::Connection.new(@config)
|
91
91
|
|
92
92
|
session_parms = {
|
@@ -105,7 +105,7 @@ class JMSTest < Test::Unit::TestCase
|
|
105
105
|
assert_nil connection.close
|
106
106
|
end
|
107
107
|
|
108
|
-
should 'Create a session from the connection with block and
|
108
|
+
should 'Create a session from the connection with block and params' do
|
109
109
|
JMS::Connection.start(@config) do |connection|
|
110
110
|
|
111
111
|
session_parms = {
|
@@ -122,7 +122,7 @@ class JMSTest < Test::Unit::TestCase
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
should 'Create a session from the connection with block and
|
125
|
+
should 'Create a session from the connection with block and params opposite test' do
|
126
126
|
JMS::Connection.start(@config) do |connection|
|
127
127
|
|
128
128
|
session_parms = {
|
@@ -143,7 +143,7 @@ class JMSTest < Test::Unit::TestCase
|
|
143
143
|
should 'start an on_message handler' do
|
144
144
|
JMS::Connection.start(@config) do |connection|
|
145
145
|
value = nil
|
146
|
-
connection.on_message(:transacted => true, :
|
146
|
+
connection.on_message(:transacted => true, :queue_name => :temporary) do |message|
|
147
147
|
value = "received"
|
148
148
|
end
|
149
149
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Allow examples to be run in-place without requiring a gem install
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'jms'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
class JMSTest < Test::Unit::TestCase
|
11
|
+
context 'JMS Session' do
|
12
|
+
# Load configuration from jms.yml
|
13
|
+
setup do
|
14
|
+
# To change the JMS provider, edit jms.yml and change :default
|
15
|
+
|
16
|
+
# Load Connection parameters from configuration file
|
17
|
+
cfg = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))
|
18
|
+
jms_provider = cfg['default']
|
19
|
+
@config = cfg[jms_provider]
|
20
|
+
raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless @config
|
21
|
+
@queue_name = @config[:queue_name] || raise("Mandatory :queue_name missing from jms.yml")
|
22
|
+
@topic_name = @config[:topic_name] || raise("Mandatory :topic_name missing from jms.yml")
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'produce and consume messages to/from a temporary queue' do
|
26
|
+
JMS::Connection.session(@config) do |session|
|
27
|
+
assert_not_nil session
|
28
|
+
data = nil
|
29
|
+
session.producer(:queue_name => :temporary) do |producer|
|
30
|
+
# Send Message
|
31
|
+
producer.send(session.message('Hello World'))
|
32
|
+
|
33
|
+
# Consume Message
|
34
|
+
session.consume(:destination => producer.destination) do |message|
|
35
|
+
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
36
|
+
data = message.data
|
37
|
+
end
|
38
|
+
end
|
39
|
+
assert_equal data, 'Hello World'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'produce, browse and consume messages to/from a queue' do
|
44
|
+
JMS::Connection.session(@config) do |session|
|
45
|
+
assert_not_nil session
|
46
|
+
data = nil
|
47
|
+
browse_data = nil
|
48
|
+
session.producer(:queue_name => @queue_name) do |producer|
|
49
|
+
# Send Message
|
50
|
+
producer.send(session.message('Hello World'))
|
51
|
+
|
52
|
+
# Browse Message
|
53
|
+
session.browse(:queue_name => @queue_name) do |message|
|
54
|
+
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
55
|
+
browse_data = message.data
|
56
|
+
end
|
57
|
+
|
58
|
+
# Consume Message
|
59
|
+
session.consume(:queue_name => @queue_name) do |message|
|
60
|
+
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
61
|
+
data = message.data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
assert_equal 'Hello World', data
|
65
|
+
assert_equal 'Hello World', browse_data
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should 'support setting persistence using symbols and the java constants' do
|
70
|
+
JMS::Connection.session(@config) do |session|
|
71
|
+
message = session.message('Hello World')
|
72
|
+
assert_equal message.jms_delivery_mode, :non_persistent
|
73
|
+
message.jms_delivery_mode = :non_persistent
|
74
|
+
assert_equal message.jms_delivery_mode, :non_persistent
|
75
|
+
message.jms_delivery_mode = :persistent
|
76
|
+
assert_equal message.jms_delivery_mode, :persistent
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'produce and consume non-persistent messages' do
|
81
|
+
JMS::Connection.session(@config) do |session|
|
82
|
+
assert_not_nil session
|
83
|
+
data = nil
|
84
|
+
session.producer(:queue_name => :temporary) do |producer|
|
85
|
+
message = session.message('Hello World')
|
86
|
+
message.jms_delivery_mode = :non_persistent
|
87
|
+
assert_equal :non_persistent, message.jms_delivery_mode
|
88
|
+
assert_equal false, message.persistent?
|
89
|
+
|
90
|
+
# Send Message
|
91
|
+
producer.send(message)
|
92
|
+
|
93
|
+
# Consume Message
|
94
|
+
session.consume(:destination => producer.destination) do |message|
|
95
|
+
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
96
|
+
data = message.data
|
97
|
+
#assert_equal :non_persistent, message.jms_delivery_mode
|
98
|
+
#assert_equal false, message.persistent?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
assert_equal data, 'Hello World'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'produce and consume persistent messages' do
|
106
|
+
JMS::Connection.session(@config) do |session|
|
107
|
+
assert_not_nil session
|
108
|
+
data = nil
|
109
|
+
session.producer(:queue_name => :temporary) do |producer|
|
110
|
+
message = session.message('Hello World')
|
111
|
+
message.jms_delivery_mode = :persistent
|
112
|
+
assert_equal :persistent, message.jms_delivery_mode
|
113
|
+
assert_equal true, message.persistent?
|
114
|
+
|
115
|
+
# Send Message
|
116
|
+
producer.send(message)
|
117
|
+
|
118
|
+
# Consume Message
|
119
|
+
session.consume(:destination => producer.destination) do |message|
|
120
|
+
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
121
|
+
data = message.data
|
122
|
+
assert_equal :persistent, message.jms_delivery_mode
|
123
|
+
assert_equal true, message.persistent?
|
124
|
+
end
|
125
|
+
end
|
126
|
+
assert_equal data, 'Hello World'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
data/test/session_test.rb
CHANGED
@@ -136,49 +136,5 @@ class JMSTest < Test::Unit::TestCase
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
should 'produce and consume messages to/from a temporary queue' do
|
140
|
-
JMS::Connection.session(@config) do |session|
|
141
|
-
assert_not_nil session
|
142
|
-
data = nil
|
143
|
-
session.producer(:queue_name => :temporary) do |producer|
|
144
|
-
# Send Message
|
145
|
-
producer.send(session.message('Hello World'))
|
146
|
-
|
147
|
-
# Consume Message
|
148
|
-
session.consume(:destination => producer.destination) do |message|
|
149
|
-
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
150
|
-
data = message.data
|
151
|
-
end
|
152
|
-
end
|
153
|
-
assert_equal data, 'Hello World'
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
should 'produce, browse and consume messages to/from a queue' do
|
158
|
-
JMS::Connection.session(@config) do |session|
|
159
|
-
assert_not_nil session
|
160
|
-
data = nil
|
161
|
-
browse_data = nil
|
162
|
-
session.producer(:queue_name => @queue_name) do |producer|
|
163
|
-
# Send Message
|
164
|
-
producer.send(session.message('Hello World'))
|
165
|
-
|
166
|
-
# Browse Message
|
167
|
-
session.browse(:queue_name => @queue_name) do |message|
|
168
|
-
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
169
|
-
browse_data = message.data
|
170
|
-
end
|
171
|
-
|
172
|
-
# Consume Message
|
173
|
-
session.consume(:queue_name => @queue_name) do |message|
|
174
|
-
assert_equal message.java_kind_of?(javax.jms::TextMessage), true
|
175
|
-
data = message.data
|
176
|
-
end
|
177
|
-
end
|
178
|
-
assert_equal data, 'Hello World'
|
179
|
-
assert_equal browse_data, 'Hello World'
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
139
|
end
|
184
140
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 10
|
8
|
-
-
|
9
|
-
version: 0.10.
|
8
|
+
- 1
|
9
|
+
version: 0.10.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Reid Morrison
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-21 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -45,11 +45,11 @@ files:
|
|
45
45
|
- lib/jms/javax_jms_queue_browser.rb
|
46
46
|
- lib/jms/javax_jms_session.rb
|
47
47
|
- lib/jms/javax_jms_text_message.rb
|
48
|
-
- lib/jms/logger.rb
|
49
48
|
- lib/jms/logging.rb
|
50
49
|
- lib/jms/message_listener.rb
|
51
50
|
- test/connection_test.rb
|
52
51
|
- test/jms.yml
|
52
|
+
- test/message_test.rb
|
53
53
|
- test/session_test.rb
|
54
54
|
has_rdoc: true
|
55
55
|
homepage: https://github.com/reidmorrison/jruby-jms
|
data/lib/jms/logger.rb
DELETED