jruby-hornetq 0.4.0 → 0.5.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +30 -0
  3. data/HISTORY.md +6 -0
  4. data/README.md +33 -35
  5. data/Rakefile +14 -9
  6. data/examples/advanced/batch_client.rb +8 -8
  7. data/examples/advanced/batch_requestor_pattern.rb +34 -34
  8. data/examples/advanced/bytes_producer.rb +3 -3
  9. data/examples/advanced/client.rb +5 -5
  10. data/examples/advanced/client_session_pooling.rb +3 -3
  11. data/examples/advanced/consume_on_message.rb +5 -5
  12. data/examples/advanced/consumer.rb +2 -2
  13. data/examples/advanced/multi_client.rb +3 -3
  14. data/examples/advanced/producer.rb +3 -3
  15. data/examples/advanced/server.rb +4 -4
  16. data/examples/client-server/client.rb +4 -4
  17. data/examples/client-server/server.rb +4 -4
  18. data/examples/producer-consumer/consume_all.rb +2 -2
  19. data/examples/producer-consumer/consume_on_message.rb +5 -5
  20. data/examples/producer-consumer/consumer.rb +2 -2
  21. data/examples/producer-consumer/producer.rb +3 -3
  22. data/examples/resque/hornetq_job.rb +19 -19
  23. data/examples/resque/processor.rb +4 -4
  24. data/examples/resque/sleep_job.rb +3 -3
  25. data/lib/hornetq.rb +3 -2
  26. data/lib/hornetq/client.rb +4 -2
  27. data/lib/hornetq/client/connection.rb +86 -86
  28. data/lib/hornetq/client/message_handler.rb +1 -1
  29. data/lib/hornetq/client/org_hornetq_api_core_client_client_session.rb +67 -67
  30. data/lib/hornetq/client/org_hornetq_core_client_impl_client_consumer_impl.rb +11 -11
  31. data/lib/hornetq/client/org_hornetq_core_client_impl_client_message_impl.rb +126 -126
  32. data/lib/hornetq/client/org_hornetq_core_client_impl_client_producer_impl.rb +14 -14
  33. data/lib/hornetq/client/org_hornetq_utils_typed_properties.rb +6 -6
  34. data/lib/hornetq/client/requestor_pattern.rb +24 -24
  35. data/lib/hornetq/client/server_pattern.rb +4 -4
  36. data/lib/hornetq/client/session_pool.rb +18 -18
  37. data/lib/hornetq/common/logging.rb +1 -14
  38. data/lib/hornetq/java/hornetq-bootstrap.jar +0 -0
  39. data/lib/hornetq/java/hornetq-commons.jar +0 -0
  40. data/lib/hornetq/java/hornetq-core-client.jar +0 -0
  41. data/lib/hornetq/java/hornetq-journal.jar +0 -0
  42. data/lib/hornetq/java/hornetq-server.jar +0 -0
  43. data/lib/hornetq/java/jnp-client.jar +0 -0
  44. data/lib/hornetq/java/netty.jar +0 -0
  45. data/lib/hornetq/server.rb +4 -1
  46. data/lib/hornetq/version.rb +3 -0
  47. data/nbproject/private/private.properties +4 -0
  48. data/nbproject/private/private.xml +4 -0
  49. data/nbproject/private/rake-d.txt +4 -0
  50. data/nbproject/project.properties +11 -0
  51. data/nbproject/project.xml +17 -0
  52. data/test/client_connection_test.rb +25 -25
  53. data/test/logging_test.rb +3 -3
  54. metadata +131 -125
  55. data/bin/data/bindings/hornetq-bindings-1.bindings +0 -0
  56. data/bin/data/bindings/hornetq-bindings-2.bindings +0 -0
  57. data/bin/data/journal/hornetq-data-1.hq +0 -0
  58. data/bin/data/journal/hornetq-data-2.hq +0 -0
  59. data/lib/hornetq/common/log_delegate.rb +0 -48
  60. data/lib/hornetq/common/org_hornetq_core_logging_logger.rb +0 -60
  61. data/lib/hornetq/java/hornetq-core.jar +0 -0
@@ -12,14 +12,14 @@ require 'hornetq'
12
12
  HornetQ::Client::Connection.session('hornetq://localhost') do |session|
13
13
  # Create the non-durable TestQueue to receive messages sent to the TestAddress
14
14
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
15
-
15
+
16
16
  # Create Producer so that we can send messages to the Address 'jms.queue.ExampleQueue'
17
17
  session.producer('TestAddress') do |producer|
18
-
18
+
19
19
  # Create a non-durable bytes message to send
20
20
  message = session.create_message(HornetQ::Client::Message::BYTES_TYPE,false)
21
21
  message.body = "#{Time.now}: ### Hello, World ###"
22
-
22
+
23
23
  producer.send(message)
24
24
  end
25
25
  end
@@ -2,8 +2,8 @@
2
2
  # HornetQ Requestor:
3
3
  # Submit a request and wait for a reply
4
4
  # Uses the Requestor Pattern
5
- #
6
- # The Server (server.rb) must be running first, otherwise this example
5
+ #
6
+ # The Server (server.rb) must be running first, otherwise this example
7
7
  # program will eventually timeout
8
8
  # Displays a '.' for every request completed
9
9
  # Used for performance measurements
@@ -26,7 +26,7 @@ HornetQ::Client::Connection.start_session(config) do |session|
26
26
  # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
27
27
  session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
28
28
  start_time = Time.now
29
-
29
+
30
30
  # Use Requestor (Client) Pattern to do a "RPC like" call to a server
31
31
  # Under the covers the requestor creates a temporary dynamic reply to queue
32
32
  # for the server to send the reply message to
@@ -38,7 +38,7 @@ HornetQ::Client::Connection.start_session(config) do |session|
38
38
  message.body = "Some request data"
39
39
  # Set the user managed message id
40
40
  message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
41
-
41
+
42
42
  if reply = requestor.request(message, timeout)
43
43
  puts "Received Response: #{reply.inspect}" if count < 10
44
44
  puts " Message:[#{reply.body.inspect}]" if count < 10
@@ -47,7 +47,7 @@ HornetQ::Client::Connection.start_session(config) do |session|
47
47
  puts "Time out, No reply received after #{timeout/1000} seconds"
48
48
  end
49
49
  puts "#{i}" if i%1000 == 0
50
-
50
+
51
51
  end
52
52
  end
53
53
 
@@ -1,10 +1,10 @@
1
1
  #
2
2
  # HornetQ Requestor using session_pooling:
3
- # Multithreaded clients all doing requests.
4
- #
3
+ # Multithreaded clients all doing requests.
4
+ #
5
5
  # Shows how the same session can be used safely on different threads
6
6
  # rather than each thread having to create its own session
7
- #
7
+ #
8
8
  # Typical scenario is in a Rails app when we need to do a call to a
9
9
  # remote server and block until a response is received
10
10
  #
@@ -20,12 +20,12 @@ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
20
20
 
21
21
  # Using Connect.start since a session must be started in order to consume messages
22
22
  HornetQ::Client::Connection.connection(config[:connection]) do |connection|
23
-
23
+
24
24
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
25
25
  connection.session(config[:session]) do |session|
26
26
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
27
27
  end
28
-
28
+
29
29
  # Consume All messages from the queue and gather statistics
30
30
  # on_message will call the supplied block for every message received in another
31
31
  # thread. As a result, the on_message call returns immediately!
@@ -33,17 +33,17 @@ HornetQ::Client::Connection.connection(config[:connection]) do |connection|
33
33
  #
34
34
  # :session_count can be used to spawn multiple consumers simultaneously, each
35
35
  # receiving messages simultaneously on their own threads
36
- connection.on_message(:queue_name => 'TestQueue',
36
+ connection.on_message(:queue_name => 'TestQueue',
37
37
  :session_count => session_count,
38
38
  :statistics => true) do |message|
39
39
  print '.'
40
40
  message.acknowledge
41
41
  end
42
-
42
+
43
43
  puts "Started #{session_count} consumers, will wait for #{sleep_time/1000} seconds before shutting down"
44
44
  # Wait for sleep_time before shutting down the server
45
45
  sleep(sleep_time/1000)
46
-
46
+
47
47
  connection.on_message_statistics.each do |stats|
48
48
  puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
49
49
  end
@@ -18,10 +18,10 @@ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
18
18
 
19
19
  # Create a HornetQ session
20
20
  HornetQ::Client::Connection.start_session(config) do |session|
21
-
21
+
22
22
  # Create the non-durable TestQueue to receive messages sent to the TestAddress
23
23
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
24
-
24
+
25
25
  # Consume All messages from the queue
26
26
  stats = session.consume(:queue_name => 'TestQueue', :timeout=> 0, :statistics=>true) do |message|
27
27
  print '.'
@@ -21,7 +21,7 @@ def worker_thread(id, connection, timeout, request_count)
21
21
  begin
22
22
  connection.start_session do |session|
23
23
  start_time = Time.now
24
-
24
+
25
25
  # Use Requestor (Client) Pattern to do a "RPC like" call to a server
26
26
  # Under the covers the requestor creates a temporary dynamic reply to queue
27
27
  # for the server to send the reply message to
@@ -33,7 +33,7 @@ def worker_thread(id, connection, timeout, request_count)
33
33
  message.body = "Some request data"
34
34
  # Set the user managed message id
35
35
  message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
36
-
36
+
37
37
  if reply = requestor.request(message, timeout)
38
38
  puts "Thread[#{id}]:Received Response: #{reply.inspect}" if request_count < 10
39
39
  puts "Thread[#{id}]: Message:[#{reply.body.inspect}]" if request_count < 10
@@ -44,7 +44,7 @@ def worker_thread(id, connection, timeout, request_count)
44
44
  puts "Thread:#{id}=>#{i}" if i%1000 == 0
45
45
  end
46
46
  end
47
-
47
+
48
48
  duration = Time.now - start_time
49
49
  puts "\nThread[#{id}]:Made #{request_count} calls in #{duration} seconds at #{request_count/duration} synchronous requests per second"
50
50
  end
@@ -20,7 +20,7 @@ HornetQ::Client::Connection.session(config) do |session|
20
20
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
21
21
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
22
22
  start_time = Time.now
23
-
23
+
24
24
  session.producer('TestAddress') do |producer|
25
25
  puts "Sending messages"
26
26
  (1..count).each do |i|
@@ -28,12 +28,12 @@ HornetQ::Client::Connection.session(config) do |session|
28
28
  message.body = "#{Time.now}: ### Hello, World ###"
29
29
  message.body = "#{Time.now}: #{i} : ### Hello, World ###"
30
30
  message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
31
-
31
+
32
32
  producer.send(message)
33
33
  puts "#{i}\n" if i%1000 == 0
34
34
  end
35
35
  end
36
-
36
+
37
37
  duration = Time.now - start_time
38
38
  puts "Delivered #{count} messages in #{duration} seconds at #{count/duration} messages per second"
39
39
  end
@@ -21,24 +21,24 @@ HornetQ::Client::Connection.start_session(config) do |session|
21
21
 
22
22
  count = 0
23
23
  start_time = Time.now
24
-
24
+
25
25
  session.server('ServerQueue', timeout) do |server|
26
26
  puts "Server started and waiting for requests ..."
27
27
  server.run do |request_message|
28
28
  count += 1
29
29
  print '.'
30
30
  puts "#{count}" if count%1000 == 0
31
-
31
+
32
32
  # Create Reply Message
33
33
  reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
34
34
  reply_message.body = "Echo [#{request_message.body}]"
35
-
35
+
36
36
  # The result of this block is the message to be sent back to the requestor (client)
37
37
  # Or, nil if no response should be sent back
38
38
  reply_message
39
39
  end
40
40
  end
41
-
41
+
42
42
  duration = Time.now - start_time - timeout/1000
43
43
  puts "\nReceived #{count} requests in #{duration} seconds at #{count/duration} messages per second"
44
44
  end
@@ -2,7 +2,7 @@
2
2
  # HornetQ Requestor (Client):
3
3
  # Submit a request and wait for a reply
4
4
  # Uses the Requestor Pattern
5
- # The Server (server.rb) must be running first, otherwise this example
5
+ # The Server (server.rb) must be running first, otherwise this example
6
6
  # program will eventually timeout
7
7
  #
8
8
 
@@ -16,7 +16,7 @@ timeout = (ARGV[0] || 5000).to_i
16
16
 
17
17
  # Using Connect.start since a session must be started in order to consume messages
18
18
  HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
19
-
19
+
20
20
  # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
21
21
  session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
22
22
 
@@ -27,7 +27,7 @@ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
27
27
  # Create non-durable message
28
28
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
29
29
  message.body = "Some request data"
30
-
30
+
31
31
  # Send message to the address
32
32
  puts "Send request message and wait for Reply"
33
33
  if reply = requestor.request(message, timeout)
@@ -35,6 +35,6 @@ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
35
35
  else
36
36
  puts "Time out, No reply received after #{timeout/1000} seconds"
37
37
  end
38
-
38
+
39
39
  end
40
40
  end
@@ -20,18 +20,18 @@ HornetQ::Client::Connection.start_session(:connection=> {:uri => 'hornetq://loca
20
20
  session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
21
21
 
22
22
  session.server('ServerQueue', timeout) do |server|
23
- puts "Waiting for Requests..."
23
+ puts "Waiting for Requests..."
24
24
  server.run do |request_message|
25
25
  puts "Received:[#{request_message.inspect}]"
26
-
26
+
27
27
  # Create Reply Message
28
28
  reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
29
29
  reply_message.body = "Echo [#{request_message.body}]"
30
-
30
+
31
31
  # The result of this block is the message to be sent back to the requestor (client)
32
32
  # Or, nil if no response should be sent back
33
33
  reply_message
34
34
  end
35
35
  end
36
-
36
+
37
37
  end
@@ -11,10 +11,10 @@ require 'hornetq'
11
11
 
12
12
  # Using Connect.start since a session must be started in order to consume messages
13
13
  HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
14
-
14
+
15
15
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
16
16
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
-
17
+
18
18
  # Consume All messages from the queue and gather statistics
19
19
  stats = session.consume(:queue_name => 'TestQueue', :timeout=> 0, :statistics=>true) do |message|
20
20
  p message
@@ -15,12 +15,12 @@ session_count = (ARGV[1] || 1).to_i
15
15
 
16
16
  # Using Connect.start since a session must be started in order to consume messages
17
17
  HornetQ::Client::Connection.connection('hornetq://localhost') do |connection|
18
-
18
+
19
19
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
20
20
  connection.session do |session|
21
21
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
22
22
  end
23
-
23
+
24
24
  # Consume All messages from the queue and gather statistics
25
25
  # on_message will call the supplied block for every message received in another
26
26
  # thread. As a result, the on_message call returns immediately!
@@ -28,18 +28,18 @@ HornetQ::Client::Connection.connection('hornetq://localhost') do |connection|
28
28
  #
29
29
  # :session_count can be used to spawn multiple consumers simultaneously, each
30
30
  # receiving messages simultaneously on their own threads
31
- connection.on_message(:queue_name => 'TestQueue',
31
+ connection.on_message(:queue_name => 'TestQueue',
32
32
  :session_count => session_count,
33
33
  :statistics => true) do |message|
34
34
  p message
35
35
  puts "=================================="
36
36
  message.acknowledge
37
37
  end
38
-
38
+
39
39
  puts "Started #{session_count} consumers, will wait for #{sleep_time/1000} seconds before shutting down"
40
40
  # Wait for sleep_time before shutting down the server
41
41
  sleep(sleep_time/1000)
42
-
42
+
43
43
  connection.on_message_statistics.each do |stats|
44
44
  puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
45
45
  end
@@ -11,10 +11,10 @@ require 'hornetq'
11
11
 
12
12
  # Using Connect.start since a session must be started in order to consume messages
13
13
  HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
14
-
14
+
15
15
  # Create the non-durable TestQueue to receive messages sent to the TestAddress
16
16
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
-
17
+
18
18
  session.consumer('TestQueue') do |consumer|
19
19
  # Receive a single message, return immediately if no message available
20
20
  if message = consumer.receive_immediate
@@ -14,7 +14,7 @@ require 'hornetq'
14
14
  HornetQ::Client::Connection.session('hornetq://localhost') do |session|
15
15
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
16
16
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
-
17
+
18
18
  # Using the Producer pattern send messages to the Address 'TestAddress'
19
19
  session.producer('TestAddress') do |producer|
20
20
  # Create a non-durable message
@@ -24,9 +24,9 @@ HornetQ::Client::Connection.session('hornetq://localhost') do |session|
24
24
  # Always set the message type prior to setting the body so that the message
25
25
  # is correctly created for you
26
26
  message.body = "#{Time.now}: ### Hello, World ###"
27
-
27
+
28
28
  producer.send(message)
29
-
29
+
30
30
  puts "Sent Message: #{message.inspect}"
31
31
  end
32
32
  end
@@ -13,12 +13,12 @@ require 'sync'
13
13
  # batch files. Rather than just flood the queue with every record from a file
14
14
  # the Batch Client Pattern can be used to only send out a batch of requests at
15
15
  # a time and when sufficient responses have been received, send another batch.
16
- #
16
+ #
17
17
  # The following additional features can be implemented in this pattern
18
18
  # * Stop the batch if say 80% of records fail in the first batch, etc.
19
19
  # * Support pause and resume of batch processing
20
20
  # * Support restart and recoverability
21
- #
21
+ #
22
22
  # See the Resque example for implementations of some of the above capabilities
23
23
  #
24
24
  class BatchClientPattern
@@ -33,11 +33,11 @@ class BatchClientPattern
33
33
  @consumer = session.create_consumer(reply_queue)
34
34
  @session = session
35
35
  session.start
36
-
36
+
37
37
  @counter_sync = Sync.new
38
38
  @processed = 0
39
39
  end
40
-
40
+
41
41
  # Before re-using a batch pattern, reset all internal counters
42
42
  def reset
43
43
  @counter_sync.synchronize(:EX) do
@@ -45,12 +45,12 @@ class BatchClientPattern
45
45
  @sucessful = 0
46
46
  end
47
47
  end
48
-
48
+
49
49
  # Return the current message count
50
50
  def processed
51
51
  @counter_sync.synchronize(:SH) { @sucessful + @processed }
52
52
  end
53
-
53
+
54
54
  # Increment Successful response counter by supplied count
55
55
  def inc_sucessful(count=1)
56
56
  @counter_sync.synchronize(:EX) { @sucessful += count }
@@ -60,7 +60,7 @@ class BatchClientPattern
60
60
  def sucessful
61
61
  @counter_sync.synchronize(:SH) { @sucessful }
62
62
  end
63
-
63
+
64
64
  # Increment Successful response counter by supplied count
65
65
  def inc_failed(count=1)
66
66
  @counter_sync.synchronize(:EX) { @failed += count }
@@ -70,7 +70,7 @@ class BatchClientPattern
70
70
  def failed
71
71
  @counter_sync.synchronize(:SH) { @failed }
72
72
  end
73
-
73
+
74
74
  # Send x messages
75
75
  def send(total_count)
76
76
  #print "Sending #{total_count} messages"
@@ -86,7 +86,7 @@ class BatchClientPattern
86
86
  duration = Time.now - start_time
87
87
  #printf "\nSend %5d msg, %5.2f s, %10.2f msg/s\n", total_count, duration, total_count/duration
88
88
  end
89
-
89
+
90
90
  # Receive Reply messages calling the supplied block for each message
91
91
  # passing in the message received from the server.
92
92
  # After the block returns, the message is automatically acknowledged
@@ -102,7 +102,7 @@ class BatchClientPattern
102
102
  p exc
103
103
  end
104
104
  end
105
-
105
+
106
106
  def close
107
107
  @producer.close
108
108
  @consumer.close
@@ -116,7 +116,7 @@ end
116
116
  # Create a Resque Job with the ability to report status
117
117
  #
118
118
  class HornetQJob < Resque::JobWithStatus
119
-
119
+
120
120
  # Set the name of the queue to use for this Job Worker
121
121
  @queue = "hornetq_job"
122
122
 
@@ -126,14 +126,14 @@ class HornetQJob < Resque::JobWithStatus
126
126
  batching_size = (options['batching_size'] || 80).to_i
127
127
  address = options['address'] || 'processor'
128
128
  receive_thread = nil
129
-
129
+
130
130
  # Create a HornetQ session
131
131
  count = 0
132
132
  HornetQ::Client::Connection.session('hornetq://localhost') do |session|
133
133
  batching_size = total_count if batching_size > total_count
134
-
134
+
135
135
  client = BatchClient.new(session, address)
136
-
136
+
137
137
  # Start receive thread
138
138
  receive_thread = Thread.new do
139
139
  client.receive do |message|
@@ -141,7 +141,7 @@ class HornetQJob < Resque::JobWithStatus
141
141
  client.inc_sucessful
142
142
  end
143
143
  end
144
-
144
+
145
145
  times = (total_count/batching_size).to_i
146
146
  puts "Performing #{times} loops"
147
147
  times.times do |i|
@@ -156,11 +156,11 @@ class HornetQJob < Resque::JobWithStatus
156
156
  #puts "\nReceived #{received_count} messages"
157
157
  if received_count >= 0.8 * count
158
158
  puts ""
159
- break
159
+ break
160
160
  end
161
161
  end
162
162
  end
163
-
163
+
164
164
  while client.counter < total_count
165
165
  sleep 0.1
166
166
  print "*"
@@ -177,7 +177,7 @@ end
177
177
  if __FILE__ == $0
178
178
  # Make sure you have a worker running
179
179
  # jruby resque_worker.rb
180
-
180
+
181
181
  options = {
182
182
  'total_count' => (ARGV[0] || 4000).to_i,
183
183
  'batching_size' => (ARGV[1] || 40).to_i,
@@ -187,7 +187,7 @@ if __FILE__ == $0
187
187
  puts "Creating the HornetQJob"
188
188
  job_id = HornetQJob.create(options)
189
189
  puts "Got back #{job_id}"
190
-
190
+
191
191
  # check the status until its complete
192
192
  while status = Resque::Status.get(job_id) and !status.completed? && !status.failed? &&!status.killed?
193
193
  sleep 1