jruby-jms 1.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +36 -0
- data/HISTORY.md +52 -0
- data/LICENSE.txt +201 -0
- data/README.md +205 -0
- data/Rakefile +30 -0
- data/examples/advanced/session_pool.rb +37 -0
- data/examples/client-server/replier.rb +29 -0
- data/examples/client-server/requestor.rb +40 -0
- data/examples/file-to-q/files_to_q.rb +51 -0
- data/examples/file-to-q/q_to_files.rb +44 -0
- data/examples/invm/invm.rb +44 -0
- data/examples/invm/log4j.properties +58 -0
- data/examples/jms.yml +149 -0
- data/examples/performance/consumer.rb +25 -0
- data/examples/performance/producer.rb +31 -0
- data/examples/producer-consumer/browser.rb +24 -0
- data/examples/producer-consumer/consumer.rb +24 -0
- data/examples/producer-consumer/consumer_async.rb +41 -0
- data/examples/producer-consumer/producer.rb +25 -0
- data/examples/publish-subscribe/publish.rb +24 -0
- data/examples/publish-subscribe/subscribe.rb +31 -0
- data/lib/jms.rb +20 -0
- data/lib/jms/bytes_message.rb +52 -0
- data/lib/jms/connection.rb +529 -0
- data/lib/jms/imports.rb +21 -0
- data/lib/jms/logging.rb +50 -0
- data/lib/jms/map_message.rb +91 -0
- data/lib/jms/message.rb +285 -0
- data/lib/jms/message_consumer.rb +117 -0
- data/lib/jms/message_listener_impl.rb +79 -0
- data/lib/jms/message_producer.rb +59 -0
- data/lib/jms/mq_workaround.rb +70 -0
- data/lib/jms/object_message.rb +26 -0
- data/lib/jms/oracle_a_q_connection_factory.rb +48 -0
- data/lib/jms/queue_browser.rb +28 -0
- data/lib/jms/session.rb +473 -0
- data/lib/jms/session_pool.rb +168 -0
- data/lib/jms/text_message.rb +31 -0
- data/lib/jms/version.rb +3 -0
- data/nbproject/private/private.properties +3 -0
- data/nbproject/private/rake-d.txt +5 -0
- data/parallel_minion.gemspec +21 -0
- data/test/connection_test.rb +160 -0
- data/test/jms.yml +111 -0
- data/test/log4j.properties +32 -0
- data/test/message_test.rb +130 -0
- data/test/session_pool_test.rb +86 -0
- data/test/session_test.rb +140 -0
- metadata +113 -0
data/lib/jms/imports.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Import Java classes into JMS Namespace
|
2
|
+
module JMS
|
3
|
+
java_import 'javax.jms.DeliveryMode'
|
4
|
+
java_import 'javax.jms.Message'
|
5
|
+
java_import 'javax.jms.BytesMessage'
|
6
|
+
java_import 'javax.jms.TextMessage'
|
7
|
+
java_import 'javax.jms.MapMessage'
|
8
|
+
java_import 'javax.jms.ObjectMessage'
|
9
|
+
java_import 'javax.jms.StreamMessage'
|
10
|
+
java_import 'javax.jms.Session'
|
11
|
+
java_import 'javax.jms.Destination'
|
12
|
+
java_import 'javax.jms.Queue'
|
13
|
+
java_import 'javax.jms.Topic'
|
14
|
+
java_import 'javax.jms.TemporaryQueue'
|
15
|
+
java_import 'javax.jms.TemporaryTopic'
|
16
|
+
java_import 'javax.jms.MessageConsumer'
|
17
|
+
java_import 'javax.jms.MessageProducer'
|
18
|
+
java_import 'javax.jms.QueueBrowser'
|
19
|
+
java_import 'javax.jms.MessageListener'
|
20
|
+
java_import 'javax.jms.ExceptionListener'
|
21
|
+
end
|
data/lib/jms/logging.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
# Add Logging capabilities
|
18
|
+
module JMS
|
19
|
+
|
20
|
+
# Returns the logger being used by jruby-jms
|
21
|
+
# Unless previously set, it will try to use the Rails logger and if it
|
22
|
+
# is not present, it will return a new Ruby logger
|
23
|
+
def self.logger
|
24
|
+
@logger ||= (self.rails_logger || self.ruby_logger)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Replace the logger for jruby-jms
|
28
|
+
def self.logger=(logger)
|
29
|
+
@logger = logger
|
30
|
+
end
|
31
|
+
|
32
|
+
# Use the ruby logger, but add needed trace level logging which will result
|
33
|
+
# in debug log entries
|
34
|
+
def self.ruby_logger(level=nil, target=STDOUT)
|
35
|
+
require 'logger'
|
36
|
+
|
37
|
+
l = ::Logger.new(target)
|
38
|
+
l.instance_eval "alias :trace :debug"
|
39
|
+
l.instance_eval "alias :trace? :debug?"
|
40
|
+
l.level = level || ::Logger::INFO
|
41
|
+
l
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def self.rails_logger
|
46
|
+
(defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
|
47
|
+
(defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#Interface javax.jms.MapMessage
|
18
|
+
module JMS::MapMessage
|
19
|
+
# Since each is defined, add support for: inject, map, include?, and find_all?
|
20
|
+
# <=> also allows support for: min, max, and sort
|
21
|
+
include Enumerable
|
22
|
+
|
23
|
+
# Return Map Message as a hash
|
24
|
+
def to_h
|
25
|
+
h = {}
|
26
|
+
each_pair {|key, value| h[key] = value}
|
27
|
+
h
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return Map Message as a hash
|
31
|
+
def data
|
32
|
+
to_h
|
33
|
+
end
|
34
|
+
|
35
|
+
# Copy values from supplied hash into this MapMessage
|
36
|
+
# Converts Ruby types to Java native Data types as follows:
|
37
|
+
# Fixnum => long
|
38
|
+
# Float => double
|
39
|
+
# Bignum => long
|
40
|
+
# true => boolean
|
41
|
+
# false => boolean
|
42
|
+
# nil => null
|
43
|
+
# Otherwise it calls ::to_s on the supplied data type
|
44
|
+
def data=(data)
|
45
|
+
data.each_pair do |key,val|
|
46
|
+
case
|
47
|
+
when val.class == Fixnum # 1
|
48
|
+
setLong(key.to_s,val)
|
49
|
+
when val.class == Float #1.1
|
50
|
+
setDouble(key.to_s,val)
|
51
|
+
when val.class == Bignum # 11111111111111111
|
52
|
+
setLong(key.to_s,val)
|
53
|
+
when (val.class == TrueClass) || (val.class == FalseClass)
|
54
|
+
setBoolean(key.to_s,val)
|
55
|
+
when val.class == NilClass
|
56
|
+
setObject(key.to_s,val)
|
57
|
+
else
|
58
|
+
setString(key.to_s,val.to_s)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Return each name value pair
|
64
|
+
def each(&proc)
|
65
|
+
# When key and value are expected separately. Should actually be calling each_pair anyway
|
66
|
+
if proc.arity == 2
|
67
|
+
each_pair(proc)
|
68
|
+
else
|
69
|
+
enum = getMapNames
|
70
|
+
while enum.has_more_elements
|
71
|
+
key = enum.next_element
|
72
|
+
proc.call [key, getObject(key)]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Return each name value pair
|
78
|
+
def each_pair(&proc)
|
79
|
+
enum = getMapNames
|
80
|
+
while enum.has_more_elements
|
81
|
+
key = enum.next_element
|
82
|
+
proc.call key, getObject(key)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Does map include specified key
|
87
|
+
def include?(key)
|
88
|
+
# Ensure a Ruby true is returned
|
89
|
+
item_exists(key) == true
|
90
|
+
end
|
91
|
+
end
|
data/lib/jms/message.rb
ADDED
@@ -0,0 +1,285 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
# Extend JMS Message Interface with Ruby methods
|
18
|
+
#
|
19
|
+
# A Message is the item that can be put on a queue, or obtained from a queue.
|
20
|
+
#
|
21
|
+
# A Message consists of 3 major parts:
|
22
|
+
# - Header
|
23
|
+
# Accessible as attributes of the Message class
|
24
|
+
# - Properties
|
25
|
+
# Accessible via [] and []= methods
|
26
|
+
# - Data
|
27
|
+
# The actual data portion of the message
|
28
|
+
# See the specific message types for details on how to access the data
|
29
|
+
# portion of the message
|
30
|
+
#
|
31
|
+
# For further help on javax.jms.Message
|
32
|
+
# http://download.oracle.com/javaee/6/api/index.html?javax/jms/Message.html
|
33
|
+
#
|
34
|
+
# Interface javax.jms.Message
|
35
|
+
module JMS::Message
|
36
|
+
|
37
|
+
# Methods directly exposed from the Java class:
|
38
|
+
|
39
|
+
# call-seq:
|
40
|
+
# acknowledge
|
41
|
+
#
|
42
|
+
# Acknowledges all consumed messages of the session of this consumed message
|
43
|
+
#
|
44
|
+
|
45
|
+
# call-seq:
|
46
|
+
# clear_body
|
47
|
+
#
|
48
|
+
# Clears out the message body
|
49
|
+
#
|
50
|
+
|
51
|
+
# call-seq:
|
52
|
+
# clear_properties
|
53
|
+
#
|
54
|
+
# Clears out the properties of this message
|
55
|
+
#
|
56
|
+
|
57
|
+
# For Backward compatibility with JRuby prior to 1.6
|
58
|
+
# JRuby 1.6 now does all this for us. Thank you headius :)
|
59
|
+
unless self.instance_methods.include? :jms_delivery_mode
|
60
|
+
|
61
|
+
# Header Fields - Attributes of the message
|
62
|
+
|
63
|
+
# Returns the JMS Delivery Mode
|
64
|
+
# One of the following will be returned
|
65
|
+
# JMS::DeliveryMode::PERSISTENT
|
66
|
+
# JMS::DeliveryMode::NON_PERSISTENT
|
67
|
+
def jms_delivery_mode
|
68
|
+
getJMSDeliveryMode
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set the JMS Delivery Mode
|
72
|
+
# Values can be
|
73
|
+
# JMS::DeliveryMode::PERSISTENT
|
74
|
+
# JMS::DeliveryMode::NON_PERSISTENT
|
75
|
+
def jms_delivery_mode=(mode)
|
76
|
+
raise "Sorry, due to incompatibility with JRuby 1.6, please call jms_delivery_mode_sym when using symbols" if mode.is_a? Symbol
|
77
|
+
self.setJMSDeliveryMode(mode)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Is the message persistent?
|
81
|
+
def persistent?
|
82
|
+
getJMSDeliveryMode == JMS::DeliveryMode::PERSISTENT
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the Message correlation ID as a String
|
86
|
+
# The resulting string may contain nulls
|
87
|
+
def jms_correlation_id
|
88
|
+
String.from_java_bytes(getJMSCorrelationIDAsBytes) if getJMSCorrelationIDAsBytes
|
89
|
+
end
|
90
|
+
|
91
|
+
# Set the Message correlation ID
|
92
|
+
# correlation_id: String
|
93
|
+
# Also supports embedded nulls within the correlation id
|
94
|
+
def jms_correlation_id=(correlation_id)
|
95
|
+
setJMSCorrelationIDAsBytes(correlation_id.nil? ? nil : correlation_id.to_java_bytes)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the Message Destination
|
99
|
+
# Instance of JMS::Destination
|
100
|
+
def jms_destination
|
101
|
+
getJMSDestination
|
102
|
+
end
|
103
|
+
|
104
|
+
# Set the Message Destination
|
105
|
+
# jms_destination: Must be an instance of JMS::Destination
|
106
|
+
def jms_destination=(destination)
|
107
|
+
setJMSDestination(destination)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Return the message expiration value as an Integer
|
111
|
+
def jms_expiration
|
112
|
+
getJMSExpiration
|
113
|
+
end
|
114
|
+
|
115
|
+
# Set the Message expiration value
|
116
|
+
# expiration: Integer
|
117
|
+
def jms_expiration=(expiration)
|
118
|
+
setJMSExpiration(expiration)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns the Message ID as a String
|
122
|
+
# The resulting string may contain embedded nulls
|
123
|
+
def jms_message_id
|
124
|
+
getJMSMessageID
|
125
|
+
end
|
126
|
+
|
127
|
+
# Set the Message correlation ID
|
128
|
+
# message_id: String
|
129
|
+
# Also supports nulls within the message id
|
130
|
+
def jms_message_id=(message_id)
|
131
|
+
setJMSMessageID(message_id)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns the Message Priority level as an Integer
|
135
|
+
def jms_priority
|
136
|
+
getJMSPriority
|
137
|
+
end
|
138
|
+
|
139
|
+
# Set the Message priority level
|
140
|
+
# priority: Integer
|
141
|
+
def jms_priority=(priority)
|
142
|
+
setJMSPriority(priority)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Indicates whether the Message was redelivered?
|
146
|
+
def jms_redelivered?
|
147
|
+
getJMSRedelivered
|
148
|
+
end
|
149
|
+
|
150
|
+
# Set whether the Message was redelivered
|
151
|
+
# bool: Boolean
|
152
|
+
def jms_redelivered=(bool)
|
153
|
+
setJMSPriority(bool)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns the Message reply to Destination
|
157
|
+
# Instance of JMS::Destination
|
158
|
+
def jms_reply_to
|
159
|
+
getJMSReplyTo
|
160
|
+
end
|
161
|
+
|
162
|
+
# Set the Message reply to Destination
|
163
|
+
# reply_to: Must be an instance of JMS::Destination
|
164
|
+
def jms_reply_to=(reply_to)
|
165
|
+
setJMSReplyTo(reply_to)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Returns the Message timestamp as Java Timestamp Integer
|
169
|
+
#TODO Return Ruby Time object?
|
170
|
+
def jms_timestamp
|
171
|
+
getJMSTimestamp
|
172
|
+
end
|
173
|
+
|
174
|
+
# Set the Message timestamp as Java Timestamp Integer
|
175
|
+
# timestamp: Must be an Java Timestamp Integer
|
176
|
+
#TODO Support Ruby Time
|
177
|
+
def jms_timestamp=(timestamp)
|
178
|
+
setJMSTimestamp(timestamp)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the Message type supplied by the client when the message was sent
|
182
|
+
def jms_type
|
183
|
+
getJMSType
|
184
|
+
end
|
185
|
+
|
186
|
+
# Sets the Message type
|
187
|
+
# type: String
|
188
|
+
def jms_type=(type)
|
189
|
+
setJMSType(type)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# Return the JMS Delivery Mode as a Ruby symbol
|
194
|
+
# :persistent
|
195
|
+
# :non_persistent
|
196
|
+
# nil if unknown
|
197
|
+
def jms_delivery_mode_sym
|
198
|
+
case jms_delivery_mode
|
199
|
+
when JMS::DeliveryMode::PERSISTENT
|
200
|
+
:persistent
|
201
|
+
when JMS::DeliveryMode::NON_PERSISTENT
|
202
|
+
:non_persistent
|
203
|
+
else
|
204
|
+
nil
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Set the JMS Delivery Mode from a Ruby Symbol
|
209
|
+
# Valid values for mode
|
210
|
+
# :persistent
|
211
|
+
# :non_persistent
|
212
|
+
def jms_delivery_mode_sym=(mode)
|
213
|
+
val = case mode
|
214
|
+
when :persistent
|
215
|
+
JMS::DeliveryMode::PERSISTENT
|
216
|
+
when :non_persistent
|
217
|
+
JMS::DeliveryMode::NON_PERSISTENT
|
218
|
+
else
|
219
|
+
raise "Unknown delivery mode symbol: #{mode}"
|
220
|
+
end
|
221
|
+
self.setJMSDeliveryMode(val)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Return the attributes (header fields) of the message as a Hash
|
225
|
+
def attributes
|
226
|
+
{
|
227
|
+
:jms_correlation_id => jms_correlation_id,
|
228
|
+
:jms_delivery_mode_sym => jms_delivery_mode_sym,
|
229
|
+
:jms_destination => jms_destination.nil? ? nil : jms_destination.to_string,
|
230
|
+
:jms_expiration => jms_expiration,
|
231
|
+
:jms_message_id => jms_message_id,
|
232
|
+
:jms_priority => jms_priority,
|
233
|
+
:jms_redelivered => jms_redelivered?,
|
234
|
+
:jms_reply_to => jms_reply_to,
|
235
|
+
:jms_timestamp => jms_timestamp,
|
236
|
+
:jms_type => jms_type,
|
237
|
+
}
|
238
|
+
end
|
239
|
+
|
240
|
+
# Methods for manipulating the message properties
|
241
|
+
|
242
|
+
# Get the value of a property
|
243
|
+
def [](key)
|
244
|
+
getObjectProperty key.to_s
|
245
|
+
end
|
246
|
+
|
247
|
+
# Set a property
|
248
|
+
def []=(key, value)
|
249
|
+
setObjectProperty(key.to_s, value)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Does message include specified property?
|
253
|
+
def include?(key)
|
254
|
+
# Ensure a Ruby true is returned
|
255
|
+
property_exists(key) == true
|
256
|
+
end
|
257
|
+
|
258
|
+
# Return Properties as a hash
|
259
|
+
def properties
|
260
|
+
h = {}
|
261
|
+
properties_each_pair {|k,v| h[k]=v}
|
262
|
+
h
|
263
|
+
end
|
264
|
+
|
265
|
+
# Set Properties from an existing hash
|
266
|
+
def properties=(h)
|
267
|
+
clear_properties
|
268
|
+
h.each_pair {|k,v| setObjectProperty(k.to_s, v)}
|
269
|
+
h
|
270
|
+
end
|
271
|
+
|
272
|
+
# Return each name value pair
|
273
|
+
def properties_each_pair(&proc)
|
274
|
+
enum = getPropertyNames
|
275
|
+
while enum.has_more_elements
|
276
|
+
key = enum.next_element
|
277
|
+
proc.call key, getObjectProperty(key)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def inspect
|
282
|
+
"#{self.class.name}: #{data}\nAttributes: #{attributes.inspect}\nProperties: #{properties.inspect}"
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|