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.
- data/HISTORY.md +12 -0
- data/Rakefile +13 -1
- data/bin/hornetq_server +2 -2
- data/examples/README +6 -0
- data/examples/{client/advanced → advanced}/batch_client.rb +18 -34
- data/examples/advanced/bytes_producer.rb +25 -0
- data/examples/advanced/client.rb +56 -0
- data/examples/{client/advanced/multi_client.rb → advanced/client_session_pooling.rb} +29 -25
- data/examples/advanced/consume_on_message.rb +50 -0
- data/examples/advanced/consumer.rb +31 -0
- data/examples/{client/advanced → advanced}/hornetq.yml +8 -6
- data/examples/advanced/multi_client.rb +71 -0
- data/examples/advanced/producer.rb +37 -0
- data/examples/advanced/server.rb +44 -0
- data/examples/client-server/client.rb +40 -0
- data/examples/client-server/server.rb +37 -0
- data/examples/producer-consumer/consume_all.rb +25 -0
- data/examples/producer-consumer/consume_on_message.rb +46 -0
- data/examples/producer-consumer/consumer.rb +27 -0
- data/examples/producer-consumer/producer.rb +32 -0
- data/examples/{client/resque → resque}/hornetq_job.rb +2 -2
- data/examples/{client/resque → resque}/processor.rb +1 -1
- data/examples/{client/resque → resque}/readme.md +0 -0
- data/examples/{client/resque → resque}/resque_conf.rb +0 -0
- data/examples/{client/resque → resque}/resque_worker.rb +0 -0
- data/examples/{client/resque → resque}/sleep_job.rb +0 -0
- data/examples/{server → server-config}/backup_server.yml +0 -0
- data/examples/{server → server-config}/live_server.yml +0 -0
- data/examples/{server → server-config}/standalone_server.yml +0 -0
- data/examples/{client → simple}/invm.rb +6 -7
- data/examples/{advanced/transaction-failover → transaction-failover}/README +0 -0
- data/examples/{advanced/transaction-failover → transaction-failover}/consumer.rb +4 -1
- data/examples/{advanced/transaction-failover → transaction-failover}/hornetq.yml +6 -3
- data/examples/{advanced/transaction-failover → transaction-failover}/producer.rb +8 -3
- data/examples/{simple_worker → worker}/README +0 -0
- data/examples/worker/hornetq.yml +26 -0
- data/examples/worker/producer.rb +71 -0
- data/examples/{simple_worker → worker}/test_object.rb +0 -0
- data/examples/worker/worker.rb +72 -0
- data/lib/hornetq/client.rb +1 -1
- data/lib/hornetq/client/{factory.rb → connection.rb} +153 -86
- data/lib/hornetq/client/message_handler.rb +3 -3
- data/lib/hornetq/client/org_hornetq_api_core_client_client_session.rb +187 -26
- data/lib/hornetq/client/org_hornetq_core_client_impl_client_consumer_impl.rb +26 -9
- data/lib/hornetq/client/org_hornetq_core_client_impl_client_message_impl.rb +190 -35
- data/lib/hornetq/client/session_pool.rb +4 -4
- data/lib/hornetq/common/log_delegate.rb +17 -15
- data/lib/hornetq/common/logging.rb +20 -7
- data/lib/hornetq/common/org_hornetq_core_logging_logger.rb +11 -9
- data/lib/hornetq/server.rb +86 -3
- data/lib/hornetq/{org_hornetq_core_server_hornet_q_server.rb → server/org_hornetq_core_server_hornet_q_server.rb} +1 -1
- data/lib/hornetq/uri.rb +4 -0
- data/test/client_connection_test.rb +158 -0
- data/test/logging_test.rb +32 -0
- data/test/server_test.rb +208 -0
- metadata +47 -48
- data/examples/client/advanced/bytes_producer.rb +0 -21
- data/examples/client/advanced/client.rb +0 -47
- data/examples/client/advanced/consumer.rb +0 -35
- data/examples/client/advanced/multi_consumer.rb +0 -54
- data/examples/client/advanced/producer.rb +0 -35
- data/examples/client/advanced/server.rb +0 -39
- data/examples/client/client.rb +0 -31
- data/examples/client/consumer.rb +0 -22
- data/examples/client/data/bindings/hornetq-bindings-1.bindings +0 -0
- data/examples/client/data/bindings/hornetq-bindings-2.bindings +0 -0
- data/examples/client/data/journal/hornetq-data-1.hq +0 -0
- data/examples/client/data/journal/hornetq-data-2.hq +0 -0
- data/examples/client/producer.rb +0 -21
- data/examples/client/server.rb +0 -31
- data/examples/simple_worker/hornetq.yml +0 -34
- data/examples/simple_worker/producer.rb +0 -54
- data/examples/simple_worker/worker.rb +0 -49
- data/lib/data/bindings/hornetq-bindings-1.bindings +0 -0
- data/lib/data/bindings/hornetq-bindings-2.bindings +0 -0
- data/lib/hornetq/server/factory.rb +0 -87
- data/test/server_factory_test.rb +0 -183
data/HISTORY.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.3.0 (2011-02-16)
|
2
|
+
|
3
|
+
* Rename HornetQ::Client::Factory to HornetQ::Client::Connection
|
4
|
+
* Add Client Tests
|
5
|
+
* Fix logging to HornetQ default logger when no other logger supplied
|
6
|
+
* Re-arrange Examples
|
7
|
+
* Add Worker samples
|
8
|
+
|
9
|
+
## 0.2.5 (2011-02-07)
|
10
|
+
|
11
|
+
* Add Rails and Ruby Logging
|
12
|
+
|
1
13
|
## 0.2.1 (2011-01-26)
|
2
14
|
|
3
15
|
* Support for InVM Server
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
raise "jruby-hornetq must be built with JRuby: try again with `jruby -S rake'" unless defined?(JRUBY_VERSION)
|
2
2
|
|
3
3
|
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
4
5
|
require 'date'
|
5
6
|
require 'java'
|
6
7
|
|
@@ -8,7 +9,7 @@ desc "Build gem"
|
|
8
9
|
task :gem do |t|
|
9
10
|
gemspec = Gem::Specification.new do |s|
|
10
11
|
s.name = 'jruby-hornetq'
|
11
|
-
s.version = '0.
|
12
|
+
s.version = '0.3.0.alpha'
|
12
13
|
s.authors = ['Reid Morrison', 'Brad Pardee']
|
13
14
|
s.email = ['rubywmq@gmail.com', 'bpardee@gmail.com']
|
14
15
|
s.homepage = 'https://github.com/ClarityServices/jruby-hornetq'
|
@@ -17,7 +18,18 @@ task :gem do |t|
|
|
17
18
|
s.summary = 'JRuby interface into HornetQ'
|
18
19
|
s.files = FileList["./**/*"].exclude('*.gem', './nbproject/*').map{|f| f.sub(/^\.\//, '')}
|
19
20
|
s.has_rdoc = true
|
21
|
+
s.executables = %w(hornetq_server)
|
20
22
|
s.add_dependency "gene_pool", "~> 1.1.1"
|
21
23
|
end
|
22
24
|
Gem::Builder.new(gemspec).build
|
23
25
|
end
|
26
|
+
|
27
|
+
desc "Run Test Suite"
|
28
|
+
task :test do
|
29
|
+
Rake::TestTask.new(:functional) do |t|
|
30
|
+
t.test_files = FileList['test/*_test.rb']
|
31
|
+
t.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::Task['functional'].invoke
|
35
|
+
end
|
data/bin/hornetq_server
CHANGED
@@ -32,10 +32,10 @@ if ARGV[0] =~ /\.ya?ml$/
|
|
32
32
|
config = config[ARGV[i]] || config[ARGV[i].to_sym]
|
33
33
|
end
|
34
34
|
puts "config=#{config.inspect}"
|
35
|
-
server = HornetQ::Server
|
35
|
+
server = HornetQ::Server.create_server(config)
|
36
36
|
else
|
37
37
|
uri = ARGV[0]
|
38
|
-
server = HornetQ::Server
|
38
|
+
server = HornetQ::Server.create_server(uri)
|
39
39
|
end
|
40
40
|
server.enable_shutdown_on_signal
|
41
41
|
server.start
|
data/examples/README
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Most of the examples will run in-place without requiring a gem install. However,
|
2
|
+
to start the hornetq_server you must set the following environment variables
|
3
|
+
adjusting the value of jruby-hornetq-home as necessary.
|
4
|
+
|
5
|
+
export RUBYLIB=<jruby-hornetq-home>/lib
|
6
|
+
export PATH=<jruby-hornetq-home>/bin:$PATH
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Once 80% of the replies are back, it will send the next batch
|
13
13
|
|
14
14
|
# Allow examples to be run in-place without requiring a gem install
|
15
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '
|
15
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
|
16
16
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'yaml'
|
@@ -21,25 +21,21 @@ require 'sync'
|
|
21
21
|
|
22
22
|
total_count = (ARGV[0] || 100).to_i
|
23
23
|
batching_size = (ARGV[1] || 10).to_i
|
24
|
-
request_address = 'jms.queue.ExampleQueue'
|
25
24
|
|
25
|
+
request_address = 'ServerAddress'
|
26
26
|
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
27
27
|
|
28
28
|
class BatchClientPattern
|
29
|
-
def initialize(
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
rescue NativeException => exc
|
35
|
-
p exc
|
36
|
-
end
|
37
|
-
@consumer = session.create_consumer(reply_queue)
|
38
|
-
@session = session
|
39
|
-
session.start
|
40
|
-
|
29
|
+
def initialize(connection, request_address)
|
30
|
+
@session = connection.create_session
|
31
|
+
@producer = @session.create_producer(request_address)
|
32
|
+
@reply_queue = "#{request_address}.#{Java::java.util::UUID.randomUUID.toString}"
|
33
|
+
@session.create_temporary_queue(@reply_queue, @reply_queue)
|
41
34
|
@counter_sync = Sync.new
|
42
35
|
@counter = 0
|
36
|
+
|
37
|
+
# Start consuming replies
|
38
|
+
connection.on_message(:queue_name => @reply_queue) {|message| process_reply(message) }
|
43
39
|
end
|
44
40
|
|
45
41
|
# Increment Message Counter
|
@@ -63,7 +59,7 @@ class BatchClientPattern
|
|
63
59
|
start_time = Time.now
|
64
60
|
total_count.times do |i|
|
65
61
|
message = @session.create_message(HornetQ::Client::Message::TEXT_TYPE,true)
|
66
|
-
message.reply_to_queue_name = @
|
62
|
+
message.reply_to_queue_name = @reply_queue
|
67
63
|
message.body = "Request Current Time. #{i}"
|
68
64
|
@producer.send(message)
|
69
65
|
print "."
|
@@ -74,35 +70,23 @@ class BatchClientPattern
|
|
74
70
|
end
|
75
71
|
|
76
72
|
# Receive Reply messages
|
77
|
-
def
|
78
|
-
print
|
79
|
-
|
80
|
-
|
81
|
-
print '@'
|
82
|
-
# puts "Received:#{reply}, [#{reply.body}]"
|
83
|
-
inc_counter(1)
|
84
|
-
reply.acknowledge
|
85
|
-
end
|
86
|
-
rescue Exception => exc
|
87
|
-
p exc
|
88
|
-
end
|
73
|
+
def process_reply(message)
|
74
|
+
print '@'
|
75
|
+
inc_counter(1)
|
76
|
+
message.acknowledge
|
89
77
|
end
|
90
78
|
|
91
79
|
def close
|
92
80
|
@producer.close
|
93
|
-
@
|
94
|
-
@session.delete_queue(@consumer.queue_name)
|
81
|
+
@session.close
|
95
82
|
end
|
96
83
|
end
|
97
84
|
|
98
85
|
# Create a HornetQ session
|
99
|
-
HornetQ::Client::
|
86
|
+
HornetQ::Client::Connection.connection(config[:connection]) do |connection|
|
100
87
|
batching_size = total_count if batching_size > total_count
|
101
88
|
|
102
|
-
client = BatchClientPattern.new(
|
103
|
-
|
104
|
-
# Start receive thread
|
105
|
-
receive_thread = Thread.new {client.receive}
|
89
|
+
client = BatchClientPattern.new(connection, request_address)
|
106
90
|
|
107
91
|
times = (total_count/batching_size).to_i
|
108
92
|
puts "Performing #{times} loops"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# HornetQ Producer:
|
3
|
+
# Write binary/bytes 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::Connection.session('hornetq://localhost') do |session|
|
13
|
+
# Create the non-durable TestQueue to receive messages sent to the TestAddress
|
14
|
+
session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
|
15
|
+
|
16
|
+
# Create Producer so that we can send messages to the Address 'jms.queue.ExampleQueue'
|
17
|
+
session.producer('TestAddress') do |producer|
|
18
|
+
|
19
|
+
# Create a non-durable bytes message to send
|
20
|
+
message = session.create_message(HornetQ::Client::Message::BYTES_TYPE,false)
|
21
|
+
message.body = "#{Time.now}: ### Hello, World ###"
|
22
|
+
|
23
|
+
producer.send(message)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# HornetQ Requestor:
|
3
|
+
# Submit a request and wait for a reply
|
4
|
+
# Uses the Requestor Pattern
|
5
|
+
#
|
6
|
+
# The Server (server.rb) must be running first, otherwise this example
|
7
|
+
# program will eventually timeout
|
8
|
+
# Displays a '.' for every request completed
|
9
|
+
# Used for performance measurements
|
10
|
+
#
|
11
|
+
|
12
|
+
# Allow examples to be run in-place without requiring a gem install
|
13
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'yaml'
|
17
|
+
require 'hornetq'
|
18
|
+
|
19
|
+
count = (ARGV[0] || 1).to_i
|
20
|
+
timeout = (ARGV[1] || 30000).to_i
|
21
|
+
|
22
|
+
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
23
|
+
|
24
|
+
# Create a HornetQ session
|
25
|
+
HornetQ::Client::Connection.start_session(config) do |session|
|
26
|
+
# Create a non-durable ServerQueue to receive messages sent to the ServerAddress
|
27
|
+
session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)
|
28
|
+
start_time = Time.now
|
29
|
+
|
30
|
+
# Use Requestor (Client) Pattern to do a "RPC like" call to a server
|
31
|
+
# Under the covers the requestor creates a temporary dynamic reply to queue
|
32
|
+
# for the server to send the reply message to
|
33
|
+
session.requestor('ServerAddress') do |requestor|
|
34
|
+
# Create non-durable message
|
35
|
+
puts "Sending #{count} requests"
|
36
|
+
(1..count).each do |i|
|
37
|
+
message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
|
38
|
+
message.body = "Some request data"
|
39
|
+
# Set the user managed message id
|
40
|
+
message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
|
41
|
+
|
42
|
+
if reply = requestor.request(message, timeout)
|
43
|
+
puts "Received Response: #{reply.inspect}" if count < 10
|
44
|
+
puts " Message:[#{reply.body.inspect}]" if count < 10
|
45
|
+
print "." if count >= 10
|
46
|
+
else
|
47
|
+
puts "Time out, No reply received after #{timeout/1000} seconds"
|
48
|
+
end
|
49
|
+
puts "#{i}" if i%1000 == 0
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
duration = Time.now - start_time
|
55
|
+
puts "\nMade #{count} calls in #{duration} seconds at #{count/duration} synchronous requests per second"
|
56
|
+
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
#
|
2
|
-
# HornetQ Requestor:
|
3
|
-
# Multithreaded clients all doing requests
|
2
|
+
# HornetQ Requestor using session_pooling:
|
3
|
+
# Multithreaded clients all doing requests.
|
4
|
+
#
|
5
|
+
# Shows how the same session can be used safely on different threads
|
6
|
+
# rather than each thread having to create its own session
|
7
|
+
#
|
4
8
|
# Typical scenario is in a Rails app when we need to do a call to a
|
5
9
|
# remote server and block until a response is received
|
6
10
|
#
|
7
|
-
# Shows how to use the session pool so that not every thread has to have its
|
8
|
-
# own session
|
9
|
-
#
|
10
11
|
|
11
12
|
# Allow examples to be run in-place without requiring a gem install
|
12
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '
|
13
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
|
13
14
|
|
14
15
|
require 'rubygems'
|
15
16
|
require 'yaml'
|
16
17
|
require 'hornetq'
|
17
18
|
|
18
|
-
$thread_count = (ARGV[0] ||
|
19
|
+
$thread_count = (ARGV[0] || 2).to_i
|
19
20
|
$timeout = (ARGV[1] || 30000).to_i
|
20
21
|
|
21
22
|
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
@@ -24,10 +25,10 @@ config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
|
24
25
|
def worker_thread(id, session_pool)
|
25
26
|
begin
|
26
27
|
# Obtain a session from the pool and return when complete
|
27
|
-
session_pool.requestor('
|
28
|
+
session_pool.requestor('ServerAddress') do |session, requestor|
|
28
29
|
message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
|
29
30
|
message.body = "Request Current Time"
|
30
|
-
|
31
|
+
|
31
32
|
# Send message to the queue
|
32
33
|
puts "Thread[#{id}]: Sending Request"
|
33
34
|
if reply = requestor.request(message, $timeout)
|
@@ -44,23 +45,26 @@ def worker_thread(id, session_pool)
|
|
44
45
|
puts "Thread[#{id}]: Complete"
|
45
46
|
end
|
46
47
|
|
47
|
-
# Create a HornetQ
|
48
|
-
HornetQ::Client::
|
49
|
-
|
48
|
+
# Create a HornetQ Connection
|
49
|
+
HornetQ::Client::Connection.connection(config[:connection]) do |connection|
|
50
|
+
|
50
51
|
# Create a pool of session connections, all with the same session parameters
|
51
52
|
# The pool is thread-safe and can be accessed concurrently by multiple threads
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
begin
|
54
|
+
session_pool = connection.create_session_pool(config[:session])
|
55
|
+
threads = []
|
56
|
+
|
57
|
+
# Do some work and then lets re-use the session in another thread below
|
58
|
+
worker_thread(9999, session_pool)
|
59
|
+
|
60
|
+
$thread_count.times do |i|
|
61
|
+
# Each thread will get a session from the session pool as needed
|
62
|
+
threads << Thread.new { worker_thread(i, session_pool) }
|
63
|
+
end
|
64
|
+
threads.each {|t| t.join}
|
65
|
+
|
66
|
+
# Important. Remember to close any open sessions in the pool
|
67
|
+
ensure
|
68
|
+
session_pool.close if session_pool
|
61
69
|
end
|
62
|
-
threads.each {|t| t.join}
|
63
|
-
|
64
|
-
# Important. Remember to close any open sessions in the pool
|
65
|
-
session_pool.close
|
66
70
|
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
# Displays a '.' for every message received
|
6
|
+
# Used for performance measurements of consuming messages
|
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 'yaml'
|
13
|
+
require 'rubygems'
|
14
|
+
require 'hornetq'
|
15
|
+
|
16
|
+
sleep_time = (ARGV[0] || 60000).to_i
|
17
|
+
session_count = (ARGV[1] || 1).to_i
|
18
|
+
|
19
|
+
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
20
|
+
|
21
|
+
# Using Connect.start since a session must be started in order to consume messages
|
22
|
+
HornetQ::Client::Connection.connection(config[:connection]) do |connection|
|
23
|
+
|
24
|
+
# Create a non-durable TestQueue to receive messages sent to the TestAddress
|
25
|
+
connection.session(config[:session]) do |session|
|
26
|
+
session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Consume All messages from the queue and gather statistics
|
30
|
+
# on_message will call the supplied block for every message received in another
|
31
|
+
# thread. As a result, the on_message call returns immediately!
|
32
|
+
# Other work can be performed on this thread, or just a sleep as in this example
|
33
|
+
#
|
34
|
+
# :session_count can be used to spawn multiple consumers simultaneously, each
|
35
|
+
# receiving messages simultaneously on their own threads
|
36
|
+
connection.on_message(:queue_name => 'TestQueue',
|
37
|
+
:session_count => session_count,
|
38
|
+
:statistics => true) do |message|
|
39
|
+
print '.'
|
40
|
+
message.acknowledge
|
41
|
+
end
|
42
|
+
|
43
|
+
puts "Started #{session_count} consumers, will wait for #{sleep_time/1000} seconds before shutting down"
|
44
|
+
# Wait for sleep_time before shutting down the server
|
45
|
+
sleep(sleep_time/1000)
|
46
|
+
|
47
|
+
connection.on_message_statistics.each do |stats|
|
48
|
+
puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# HornetQ Consumer:
|
3
|
+
# Consume all messages from the queue: TestQueue in the current thread
|
4
|
+
# Displays a '.' for every message received
|
5
|
+
# Used for performance measurements of consuming messages
|
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
|
+
timeout = (ARGV[0] || 1000).to_i
|
16
|
+
|
17
|
+
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
18
|
+
|
19
|
+
# Create a HornetQ session
|
20
|
+
HornetQ::Client::Connection.start_session(config) do |session|
|
21
|
+
|
22
|
+
# Create the non-durable TestQueue to receive messages sent to the TestAddress
|
23
|
+
session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)
|
24
|
+
|
25
|
+
# Consume All messages from the queue
|
26
|
+
stats = session.consume(:queue_name => 'TestQueue', :timeout=> 0, :statistics=>true) do |message|
|
27
|
+
print '.'
|
28
|
+
message.acknowledge
|
29
|
+
end
|
30
|
+
puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
|
31
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
---
|
2
2
|
development:
|
3
|
-
:
|
4
|
-
:uri: hornetq://localhost
|
3
|
+
:connection:
|
4
|
+
:uri: hornetq://localhost
|
5
5
|
:failover_on_initial_connection: true
|
6
6
|
:failover_on_server_shutdown: true
|
7
|
-
# 5 Connection attempts takes about 16 seconds before it switches to the backup server
|
8
7
|
:reconnect_attempts: 5
|
9
8
|
:session:
|
10
9
|
:username: guest
|
@@ -12,11 +11,14 @@ development:
|
|
12
11
|
|
13
12
|
# Example configuration showing all possible options and their default values if available
|
14
13
|
full_example:
|
15
|
-
:
|
14
|
+
:connection:
|
16
15
|
# The uri is written as follows for the NettyConnectorFactory.
|
17
|
-
# protocol=netty is the default and therefore not required
|
18
16
|
:uri: hornetq://localhost:5445,backuphost:5445/?protocol=netty
|
19
|
-
#
|
17
|
+
# protocol=netty is the default and therefore not required
|
18
|
+
:uri: hornetq://localhost:5445,backuphost:5445
|
19
|
+
# And since the default port is 5445
|
20
|
+
:uri: hornetq://localhost,backuphost
|
21
|
+
# Or, the uri is written as follows for InVM
|
20
22
|
:uri: hornetq://invm
|
21
23
|
# Or, the uri is written as follows for auto-discovery
|
22
24
|
:uri: hornetq://discoveryhost:5445/?protocol=discovery
|