jruby-hornetq 0.2.5.alpha → 0.3.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/HISTORY.md +12 -0
  2. data/Rakefile +13 -1
  3. data/bin/hornetq_server +2 -2
  4. data/examples/README +6 -0
  5. data/examples/{client/advanced → advanced}/batch_client.rb +18 -34
  6. data/examples/advanced/bytes_producer.rb +25 -0
  7. data/examples/advanced/client.rb +56 -0
  8. data/examples/{client/advanced/multi_client.rb → advanced/client_session_pooling.rb} +29 -25
  9. data/examples/advanced/consume_on_message.rb +50 -0
  10. data/examples/advanced/consumer.rb +31 -0
  11. data/examples/{client/advanced → advanced}/hornetq.yml +8 -6
  12. data/examples/advanced/multi_client.rb +71 -0
  13. data/examples/advanced/producer.rb +37 -0
  14. data/examples/advanced/server.rb +44 -0
  15. data/examples/client-server/client.rb +40 -0
  16. data/examples/client-server/server.rb +37 -0
  17. data/examples/producer-consumer/consume_all.rb +25 -0
  18. data/examples/producer-consumer/consume_on_message.rb +46 -0
  19. data/examples/producer-consumer/consumer.rb +27 -0
  20. data/examples/producer-consumer/producer.rb +32 -0
  21. data/examples/{client/resque → resque}/hornetq_job.rb +2 -2
  22. data/examples/{client/resque → resque}/processor.rb +1 -1
  23. data/examples/{client/resque → resque}/readme.md +0 -0
  24. data/examples/{client/resque → resque}/resque_conf.rb +0 -0
  25. data/examples/{client/resque → resque}/resque_worker.rb +0 -0
  26. data/examples/{client/resque → resque}/sleep_job.rb +0 -0
  27. data/examples/{server → server-config}/backup_server.yml +0 -0
  28. data/examples/{server → server-config}/live_server.yml +0 -0
  29. data/examples/{server → server-config}/standalone_server.yml +0 -0
  30. data/examples/{client → simple}/invm.rb +6 -7
  31. data/examples/{advanced/transaction-failover → transaction-failover}/README +0 -0
  32. data/examples/{advanced/transaction-failover → transaction-failover}/consumer.rb +4 -1
  33. data/examples/{advanced/transaction-failover → transaction-failover}/hornetq.yml +6 -3
  34. data/examples/{advanced/transaction-failover → transaction-failover}/producer.rb +8 -3
  35. data/examples/{simple_worker → worker}/README +0 -0
  36. data/examples/worker/hornetq.yml +26 -0
  37. data/examples/worker/producer.rb +71 -0
  38. data/examples/{simple_worker → worker}/test_object.rb +0 -0
  39. data/examples/worker/worker.rb +72 -0
  40. data/lib/hornetq/client.rb +1 -1
  41. data/lib/hornetq/client/{factory.rb → connection.rb} +153 -86
  42. data/lib/hornetq/client/message_handler.rb +3 -3
  43. data/lib/hornetq/client/org_hornetq_api_core_client_client_session.rb +187 -26
  44. data/lib/hornetq/client/org_hornetq_core_client_impl_client_consumer_impl.rb +26 -9
  45. data/lib/hornetq/client/org_hornetq_core_client_impl_client_message_impl.rb +190 -35
  46. data/lib/hornetq/client/session_pool.rb +4 -4
  47. data/lib/hornetq/common/log_delegate.rb +17 -15
  48. data/lib/hornetq/common/logging.rb +20 -7
  49. data/lib/hornetq/common/org_hornetq_core_logging_logger.rb +11 -9
  50. data/lib/hornetq/server.rb +86 -3
  51. data/lib/hornetq/{org_hornetq_core_server_hornet_q_server.rb → server/org_hornetq_core_server_hornet_q_server.rb} +1 -1
  52. data/lib/hornetq/uri.rb +4 -0
  53. data/test/client_connection_test.rb +158 -0
  54. data/test/logging_test.rb +32 -0
  55. data/test/server_test.rb +208 -0
  56. metadata +47 -48
  57. data/examples/client/advanced/bytes_producer.rb +0 -21
  58. data/examples/client/advanced/client.rb +0 -47
  59. data/examples/client/advanced/consumer.rb +0 -35
  60. data/examples/client/advanced/multi_consumer.rb +0 -54
  61. data/examples/client/advanced/producer.rb +0 -35
  62. data/examples/client/advanced/server.rb +0 -39
  63. data/examples/client/client.rb +0 -31
  64. data/examples/client/consumer.rb +0 -22
  65. data/examples/client/data/bindings/hornetq-bindings-1.bindings +0 -0
  66. data/examples/client/data/bindings/hornetq-bindings-2.bindings +0 -0
  67. data/examples/client/data/journal/hornetq-data-1.hq +0 -0
  68. data/examples/client/data/journal/hornetq-data-2.hq +0 -0
  69. data/examples/client/producer.rb +0 -21
  70. data/examples/client/server.rb +0 -31
  71. data/examples/simple_worker/hornetq.yml +0 -34
  72. data/examples/simple_worker/producer.rb +0 -54
  73. data/examples/simple_worker/worker.rb +0 -49
  74. data/lib/data/bindings/hornetq-bindings-1.bindings +0 -0
  75. data/lib/data/bindings/hornetq-bindings-2.bindings +0 -0
  76. data/lib/hornetq/server/factory.rb +0 -87
  77. data/test/server_factory_test.rb +0 -183
@@ -0,0 +1,71 @@
1
+ #
2
+ # HornetQ Requestor:
3
+ # Multithreaded clients all doing requests
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 'yaml'
11
+ require 'hornetq'
12
+
13
+ timeout = (ARGV[0] || 30000).to_i
14
+ thread_count = (ARGV[1] || 2).to_i
15
+ request_count = (ARGV[2] || 5).to_i
16
+
17
+ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
18
+
19
+ # Sample thread that does some work and then does a request-response call
20
+ def worker_thread(id, connection, timeout, request_count)
21
+ begin
22
+ connection.start_session do |session|
23
+ start_time = Time.now
24
+
25
+ # Use Requestor (Client) Pattern to do a "RPC like" call to a server
26
+ # Under the covers the requestor creates a temporary dynamic reply to queue
27
+ # for the server to send the reply message to
28
+ session.requestor('ServerAddress') do |requestor|
29
+ # Create non-durable message
30
+ puts "Sending #{request_count} requests"
31
+ (1..request_count).each do |i|
32
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
33
+ message.body = "Some request data"
34
+ # Set the user managed message id
35
+ message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
36
+
37
+ if reply = requestor.request(message, timeout)
38
+ puts "Thread[#{id}]:Received Response: #{reply.inspect}" if request_count < 10
39
+ puts "Thread[#{id}]: Message:[#{reply.body.inspect}]" if request_count < 10
40
+ print ".#{id}" if request_count >= 10
41
+ else
42
+ puts "Thread[#{id}]:Time out, No reply received after #{timeout/1000} seconds"
43
+ end
44
+ puts "Thread:#{id}=>#{i}" if i%1000 == 0
45
+ end
46
+ end
47
+
48
+ duration = Time.now - start_time
49
+ puts "\nThread[#{id}]:Made #{request_count} calls in #{duration} seconds at #{request_count/duration} synchronous requests per second"
50
+ end
51
+
52
+ rescue Exception => exc
53
+ puts "Thread[#{id}]: Terminating due to Exception:#{exc.inspect}"
54
+ puts exc.backtrace
55
+ end
56
+ puts "Thread[#{id}]: Complete"
57
+ end
58
+
59
+ # Create a HornetQ Connection
60
+ HornetQ::Client::Connection.connection(config[:connection]) do |connection|
61
+ threads = []
62
+
63
+ # Start threads passing in an id and the connection so that the thread
64
+ # can create its own session
65
+ thread_count.times do |i|
66
+ threads << Thread.new { worker_thread(i, connection, timeout, request_count) }
67
+ end
68
+ # Since each thread will terminate once it has completed its required number
69
+ # of requests, we can just wait for all the threads to terminate
70
+ threads.each {|t| t.join}
71
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # HornetQ Producer:
3
+ # Write messages to the queue
4
+ # This example will display the message count after every 1000
5
+ # messages written to the address
6
+ #
7
+
8
+ # Allow examples to be run in-place without requiring a gem install
9
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
10
+
11
+ require 'rubygems'
12
+ require 'yaml'
13
+ require 'hornetq'
14
+
15
+ count = (ARGV[0] || 1).to_i
16
+ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
17
+
18
+ # Create a HornetQ session
19
+ HornetQ::Client::Connection.session(config) do |session|
20
+ # Create a non-durable TestQueue to receive messages sent to the TestAddress
21
+ session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
22
+ start_time = Time.now
23
+
24
+ session.producer('TestAddress') do |producer|
25
+ puts "Sending messages"
26
+ (1..count).each do |i|
27
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
28
+ message.body = "#{Time.now}: ### Hello, World ###"
29
+
30
+ producer.send(message)
31
+ puts "#{i}\n" if i%1000 == 0
32
+ end
33
+ end
34
+
35
+ duration = Time.now - start_time
36
+ puts "Delivered #{count} messages in #{duration} seconds at #{count/duration} messages per second"
37
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # HornetQ Consumer:
3
+ # Reply to a request
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 'yaml'
11
+ require 'hornetq'
12
+
13
+ timeout = (ARGV[0] || 60000).to_i
14
+
15
+ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
16
+
17
+ # Create a HornetQ session
18
+ HornetQ::Client::Connection.start_session(config) do |session|
19
+ # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
20
+ session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
21
+
22
+ count = 0
23
+ start_time = Time.now
24
+
25
+ session.server('ServerQueue', timeout) do |server|
26
+ puts "Server started and waiting for requests ..."
27
+ server.run do |request_message|
28
+ count += 1
29
+ print '.'
30
+ puts "#{count}" if count%1000 == 0
31
+
32
+ # Create Reply Message
33
+ reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
34
+ reply_message.body = "Echo [#{request_message.body}]"
35
+
36
+ # The result of this block is the message to be sent back to the requestor (client)
37
+ # Or, nil if no response should be sent back
38
+ reply_message
39
+ end
40
+ end
41
+
42
+ duration = Time.now - start_time - timeout/1000
43
+ puts "\nReceived #{count} requests in #{duration} seconds at #{count/duration} messages per second"
44
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # HornetQ Requestor (Client):
3
+ # Submit a request and wait for a reply
4
+ # Uses the Requestor Pattern
5
+ # The Server (server.rb) must be running first, otherwise this example
6
+ # program will eventually timeout
7
+ #
8
+
9
+ # Allow examples to be run in-place without requiring a gem install
10
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
11
+
12
+ require 'rubygems'
13
+ require 'hornetq'
14
+
15
+ timeout = (ARGV[0] || 5000).to_i
16
+
17
+ # Using Connect.start since a session must be started in order to consume messages
18
+ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
19
+
20
+ # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
21
+ session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
22
+
23
+ # Use Requestor (Client) Pattern to do a "RPC like" call to a server
24
+ # Under the covers the requestor creates a temporary dynamic reply to queue
25
+ # for the server to send the reply message to
26
+ session.requestor('ServerAddress') do |requestor|
27
+ # Create non-durable message
28
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
29
+ message.body = "Some request data"
30
+
31
+ # Send message to the address
32
+ puts "Send request message and wait for Reply"
33
+ if reply = requestor.request(message, timeout)
34
+ puts "Received Response: #{reply.inspect}"
35
+ else
36
+ puts "Time out, No reply received after #{timeout/1000} seconds"
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # HornetQ Consumer:
3
+ # Reply to a request
4
+ # Implements the Server Pattern
5
+ # The reply message is sent back to the reply to address supplied by the
6
+ # requestor
7
+ #
8
+
9
+ # Allow examples to be run in-place without requiring a gem install
10
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
11
+
12
+ require 'rubygems'
13
+ require 'hornetq'
14
+
15
+ # By default the server will shutdown after 60 seconds, set to 0 to never shutdown
16
+ timeout = (ARGV[0] || 60000).to_i
17
+
18
+ HornetQ::Client::Connection.start_session(:connection=> {:uri => 'hornetq://localhost'}) do |session|
19
+ # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
20
+ session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
21
+
22
+ session.server('ServerQueue', timeout) do |server|
23
+ puts "Waiting for Requests..."
24
+ server.run do |request_message|
25
+ puts "Received:[#{request_message.inspect}]"
26
+
27
+ # Create Reply Message
28
+ reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
29
+ reply_message.body = "Echo [#{request_message.body}]"
30
+
31
+ # The result of this block is the message to be sent back to the requestor (client)
32
+ # Or, nil if no response should be sent back
33
+ reply_message
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # HornetQ Consumer:
3
+ # Read a single message from 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
+ # Using Connect.start since a session must be started in order to consume messages
13
+ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
14
+
15
+ # Create a non-durable TestQueue to receive messages sent to the TestAddress
16
+ session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
+
18
+ # Consume All messages from the queue and gather statistics
19
+ stats = session.consume(:queue_name => 'TestQueue', :timeout=> 0, :statistics=>true) do |message|
20
+ p message
21
+ puts "=================================="
22
+ message.acknowledge
23
+ end
24
+ puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
25
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # HornetQ Consumer:
3
+ # Use Connection::on_message to consume all messages in separate
4
+ # threads so as not to block the main thread
5
+ #
6
+
7
+ # Allow examples to be run in-place without requiring a gem install
8
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
9
+
10
+ require 'rubygems'
11
+ require 'hornetq'
12
+
13
+ sleep_time = (ARGV[0] || 60000).to_i
14
+ session_count = (ARGV[1] || 1).to_i
15
+
16
+ # Using Connect.start since a session must be started in order to consume messages
17
+ HornetQ::Client::Connection.connection('hornetq://localhost') do |connection|
18
+
19
+ # Create a non-durable TestQueue to receive messages sent to the TestAddress
20
+ connection.session do |session|
21
+ session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
22
+ end
23
+
24
+ # Consume All messages from the queue and gather statistics
25
+ # on_message will call the supplied block for every message received in another
26
+ # thread. As a result, the on_message call returns immediately!
27
+ # Other work can be performed on this thread, or just a sleep as in this example
28
+ #
29
+ # :session_count can be used to spawn multiple consumers simultaneously, each
30
+ # receiving messages simultaneously on their own threads
31
+ connection.on_message(:queue_name => 'TestQueue',
32
+ :session_count => session_count,
33
+ :statistics => true) do |message|
34
+ p message
35
+ puts "=================================="
36
+ message.acknowledge
37
+ end
38
+
39
+ puts "Started #{session_count} consumers, will wait for #{sleep_time/1000} seconds before shutting down"
40
+ # Wait for sleep_time before shutting down the server
41
+ sleep(sleep_time/1000)
42
+
43
+ connection.on_message_statistics.each do |stats|
44
+ puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # HornetQ Consumer:
3
+ # Read a single message from 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
+ # Using Connect.start since a session must be started in order to consume messages
13
+ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
14
+
15
+ # Create the non-durable TestQueue to receive messages sent to the TestAddress
16
+ session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
+
18
+ session.consumer('TestQueue') do |consumer|
19
+ # Receive a single message, return immediately if no message available
20
+ if message = consumer.receive_immediate
21
+ puts "Received:[#{message.body}]"
22
+ message.acknowledge
23
+ else
24
+ puts "No message found"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
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
+ # Using Connect.session since a session does not have to be started in order
13
+ # to produce messages
14
+ HornetQ::Client::Connection.session('hornetq://localhost') do |session|
15
+ # Create a non-durable TestQueue to receive messages sent to the TestAddress
16
+ session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
17
+
18
+ # Using the Producer pattern send messages to the Address 'TestAddress'
19
+ session.producer('TestAddress') do |producer|
20
+ # Create a non-durable message
21
+ message = session.create_message(false)
22
+ # Mark message as text
23
+ message.type_sym = :text
24
+ # Always set the message type prior to setting the body so that the message
25
+ # is correctly created for you
26
+ message.body = "#{Time.now}: ### Hello, World ###"
27
+
28
+ producer.send(message)
29
+
30
+ puts "Sent Message: #{message.inspect}"
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # Allow examples to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../../lib'
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
3
3
 
4
4
  require 'rubygems'
5
5
  require 'resque/job_with_status' # in rails you would probably do this in an initializer
@@ -129,7 +129,7 @@ class HornetQJob < Resque::JobWithStatus
129
129
 
130
130
  # Create a HornetQ session
131
131
  count = 0
132
- HornetQ::Client::Factory.session('hornetq://localhost') do |session|
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)
@@ -14,7 +14,7 @@ timeout = (ARGV[0] || 300000).to_i
14
14
 
15
15
  q_name = 'processor'
16
16
 
17
- HornetQ::Client::Factory.start('hornetq://localhost') do |session|
17
+ HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
18
18
  begin
19
19
  # Create durable queue with matching address
20
20
  session.create_queue(q_name, q_name, true)
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,23 +10,22 @@ require 'rubygems'
10
10
  require 'hornetq'
11
11
 
12
12
  # Create and start an InVM HornetQ server instance
13
- HornetQ::Server::Factory.start('hornetq://invm') do |server|
13
+ HornetQ::Server.start('hornetq://invm') do |server|
14
14
  # Allow a CTRL-C to stop this process
15
15
  server.enable_shutdown_on_signal
16
16
 
17
- HornetQ::Client::Factory.start('hornetq://invm') do |session|
17
+ HornetQ::Client::Connection.start_session('hornetq://invm') do |session|
18
18
  session.create_queue("MyAddress","MyQueue", nil, false)
19
-
19
+
20
20
  producer = session.create_producer('MyAddress')
21
21
  consumer = session.create_consumer('MyQueue')
22
-
22
+
23
23
  # Create a non-durable message to send
24
24
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
25
25
  message.body = "#{Time.now}: ### Hello, World ###"
26
-
26
+
27
27
  producer.send(message)
28
-
29
-
28
+
30
29
  # Receive a single message, return immediately if no message available
31
30
  if message = consumer.receive_immediate
32
31
  puts "Received:[#{message.body}]"