jruby-hornetq 0.2.1.alpha → 0.2.3.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ desc "Build gem"
8
8
  task :gem do |t|
9
9
  gemspec = Gem::Specification.new do |s|
10
10
  s.name = 'jruby-hornetq'
11
- s.version = '0.2.1.alpha'
11
+ s.version = '0.2.3.alpha'
12
12
  s.authors = ['Reid Morrison', 'Brad Pardee']
13
13
  s.email = ['rubywmq@gmail.com', 'bpardee@gmail.com']
14
14
  s.homepage = 'https://github.com/ClarityServices/jruby-hornetq'
@@ -0,0 +1,20 @@
1
+ # Window 1:
2
+ # Step 1
3
+ rm -rf data data_backup
4
+ hornetq_server hornetq.yml backup_server
5
+ # Wait for HornetQ Server version ... started
6
+
7
+ # Window 2:
8
+ # Step 2
9
+ hornetq_server hornetq.yml live_server &
10
+ # Step 5
11
+ # View window 3&4 looking for "1000" signifying that 1000 messages have been produced/consumed
12
+ kill -9 %1 (or whatever the background job id for the server is) (or start in the foreground and just cntl-c)
13
+
14
+ # Window 3:
15
+ # Step 3
16
+ ./producer.rb 10000
17
+
18
+ # Window 4:
19
+ # Step 4
20
+ ./consumer.rb
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # HornetQ Consumer:
4
+ # Write messages to the queue
5
+ #
6
+
7
+ require 'rubygems'
8
+ require 'yaml'
9
+ require 'hornetq'
10
+
11
+ timeout = (ARGV[0] || 3000).to_i
12
+
13
+ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')
14
+ constants = config['constants']
15
+
16
+ # Create a HornetQ session
17
+ HornetQ::Client::Factory.session(config['client']) do |session|
18
+ consumer = session.create_consumer(constants[:queue])
19
+ session.start
20
+
21
+ i = 0
22
+ start_time = Time.now
23
+ while message = consumer.receive(timeout)
24
+ i += 1
25
+ message.acknowledge
26
+ expected_message = "Message ##{i}"
27
+ if message.body != expected_message
28
+ puts "Unexpected message: #{message.body} Expected: #{expected_message}"
29
+ i = $1.to_i if message.body =~ /Message #(\d+)/
30
+ end
31
+ puts "#{i}\n" if i%1000 == 0
32
+ end
33
+ duration = Time.now - start_time - timeout/1000
34
+ puts "Received #{i} messages in #{duration} seconds at #{i/duration} messages per second"
35
+ end
@@ -0,0 +1,29 @@
1
+ backup_server:
2
+ :uri: hornetq://localhost:15446
3
+ :backup: true
4
+ :data_directory: ./data_backup
5
+ :persistence_enabled: true
6
+ :security_enabled: false
7
+
8
+ live_server:
9
+ :uri: hornetq://localhost:15445,localhost:15446
10
+ :data_directory: ./data
11
+ :persistence_enabled: true
12
+ :security_enabled: false
13
+
14
+ client:
15
+ :connector:
16
+ :uri: hornetq://localhost:15445,localhost:15446
17
+ :failover_on_initial_connection: true
18
+ :failover_on_server_shutdown: true
19
+ # 5 Connection attempts takes about 16 seconds before it switches to the backup server
20
+ :reconnect_attempts: 5
21
+
22
+ :session:
23
+ :username: guest
24
+ :password: guest
25
+
26
+ constants:
27
+ :address: test_address
28
+ :queue: test_queue
29
+ :durable: true
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # HornetQ Producer:
4
+ # Write messages to the queue
5
+ #
6
+
7
+ require 'rubygems'
8
+ require 'yaml'
9
+ require 'hornetq'
10
+
11
+ count = (ARGV[0] || 1).to_i
12
+ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')
13
+ constants = config['constants']
14
+
15
+ # Create a HornetQ session
16
+ HornetQ::Client::Factory.session(config['client']) do |session|
17
+ session.delete_queue(constants[:queue]) rescue nil
18
+ session.create_queue(constants[:address], constants[:queue], constants[:durable])
19
+ producer = session.create_producer(constants[:address])
20
+ start_time = Time.now
21
+
22
+ puts "Sending messages"
23
+ (1..count).each do |i|
24
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, true)
25
+ # Set the message body text
26
+ message.body = "Message ##{i}"
27
+ message.put_string_property(Java::org.hornetq.api.core.SimpleString.new(HornetQ::Client::Message::HDR_DUPLICATE_DETECTION_ID.to_s), Java::org.hornetq.api.core.SimpleString.new("uniqueid#{i}"))
28
+ # Send message to the queue
29
+ begin
30
+ producer.send(message)
31
+ rescue Java::org.hornetq.api.core.HornetQException => e
32
+ puts "Received producer exception: #{e.message} with code=#{e.cause.code}"
33
+ if e.cause.code == Java::org.hornetq.api.core.HornetQException::UNBLOCKED
34
+ puts "Retrying the send"
35
+ retry
36
+ end
37
+ end
38
+ #puts message
39
+ puts "#{i}\n" if i%1000 == 0
40
+ end
41
+
42
+ duration = Time.now - start_time
43
+ puts "Delivered #{count} messages in #{duration} seconds at #{count/duration} messages per second"
44
+ end
@@ -64,7 +64,7 @@ class BatchClient
64
64
  total_count.times do |i|
65
65
  message = @session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
66
66
  message.reply_to_queue_name = @consumer.queue_name
67
- message << "Request Current Time. #{i}"
67
+ message.body = "Request Current Time. #{i}"
68
68
  @producer.send(message)
69
69
  print "."
70
70
  #puts "Sent:#{message}"
@@ -96,7 +96,7 @@ class BatchClient
96
96
  end
97
97
 
98
98
  # Create a HornetQ session
99
- HornetQ::Client::Factory.create_session(config) do |session|
99
+ HornetQ::Client::Factory.session(config) do |session|
100
100
  batching_size = total_count if batching_size > total_count
101
101
 
102
102
  client = BatchClient.new(session, request_address)
@@ -0,0 +1,21 @@
1
+ #
2
+ # HornetQ Producer:
3
+ # Write messages to the queue
4
+ #
5
+
6
+ # Allow examples to be run in-place without requiring a gem install
7
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../../lib'
8
+
9
+ require 'rubygems'
10
+ require 'hornetq'
11
+
12
+ HornetQ::Client::Factory.session('hornetq://localhost') do |session|
13
+ # Create Producer so that we can send messages to the Address 'jms.queue.ExampleQueue'
14
+ producer = session.create_producer('jms.queue.ExampleQueue')
15
+
16
+ # Create a non-durable message to send
17
+ message = session.create_message(HornetQ::Client::Message::BYTES_TYPE,false)
18
+ message.body = "#{Time.now}: ### Hello, World ###"
19
+
20
+ producer.send(message)
21
+ end
@@ -16,7 +16,7 @@ timeout = (ARGV[1] || 30000).to_i
16
16
  config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
17
17
 
18
18
  # Create a HornetQ session
19
- HornetQ::Client::Factory.create_session(config) do |session|
19
+ HornetQ::Client::Factory.session(config) do |session|
20
20
  #session.create_queue('Example', 'Example', true)
21
21
  requestor = session.create_requestor('jms.queue.ExampleQueue')
22
22
  session.start
@@ -26,7 +26,7 @@ HornetQ::Client::Factory.create_session(config) do |session|
26
26
  (1..count).each do |i|
27
27
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
28
28
  # Set the message body text
29
- message << "Request Current Time"
29
+ message.body = "Request Current Time"
30
30
  # Set the user managed message id
31
31
  message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
32
32
  # Send request message and wait for reply
@@ -15,7 +15,7 @@ timeout = (ARGV[0] || 1000).to_i
15
15
  config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
16
16
 
17
17
  # Create a HornetQ session
18
- HornetQ::Client::Factory.create_session(config) do |session|
18
+ HornetQ::Client::Factory.session(config) do |session|
19
19
  consumer = session.create_consumer('jms.queue.ExampleQueue')
20
20
  session.start
21
21
 
@@ -26,7 +26,7 @@ def worker_thread(id, session_pool)
26
26
  # Obtain a session from the pool and return when complete
27
27
  session_pool.requestor('jms.queue.ExampleQueue') do |session, requestor|
28
28
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
29
- message << "Request Current Time"
29
+ message.body = "Request Current Time"
30
30
 
31
31
  # Send message to the queue
32
32
  puts "Thread[#{id}]: Sending Request"
@@ -14,7 +14,7 @@ count = (ARGV[0] || 1).to_i
14
14
  config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
15
15
 
16
16
  # Create a HornetQ session
17
- HornetQ::Client::Factory.create_session(config) do |session|
17
+ HornetQ::Client::Factory.session(config) do |session|
18
18
  producer = session.create_producer('jms.queue.ExampleQueue')
19
19
  start_time = Time.now
20
20
 
@@ -22,7 +22,7 @@ HornetQ::Client::Factory.create_session(config) do |session|
22
22
  (1..count).each do |i|
23
23
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
24
24
  # Set the message body text
25
- message << "#{Time.now}: ### Hello, World ###"
25
+ message.body = "#{Time.now}: ### Hello, World ###"
26
26
  # Send message to the queue
27
27
  producer.send(message)
28
28
  #puts message
@@ -15,7 +15,7 @@ timeout = (ARGV[0] || 60000).to_i
15
15
  config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
16
16
 
17
17
  # Create a HornetQ session
18
- HornetQ::Client::Factory.create_session(config) do |session|
18
+ HornetQ::Client::Factory.session(config) do |session|
19
19
  server = session.create_server('jms.queue.ExampleQueue', timeout)
20
20
  session.start
21
21
 
@@ -28,7 +28,7 @@ HornetQ::Client::Factory.create_session(config) do |session|
28
28
  puts "#{count}" if count%1000 == 0
29
29
  puts "Durable" if request_message.durable
30
30
  reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
31
- reply_message << "Test Response"
31
+ reply_message.body = "Test Response"
32
32
  reply_message
33
33
  end
34
34
 
@@ -22,7 +22,7 @@ HornetQ::Server::Factory.start('hornetq://invm') do |server|
22
22
 
23
23
  # Create a non-durable message to send
24
24
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
25
- message << "#{Time.now}: ### Hello, World ###"
25
+ message.body = "#{Time.now}: ### Hello, World ###"
26
26
 
27
27
  producer.send(message)
28
28
 
@@ -9,13 +9,13 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
9
9
  require 'rubygems'
10
10
  require 'hornetq'
11
11
 
12
- HornetQ::Client::Factory.create_session(:connector=> {:uri => 'hornetq://localhost'}) do |session|
12
+ HornetQ::Client::Factory.session('hornetq://localhost') do |session|
13
13
  # Create Producer so that we can send messages to the Address 'jms.queue.ExampleQueue'
14
14
  producer = session.create_producer('jms.queue.ExampleQueue')
15
15
 
16
16
  # Create a non-durable message to send
17
17
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
18
- message << "#{Time.now}: ### Hello, World ###"
18
+ message.body = "#{Time.now}: ### Hello, World ###"
19
19
 
20
20
  producer.send(message)
21
21
  end
@@ -155,12 +155,8 @@ module HornetQ::Client
155
155
 
156
156
  # Create a new HornetQ session
157
157
  #
158
- # If a block is passed in the block will be passed the session as a parameter
159
- # and this method will return the result of the block. The session is
160
- # always closed once the proc completes
161
- #
162
- # If no block is passed, a new session is returned and it is the responsibility
163
- # of the caller to close the session
158
+ # Note: Remember to close the session once it is no longer used.
159
+ # Recommend using #session with a block over this method where possible
164
160
  #
165
161
  # Note:
166
162
  # * The returned session MUST be closed once complete
@@ -169,11 +165,6 @@ module HornetQ::Client
169
165
  # ...
170
166
  # session.close
171
167
  # factory.close
172
- # * It is recommended to rather call HornetQ::Client::Factory.create_session
173
- # so that all resouces are closed automatically
174
- # HornetQ::Client::Factory.create_session(:uri => 'hornetq://localhost/') do |session|
175
- # ...
176
- # end
177
168
  #
178
169
  # Returns:
179
170
  # * A new HornetQ ClientSession
@@ -187,31 +178,6 @@ module HornetQ::Client
187
178
  # require 'hornetq'
188
179
  #
189
180
  # factory = nil
190
- # begin
191
- # factory = HornetQ::Client::Factory.new(:uri => 'hornetq://localhost/')
192
- # factory.create_session do |session|
193
- #
194
- # # Create a new queue
195
- # session.create_queue('Example', 'Example', true)
196
- #
197
- # # Create a producer to send messages
198
- # producer = session.create_producer('Example')
199
- #
200
- # # Create a Text Message
201
- # message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,true)
202
- # message << 'Hello World'
203
- #
204
- # # Send the message
205
- # producer.send(message)
206
- # end
207
- # ensure
208
- # factory.close if factory
209
- # end
210
- #
211
- # Example:
212
- # require 'hornetq'
213
- #
214
- # factory = nil
215
181
  # session = nil
216
182
  # begin
217
183
  # factory = HornetQ::Client::Factory.new(:uri => 'hornetq://localhost/')
@@ -280,37 +246,64 @@ module HornetQ::Client
280
246
  # * :ack_batch_size
281
247
  # * the batch size of the acknowledgements
282
248
  #
283
- def create_session(params={}, &proc)
249
+ def create_session(params={})
284
250
  raise "HornetQ::Client::Factory Already Closed" unless @factory
285
- if proc
286
- session = nil
287
- result = nil
288
- begin
289
- session = @factory.create_session(
290
- params[:username],
291
- params[:password],
292
- params[:xa] || false,
293
- params[:auto_commit_sends].nil? ? true : params[:auto_commit_sends],
294
- params[:auto_commit_acks].nil? ? true : params[:auto_commit_acks],
295
- params[:pre_acknowledge] || false,
296
- params[:ack_batch_size] || 1)
297
- result = proc.call(session)
298
- ensure
299
- session.close if session
300
- end
301
- result
302
- else
303
- @factory.create_session(
304
- params[:username],
305
- params[:password],
306
- params[:xa] || false,
307
- params[:auto_commit_sends].nil? ? true : params[:auto_commit_sends],
308
- params[:auto_commit_acks].nil? ? true : params[:auto_commit_acks],
309
- params[:pre_acknowledge] || false,
310
- params[:ack_batch_size] || 1)
311
- end
251
+ @factory.create_session(
252
+ params[:username],
253
+ params[:password],
254
+ params[:xa] || false,
255
+ params[:auto_commit_sends].nil? ? true : params[:auto_commit_sends],
256
+ params[:auto_commit_acks].nil? ? true : params[:auto_commit_acks],
257
+ params[:pre_acknowledge] || false,
258
+ params[:ack_batch_size] || 1)
312
259
  end
313
260
 
261
+ # Create a session, call the supplied block and once it completes
262
+ # close the session.
263
+ # See session_create for the Parameters
264
+ #
265
+ # Returns the result of the block
266
+ #
267
+ # Example
268
+ # HornetQ::Client::Factory.create_session(:uri => 'hornetq://localhost/') do |session|
269
+ # session.create_queue("Address", "Queue")
270
+ # end
271
+ #
272
+ # Example:
273
+ # require 'hornetq'
274
+ #
275
+ # factory = nil
276
+ # begin
277
+ # factory = HornetQ::Client::Factory.new(:uri => 'hornetq://localhost/')
278
+ # factory.create_session do |session|
279
+ #
280
+ # # Create a new queue
281
+ # session.create_queue('Example', 'Example', true)
282
+ #
283
+ # # Create a producer to send messages
284
+ # producer = session.create_producer('Example')
285
+ #
286
+ # # Create a Text Message
287
+ # message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,true)
288
+ # message.body = 'Hello World'
289
+ #
290
+ # # Send the message
291
+ # producer.send(message)
292
+ # end
293
+ # ensure
294
+ # factory.close if factory
295
+ # end
296
+ def session(params={}, &proc)
297
+ raise "HornetQ::Client::session mandatory block missing" unless proc
298
+ session = nil
299
+ begin
300
+ session = create_session(params)
301
+ proc.call(session)
302
+ ensure
303
+ session.close if session
304
+ end
305
+ end
306
+
314
307
  # Create a Session pool
315
308
  # TODO Raise an exception when gene_pool is not available
316
309
  def create_session_pool(params={})
@@ -330,7 +323,7 @@ module HornetQ::Client
330
323
  # block. Upon completion the session and factory are both closed
331
324
  # See Factory::initialize and Factory::create_session for the list
332
325
  # of parameters
333
- def self.create_session(params={},&proc)
326
+ def self.session(params={},&proc)
334
327
  raise "Missing mandatory code block" unless proc
335
328
  factory = nil
336
329
  session = nil
@@ -338,10 +331,10 @@ module HornetQ::Client
338
331
  if params.kind_of?(String)
339
332
  # TODO: Support passing username and password from URI to Session
340
333
  factory = self.new(params)
341
- session = factory.create_session({}, &proc)
334
+ session = factory.session({}, &proc)
342
335
  else
343
336
  factory = self.new(params[:connector] || {})
344
- session = factory.create_session(params[:session] || {}, &proc)
337
+ session = factory.session(params[:session] || {}, &proc)
345
338
  end
346
339
  ensure
347
340
  session.close if session
@@ -356,7 +349,7 @@ module HornetQ::Client
356
349
  # See Factory::initialize and Factory::create_session for the list
357
350
  # of parameters
358
351
  def self.start(params={},&proc)
359
- create_session(params) do |session|
352
+ session(params) do |session|
360
353
  session.start
361
354
  proc.call(session)
362
355
  end
@@ -48,12 +48,35 @@ class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
48
48
  case type
49
49
  when Java::org.hornetq.api.core.Message::BYTES_TYPE #4
50
50
  buf = body_buffer
51
- String.new(buf.read_bytes(buf.readable_bytes))
51
+ buf.reset_reader_index
52
+ available = body_size
53
+ result = ""
54
+ bytes_size = 1024
55
+ bytes = Java::byte[bytes_size].new
56
+
57
+ while (n = available < bytes_size ? available : bytes_size) > 0
58
+ buf.read_bytes(bytes, 0, n)
59
+ if n == bytes_size
60
+ result << String.from_java_bytes(bytes)
61
+ else
62
+ result << String.from_java_bytes(bytes)[0..n-1]
63
+ end
64
+ available -= n
65
+ end
66
+ result
67
+
52
68
  when Java::org.hornetq.api.core.Message::DEFAULT_TYPE #0
69
+ #TODO Default Type?
70
+
53
71
  when Java::org.hornetq.api.core.Message::MAP_TYPE #5
54
72
  Java::org.hornetq.utils::TypedProperties.new.decode(body_buffer)
73
+
55
74
  when Java::org.hornetq.api.core.Message::OBJECT_TYPE #2
75
+ # TODO Java Object Type
76
+
56
77
  when Java::org.hornetq.api.core.Message::STREAM_TYPE #6
78
+ #TODO Stream Type
79
+
57
80
  when Java::org.hornetq.api.core.Message::TEXT_TYPE #3
58
81
  body_buffer.read_nullable_simple_string.to_string
59
82
  else
@@ -63,89 +86,52 @@ class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
63
86
 
64
87
  # Write data into the message body
65
88
  #
89
+ # Note: The message type Must be set before calling this method
90
+ #
66
91
  # Data is automatically converted based on the message type
67
92
  #
68
- # DEPRECATED
69
- def <<(data)
93
+ def body=(data)
94
+ body_buffer.reset_writer_index
70
95
  case type
96
+
71
97
  when Java::org.hornetq.api.core.Message::BYTES_TYPE #4
72
- body_buffer.write_bytes(data)
73
- when Java::org.hornetq.api.core.Message::DEFAULT_TYPE #0
74
- raise "Cannot use Message#<< when the Message#type has not been set"
98
+ body_buffer.write_bytes(data.respond_to?(:to_java_bytes) ? data.to_java_bytes : data)
99
+
75
100
  when Java::org.hornetq.api.core.Message::MAP_TYPE #5
76
- if data.class == Java::org.hornetq.utils::TypedProperties
77
- body_buffer.reset_writer_index
101
+ if data.kind_of? Java::org.hornetq.utils::TypedProperties
78
102
  data.encode(body_buffer)
79
103
  elsif data.responds_to? :each_pair
104
+ # Ruby Hash, or anything that responds to :each_pair
105
+ # TODO What about Hash inside of Hash?
80
106
  properties = Java::org.hornetq.utils::TypedProperties.new
81
- properties.from_hash(data)
82
- body_buffer.reset_writer_index
107
+ data.each_pair do |key, val|
108
+ properties[key.to_s] = val
109
+ end
83
110
  properties.encode(body_buffer)
111
+ else
112
+ raise "Unrecognized data type #{data.class.name} being set when the message type is MAP"
84
113
  end
114
+
85
115
  when Java::org.hornetq.api.core.Message::OBJECT_TYPE #2
116
+ # Serialize Java Object
117
+ # TODO Should we do the serialize here?
118
+ body_buffer.write_bytes(data)
119
+
86
120
  when Java::org.hornetq.api.core.Message::STREAM_TYPE #6
121
+ # TODO Stream Type
122
+
87
123
  when Java::org.hornetq.api.core.Message::TEXT_TYPE #3
88
- if data.class == Java::org.hornetq.api.core::SimpleString
124
+ if data.kind_of? Java::org.hornetq.api.core::SimpleString
89
125
  body_buffer.writeNullableSimpleString(data)
90
126
  else
91
127
  body_buffer.writeNullableSimpleString(Java::org.hornetq.api.core::SimpleString.new(data.to_s))
92
128
  end
129
+
130
+ when Java::org.hornetq.api.core.Message::DEFAULT_TYPE #0
131
+ raise "The Message#type must be set before attempting to set the message body"
132
+
93
133
  else
94
- raise "Unknown Message Type, use Message#body_buffer instead"
95
- end
96
- end
97
-
98
- # Set the body of the message
99
- # The type of the message is automatically set based on the type passed in.
100
- # The following types are automatically supported in order of priority
101
- # String => :text
102
- # Java::org.hornetq.api.core::SimpleString => :text
103
- # Java::org.hornetq.utils::TypedProperties => :map
104
- # Hash (actually any object responding to => :map
105
- def body=(data)
106
- body_buffer.reset_writer_index
107
- if data.is_a? String
108
- # Ruby String
109
- self.type = Java::org.hornetq.api.core.Message::TEXT_TYPE
110
- body_buffer.writeNullableSimpleString(Java::org.hornetq.api.core::SimpleString.new(data))
111
- elsif data.is_a? Java::org.hornetq.api.core::SimpleString
112
- # SimpleString instance
113
- self.type = Java::org.hornetq.api.core.Message::TEXT_TYPE
114
- body_buffer.writeNullableSimpleString(data)
115
- elsif data.is_a? Java::org.hornetq.utils::TypedProperties
116
- # TypedProperties
117
- self.type = Java::org.hornetq.api.core.Message::MAP_TYPE
118
- data.encode(body_buffer)
119
- elsif data.responds_to? :each_pair
120
- # Ruby Hash, or anything that responds to :each_pair
121
- # TODO What about Hash inside of Hash?
122
- self.type = Java::org.hornetq.api.core.Message::MAP_TYPE
123
- properties = Java::org.hornetq.utils::TypedProperties.new
124
- data.each_pair do |key, val|
125
- properties[key.to_s] = val
126
- end
127
- properties.encode(body_buffer)
128
- elsif data.responds_to? :to_s
129
- # Can be converted to a Ruby String
130
- self.type = Java::org.hornetq.api.core.Message::TEXT_TYPE
131
- body_buffer.writeNullableSimpleString(Java::org.hornetq.api.core::SimpleString.new(data.to_s))
132
- else
133
- # Otherwise Serialize Ruby object
134
- self.type = Java::org.hornetq.api.core.Message::BYTES_TYPE
135
- self['encoding', 'jruby']
136
- # If BYTES type is not working we could use Base64.encode64
137
- self << Marshal.dump(data)
138
- self.text = encoded
139
- end
140
- end
141
-
142
- # Serialize JRuby object and base64 encode
143
- def decode
144
- if self.get_string_property( 'torquebox_encoding' ) == 'base64'
145
- serialized = Base64.decode64( self.text )
146
- Marshal.restore( serialized )
147
- else
148
- self.text
134
+ raise "Unknown Message Type, use Message#body_buffer directly"
149
135
  end
150
136
  end
151
137
 
@@ -95,7 +95,7 @@ module HornetQ::Client
95
95
  # Example
96
96
  # session_pool.producer('MyAddress') do |session, producer|
97
97
  # message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
98
- # message << "#{Time.now}: ### Hello, World ###"
98
+ # message.body = "#{Time.now}: ### Hello, World ###"
99
99
  # producer.send(message)
100
100
  # end
101
101
  def producer(address, &block)
@@ -20,25 +20,10 @@ module HornetQ::Server
20
20
  config.journal_directory = "#{data_directory}/journal"
21
21
  config.large_messages_directory = "#{data_directory}/large-messages"
22
22
 
23
- parms.each_pair do |key, val|
24
- method = key.to_s+'='
25
- if config.respond_to? method
26
- config.send method, val
27
- #puts "Debug: #{key} = #{config.send key}" if config.respond_to? key.to_sym
28
- else
29
- puts "Warning: Option:#{key} class=#{key.class} with value:#{val} is invalid and being ignored"
30
- end
31
- end
32
-
33
- if Java::org.hornetq.core.journal.impl.AIOSequentialFileFactory.isSupported
34
- config.journal_type = Java::org.hornetq.core.server.JournalType::ASYNCIO
35
- else
36
- puts("AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal");
37
- config.journal_type = Java::org.hornetq.core.server.JournalType::NIO
38
- end
39
-
40
23
  if uri.host == 'invm'
41
24
  acceptor = Java::org.hornetq.api.core.TransportConfiguration.new(HornetQ::INVM_ACCEPTOR_CLASS_NAME)
25
+ config.persistence_enabled = false
26
+ config.security_enabled = false
42
27
  else
43
28
  acceptor = Java::org.hornetq.api.core.TransportConfiguration.new(HornetQ::NETTY_ACCEPTOR_CLASS_NAME, {'host' => uri.host, 'port' => uri.port })
44
29
  connector = Java::org.hornetq.api.core.TransportConfiguration.new(HornetQ::NETTY_CONNECTOR_CLASS_NAME, {'host' => uri.host, 'port' => uri.port })
@@ -50,6 +35,12 @@ module HornetQ::Server
50
35
  acceptor_conf_set.add(acceptor)
51
36
  config.acceptor_configurations = acceptor_conf_set
52
37
 
38
+ if Java::org.hornetq.core.journal.impl.AIOSequentialFileFactory.isSupported
39
+ config.journal_type = Java::org.hornetq.core.server.JournalType::ASYNCIO
40
+ else
41
+ puts("AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal");
42
+ config.journal_type = Java::org.hornetq.core.server.JournalType::NIO
43
+ end
53
44
 
54
45
  if parms[:backup]
55
46
  puts "backup"
@@ -67,6 +58,16 @@ module HornetQ::Server
67
58
  puts 'standalone'
68
59
  end
69
60
 
61
+ parms.each_pair do |key, val|
62
+ method = key.to_s+'='
63
+ if config.respond_to? method
64
+ config.send method, val
65
+ #puts "Debug: #{key} = #{config.send key}" if config.respond_to? key.to_sym
66
+ else
67
+ puts "Warning: Option:#{key} class=#{key.class} with value:#{val} is invalid and being ignored"
68
+ end
69
+ end
70
+
70
71
  return Java::org.hornetq.core.server.HornetQServers.newHornetQServer(config)
71
72
  end
72
73
 
@@ -45,20 +45,20 @@ class ServerFactoryTest < Test::Unit::TestCase
45
45
  }
46
46
 
47
47
  # Create a HornetQ session
48
- HornetQ::Client::Factory.create_session(config) do |session|
48
+ HornetQ::Client::Factory.session(config) do |session|
49
49
  session.create_queue(queue_name, queue_name, true)
50
50
  producer = session.create_producer(queue_name)
51
51
  (1..count).each do |i|
52
52
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
53
53
  message.durable = true
54
54
  # Set the message body text
55
- message << "Message ##{i}"
55
+ message.body = "Message ##{i}"
56
56
  # Send message to the queue
57
57
  producer.send(message)
58
58
  end
59
59
  end
60
60
 
61
- HornetQ::Client::Factory.create_session(config) do |session|
61
+ HornetQ::Client::Factory.session(config) do |session|
62
62
  consumer = session.create_consumer(queue_name)
63
63
  session.start
64
64
 
@@ -124,14 +124,13 @@ class ServerFactoryTest < Test::Unit::TestCase
124
124
 
125
125
  @producer_thread = MyThread.new('producer') do
126
126
  # Create a HornetQ session
127
- HornetQ::Client::Factory.create_session(@config) do |session|
127
+ HornetQ::Client::Factory.session(@config) do |session|
128
128
  session.create_queue(@queue_name, @queue_name, true)
129
129
  producer = session.create_producer(@queue_name)
130
130
  (1..@count).each do |i|
131
- message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
132
- message.durable = true
131
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, true)
133
132
  # Set the message body text
134
- message << "Message ##{i}"
133
+ message.body = "Message ##{i}"
135
134
  # Send message to the queue
136
135
  begin
137
136
  puts "Producing message: #{message.body}"
@@ -163,7 +162,7 @@ class ServerFactoryTest < Test::Unit::TestCase
163
162
  should 'failover to backup server w/o message loss' do
164
163
  # Let the producer create the queue
165
164
  sleep 2
166
- HornetQ::Client::Factory.create_session(@config) do |session|
165
+ HornetQ::Client::Factory.session(@config) do |session|
167
166
  consumer = session.create_consumer(@queue_name)
168
167
  session.start
169
168
 
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-hornetq
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
5
- segments:
6
- - 0
7
- - 2
8
- - 1
9
- - alpha
10
- version: 0.2.1.alpha
4
+ prerelease: 6
5
+ version: 0.2.3.alpha
11
6
  platform: ruby
12
7
  authors:
13
8
  - Reid Morrison
@@ -16,20 +11,17 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2011-01-26 00:00:00 -05:00
14
+ date: 2011-01-27 00:00:00 -05:00
20
15
  default_executable:
21
16
  dependencies:
22
17
  - !ruby/object:Gem::Dependency
23
18
  name: gene_pool
24
19
  prerelease: false
25
20
  requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
26
22
  requirements:
27
23
  - - ~>
28
24
  - !ruby/object:Gem::Version
29
- segments:
30
- - 1
31
- - 1
32
- - 1
33
25
  version: 1.1.1
34
26
  type: :runtime
35
27
  version_requirements: *id001
@@ -49,12 +41,17 @@ files:
49
41
  - Rakefile
50
42
  - README.md
51
43
  - bin/hornetq_server
44
+ - examples/advanced/transaction-failover/consumer.rb
45
+ - examples/advanced/transaction-failover/hornetq.yml
46
+ - examples/advanced/transaction-failover/producer.rb
47
+ - examples/advanced/transaction-failover/README
52
48
  - examples/client/client.rb
53
49
  - examples/client/consumer.rb
54
50
  - examples/client/invm.rb
55
51
  - examples/client/producer.rb
56
52
  - examples/client/server.rb
57
53
  - examples/client/advanced/batch_client.rb
54
+ - examples/client/advanced/bytes_producer.rb
58
55
  - examples/client/advanced/client.rb
59
56
  - examples/client/advanced/consumer.rb
60
57
  - examples/client/advanced/hornetq.yml
@@ -62,6 +59,10 @@ files:
62
59
  - examples/client/advanced/multi_consumer.rb
63
60
  - examples/client/advanced/producer.rb
64
61
  - examples/client/advanced/server.rb
62
+ - examples/client/data/bindings/hornetq-bindings-1.bindings
63
+ - examples/client/data/bindings/hornetq-bindings-2.bindings
64
+ - examples/client/data/journal/hornetq-data-1.hq
65
+ - examples/client/data/journal/hornetq-data-2.hq
65
66
  - examples/server/backup_server.yml
66
67
  - examples/server/live_server.yml
67
68
  - examples/server/standalone_server.yml
@@ -96,25 +97,21 @@ rdoc_options: []
96
97
  require_paths:
97
98
  - lib
98
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
99
101
  requirements:
100
102
  - - ">="
101
103
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
104
  version: "0"
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
106
107
  requirements:
107
108
  - - ">"
108
109
  - !ruby/object:Gem::Version
109
- segments:
110
- - 1
111
- - 3
112
- - 1
113
110
  version: 1.3.1
114
111
  requirements: []
115
112
 
116
113
  rubyforge_project:
117
- rubygems_version: 1.3.6
114
+ rubygems_version: 1.4.2
118
115
  signing_key:
119
116
  specification_version: 3
120
117
  summary: JRuby interface into HornetQ