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
@@ -0,0 +1,32 @@
|
|
1
|
+
# Allow examples to be run in-place without requiring a gem install
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'yaml'
|
8
|
+
require 'hornetq'
|
9
|
+
|
10
|
+
class LoggingTest < Test::Unit::TestCase
|
11
|
+
context 'Without Connection' do
|
12
|
+
def log_it
|
13
|
+
HornetQ::logger.error 'Hello'
|
14
|
+
HornetQ::logger.warn 'Hello'
|
15
|
+
HornetQ::logger.info 'Hello'
|
16
|
+
HornetQ::logger.debug 'Hello'
|
17
|
+
HornetQ::logger.trace 'Hello'
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'be able to use the default HornetQ logger' do
|
21
|
+
# Reset logger to HornetQ logger
|
22
|
+
HornetQ::logger = nil
|
23
|
+
log_it
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'be able to use the default HornetQ Ruby logger' do
|
27
|
+
HornetQ::logger = HornetQ::ruby_logger
|
28
|
+
log_it
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/test/server_test.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'hornetq'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
class MyThread < ::Thread
|
8
|
+
def initialize(name, &block)
|
9
|
+
super() do
|
10
|
+
begin
|
11
|
+
yield
|
12
|
+
rescue => e
|
13
|
+
HornetQ.logger.error("Thread #{name} died due to exception #{e.message}\n#{e.backtrace.join("\n")}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ServerTest < Test::Unit::TestCase
|
20
|
+
context 'standalone server without security' do
|
21
|
+
setup do
|
22
|
+
@server = nil
|
23
|
+
@tmp_data_dir = "/tmp/data_dir/#{$$}"
|
24
|
+
@uri = "hornetq://localhost:15445"
|
25
|
+
@server_thread = MyThread.new('standalone server') do
|
26
|
+
@server = HornetQ::Server.create_server(:uri => @uri, :data_directory => @tmp_data_dir, :security_enabled => false)
|
27
|
+
@server.start
|
28
|
+
end
|
29
|
+
# Give the server time to startup
|
30
|
+
sleep 5
|
31
|
+
end
|
32
|
+
|
33
|
+
teardown do
|
34
|
+
@server.stop if @server
|
35
|
+
@server_thread.join if @server_thread
|
36
|
+
FileUtils.rm_rf(@tmp_data_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
should 'pass simple messages' do
|
40
|
+
config = { :connection => { :uri => @uri } }
|
41
|
+
perform_simple_message_test(config, 'test_queue', 10)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'standalone server with security' do
|
46
|
+
setup do
|
47
|
+
@server = nil
|
48
|
+
@user = 'clarity'
|
49
|
+
@password = 'clarity'
|
50
|
+
@tmp_data_dir = "/tmp/data_dir/#{$$}"
|
51
|
+
@uri = "hornetq://localhost:15445"
|
52
|
+
@server_thread = MyThread.new('standalone server') do
|
53
|
+
@server = HornetQ::Server.create_server(:uri => @uri, :data_directory => @tmp_data_dir, :cluster_user => @user, :cluster_password => @password)
|
54
|
+
@server.start
|
55
|
+
end
|
56
|
+
# Give the server time to startup
|
57
|
+
sleep 5
|
58
|
+
end
|
59
|
+
|
60
|
+
teardown do
|
61
|
+
@server.stop if @server
|
62
|
+
@server_thread.join if @server_thread
|
63
|
+
FileUtils.rm_rf(@tmp_data_dir)
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'pass simple messages' do
|
67
|
+
config = {
|
68
|
+
:connection => { :uri => @uri },
|
69
|
+
:session => { :username => @user, :password => @password}
|
70
|
+
}
|
71
|
+
perform_simple_message_test(config, 'test_queue', 10)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# TODO: Figure out why producer gets severe error during failover
|
76
|
+
# context 'live and backup server' do
|
77
|
+
# setup do
|
78
|
+
# @count = 20
|
79
|
+
#
|
80
|
+
# @server = nil
|
81
|
+
# @tmp_data_dir = "/tmp/data_dir/#{$$}"
|
82
|
+
# @uri = "hornetq://localhost:15445,localhost:15446"
|
83
|
+
#
|
84
|
+
# @backup_server = nil
|
85
|
+
# @backup_tmp_data_dir = "/tmp/backup_data_dir/#{$$}"
|
86
|
+
# @backup_uri = "hornetq://localhost:15446"
|
87
|
+
#
|
88
|
+
# @backup_server_thread = MyThread.new('backup server') do
|
89
|
+
# begin
|
90
|
+
# @backup_server = HornetQ::Server.create_server(:uri => @backup_uri, :data_directory => @backup_tmp_data_dir, :backup => true, :security_enabled => false)
|
91
|
+
# @backup_server.start
|
92
|
+
# rescue Exception => e
|
93
|
+
# HornetQ.logger.error "Error in backup server thread: #{e.message}\n#{e.backtrace.join("\n")}"
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
# # Give the backup server time to startup
|
97
|
+
# sleep 10
|
98
|
+
#
|
99
|
+
# @server_thread = MyThread.new('live server') do
|
100
|
+
# begin
|
101
|
+
# @server = HornetQ::Server.create_server(:uri => @uri, :data_directory => @tmp_data_dir, :security_enabled => false)
|
102
|
+
# @server.start
|
103
|
+
# rescue Exception => e
|
104
|
+
# HornetQ.logger.error "Error in live server thread: #{e.message}\n#{e.backtrace.join("\n")}"
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# # Give the live server time to startup
|
109
|
+
# sleep 10
|
110
|
+
#
|
111
|
+
# @queue_name = 'test_queue'
|
112
|
+
# @config = {
|
113
|
+
# :connection => {
|
114
|
+
# :uri => @uri,
|
115
|
+
# :failover_on_initial_connection => true,
|
116
|
+
# :failover_on_server_shutdown => true,
|
117
|
+
# },
|
118
|
+
# :session => {}
|
119
|
+
# }
|
120
|
+
#
|
121
|
+
# @killer_thread = MyThread.new('killer') do
|
122
|
+
# sleep 5
|
123
|
+
# @server.stop
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# @producer_thread = MyThread.new('producer') do
|
127
|
+
# # Create a HornetQ session
|
128
|
+
# HornetQ::Client::Connection.session(@config) do |session|
|
129
|
+
# session.create_queue(@queue_name, @queue_name, true)
|
130
|
+
# producer = session.create_producer(@queue_name)
|
131
|
+
# (1..@count).each do |i|
|
132
|
+
# message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, true)
|
133
|
+
# # Set the message body text
|
134
|
+
# message.body = "Message ##{i}"
|
135
|
+
# # Send message to the queue
|
136
|
+
# begin
|
137
|
+
# HornetQ.logger.info "Producing message: #{message.body}"
|
138
|
+
# producer.send(message)
|
139
|
+
# sleep 1
|
140
|
+
# rescue Java::org.hornetq.api.core.HornetQException => e
|
141
|
+
# HornetQ.logger.error "Received producer exception: #{e.message} with code=#{e.cause.code}"
|
142
|
+
# if e.cause.getCode == Java::org.hornetq.api.core.HornetQException::UNBLOCKED
|
143
|
+
# HornetQ.logger.info "Retrying the send"
|
144
|
+
# retry
|
145
|
+
# end
|
146
|
+
# rescue Exception => e
|
147
|
+
# HornetQ.logger.error "Received producer exception: #{e.message}"
|
148
|
+
# end
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# teardown do
|
155
|
+
# @server.stop
|
156
|
+
# @backup_server.stop
|
157
|
+
# [ @server_thread, @backup_server_thread, @killer_thread, @producer_thread ].each do |thread|
|
158
|
+
# thread.join
|
159
|
+
# end
|
160
|
+
# FileUtils.rm_rf([@tmp_data_dir, @backup_tmp_data_dir])
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# should 'failover to backup server w/o message loss' do
|
164
|
+
# # Let the producer create the queue
|
165
|
+
# sleep 2
|
166
|
+
# HornetQ::Client::Connection.session(@config) do |session|
|
167
|
+
# consumer = session.create_consumer(@queue_name)
|
168
|
+
# session.start
|
169
|
+
#
|
170
|
+
# i = 0
|
171
|
+
# while message = consumer.receive(1000)
|
172
|
+
# i += 1
|
173
|
+
# message.acknowledge
|
174
|
+
# assert_equal "Message ##{i}", message.body
|
175
|
+
# HornetQ.logger.info "Consuming message #{message.body}"
|
176
|
+
# end
|
177
|
+
# assert_equal @count, i
|
178
|
+
# end
|
179
|
+
# end
|
180
|
+
# end
|
181
|
+
|
182
|
+
def perform_simple_message_test(config, queue_name, count)
|
183
|
+
HornetQ::Client::Connection.session(config) do |session|
|
184
|
+
session.create_queue(queue_name, queue_name, true)
|
185
|
+
producer = session.create_producer(queue_name)
|
186
|
+
(1..count).each do |i|
|
187
|
+
message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
|
188
|
+
message.durable = true
|
189
|
+
# Set the message body text
|
190
|
+
message.body = "Message ##{i}"
|
191
|
+
# Send message to the queue
|
192
|
+
producer.send(message)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
HornetQ::Client::Connection.session(config) do |session|
|
197
|
+
consumer = session.create_consumer(queue_name)
|
198
|
+
session.start
|
199
|
+
|
200
|
+
i = 0
|
201
|
+
while message = consumer.receive(1000)
|
202
|
+
i += 1
|
203
|
+
message.acknowledge
|
204
|
+
assert_equal "Message ##{i}", message.body
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
metadata
CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- 3
|
8
|
+
- 0
|
9
9
|
- alpha
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0.alpha
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Reid Morrison
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-02-
|
19
|
+
date: 2011-02-18 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -37,8 +37,8 @@ description: JRuby-HornetQ is a Java and Ruby library that exposes the HornetQ J
|
|
37
37
|
email:
|
38
38
|
- rubywmq@gmail.com
|
39
39
|
- bpardee@gmail.com
|
40
|
-
executables:
|
41
|
-
|
40
|
+
executables:
|
41
|
+
- hornetq_server
|
42
42
|
extensions: []
|
43
43
|
|
44
44
|
extra_rdoc_files: []
|
@@ -49,50 +49,47 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- README.md
|
51
51
|
- bin/hornetq_server
|
52
|
-
- examples/
|
53
|
-
- examples/advanced/
|
54
|
-
- examples/advanced/
|
55
|
-
- examples/advanced/
|
56
|
-
- examples/
|
57
|
-
- examples/
|
58
|
-
- examples/
|
59
|
-
- examples/
|
60
|
-
- examples/
|
61
|
-
- examples/
|
62
|
-
- examples/
|
63
|
-
- examples/client/
|
64
|
-
- examples/client/
|
65
|
-
- examples/
|
66
|
-
- examples/
|
67
|
-
- examples/
|
68
|
-
- examples/
|
69
|
-
- examples/
|
70
|
-
- examples/
|
71
|
-
- examples/
|
72
|
-
- examples/
|
73
|
-
- examples/
|
74
|
-
- examples/
|
75
|
-
- examples/
|
76
|
-
- examples/
|
77
|
-
- examples/
|
78
|
-
- examples/
|
79
|
-
- examples/
|
80
|
-
- examples/
|
81
|
-
- examples/
|
82
|
-
- examples/
|
83
|
-
- examples/
|
84
|
-
- examples/
|
85
|
-
- examples/
|
86
|
-
- examples/
|
87
|
-
- examples/
|
52
|
+
- examples/README
|
53
|
+
- examples/advanced/batch_client.rb
|
54
|
+
- examples/advanced/bytes_producer.rb
|
55
|
+
- examples/advanced/client.rb
|
56
|
+
- examples/advanced/client_session_pooling.rb
|
57
|
+
- examples/advanced/consume_on_message.rb
|
58
|
+
- examples/advanced/consumer.rb
|
59
|
+
- examples/advanced/hornetq.yml
|
60
|
+
- examples/advanced/multi_client.rb
|
61
|
+
- examples/advanced/producer.rb
|
62
|
+
- examples/advanced/server.rb
|
63
|
+
- examples/client-server/client.rb
|
64
|
+
- examples/client-server/server.rb
|
65
|
+
- examples/producer-consumer/consume_all.rb
|
66
|
+
- examples/producer-consumer/consume_on_message.rb
|
67
|
+
- examples/producer-consumer/consumer.rb
|
68
|
+
- examples/producer-consumer/producer.rb
|
69
|
+
- examples/resque/hornetq_job.rb
|
70
|
+
- examples/resque/processor.rb
|
71
|
+
- examples/resque/readme.md
|
72
|
+
- examples/resque/resque_conf.rb
|
73
|
+
- examples/resque/resque_worker.rb
|
74
|
+
- examples/resque/sleep_job.rb
|
75
|
+
- examples/server-config/backup_server.yml
|
76
|
+
- examples/server-config/live_server.yml
|
77
|
+
- examples/server-config/standalone_server.yml
|
78
|
+
- examples/simple/invm.rb
|
79
|
+
- examples/transaction-failover/consumer.rb
|
80
|
+
- examples/transaction-failover/hornetq.yml
|
81
|
+
- examples/transaction-failover/producer.rb
|
82
|
+
- examples/transaction-failover/README
|
83
|
+
- examples/worker/hornetq.yml
|
84
|
+
- examples/worker/producer.rb
|
85
|
+
- examples/worker/README
|
86
|
+
- examples/worker/test_object.rb
|
87
|
+
- examples/worker/worker.rb
|
88
88
|
- lib/hornetq.rb
|
89
|
-
- lib/data/bindings/hornetq-bindings-1.bindings
|
90
|
-
- lib/data/bindings/hornetq-bindings-2.bindings
|
91
89
|
- lib/hornetq/client.rb
|
92
|
-
- lib/hornetq/org_hornetq_core_server_hornet_q_server.rb
|
93
90
|
- lib/hornetq/server.rb
|
94
91
|
- lib/hornetq/uri.rb
|
95
|
-
- lib/hornetq/client/
|
92
|
+
- lib/hornetq/client/connection.rb
|
96
93
|
- lib/hornetq/client/message_handler.rb
|
97
94
|
- lib/hornetq/client/org_hornetq_api_core_client_client_session.rb
|
98
95
|
- lib/hornetq/client/org_hornetq_core_client_impl_client_consumer_impl.rb
|
@@ -108,8 +105,10 @@ files:
|
|
108
105
|
- lib/hornetq/java/hornetq-core-client.jar
|
109
106
|
- lib/hornetq/java/hornetq-core.jar
|
110
107
|
- lib/hornetq/java/netty.jar
|
111
|
-
- lib/hornetq/server/
|
112
|
-
- test/
|
108
|
+
- lib/hornetq/server/org_hornetq_core_server_hornet_q_server.rb
|
109
|
+
- test/client_connection_test.rb
|
110
|
+
- test/logging_test.rb
|
111
|
+
- test/server_test.rb
|
113
112
|
- test/uri_test.rb
|
114
113
|
has_rdoc: true
|
115
114
|
homepage: https://github.com/ClarityServices/jruby-hornetq
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,47 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# HornetQ Requestor:
|
3
|
-
# Submit a request and wait for a reply
|
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
|
-
count = (ARGV[0] || 1).to_i
|
14
|
-
timeout = (ARGV[1] || 30000).to_i
|
15
|
-
|
16
|
-
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
17
|
-
|
18
|
-
# Create a HornetQ session
|
19
|
-
HornetQ::Client::Factory.session(config) do |session|
|
20
|
-
#session.create_queue('Example', 'Example', true)
|
21
|
-
requestor = session.create_requestor('jms.queue.ExampleQueue')
|
22
|
-
session.start
|
23
|
-
start_time = Time.now
|
24
|
-
|
25
|
-
puts "Sending messages"
|
26
|
-
(1..count).each do |i|
|
27
|
-
message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
|
28
|
-
# Set the message body text
|
29
|
-
message.body = "Request Current Time"
|
30
|
-
# Set the user managed message id
|
31
|
-
message.user_id = Java::org.hornetq.utils::UUIDGenerator.getInstance.generateUUID
|
32
|
-
# Send request message and wait for reply
|
33
|
-
if reply = requestor.request(message, timeout)
|
34
|
-
puts "Received Response: #{reply.inspect}" if count < 10
|
35
|
-
puts " Message:[#{reply.body.inspect}]" if count < 10
|
36
|
-
print "." if count >= 10
|
37
|
-
else
|
38
|
-
puts "Time out, No reply received after #{timeout/1000} seconds"
|
39
|
-
end
|
40
|
-
puts "#{i}" if i%1000 == 0
|
41
|
-
puts "Durable" if message.durable
|
42
|
-
end
|
43
|
-
|
44
|
-
requestor.close
|
45
|
-
duration = Time.now - start_time
|
46
|
-
puts "\nMade #{count} calls in #{duration} seconds at #{count/duration} messages per second"
|
47
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# HornetQ Consumer:
|
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 'yaml'
|
11
|
-
require 'hornetq'
|
12
|
-
|
13
|
-
timeout = (ARGV[0] || 1000).to_i
|
14
|
-
|
15
|
-
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
16
|
-
|
17
|
-
# Create a HornetQ session
|
18
|
-
HornetQ::Client::Factory.session(config) do |session|
|
19
|
-
consumer = session.create_consumer('jms.queue.ExampleQueue')
|
20
|
-
session.start
|
21
|
-
|
22
|
-
count = 0
|
23
|
-
start_time = Time.now
|
24
|
-
while message = consumer.receive(timeout)
|
25
|
-
count = count + 1
|
26
|
-
message.acknowledge
|
27
|
-
puts "=================================="
|
28
|
-
text = message.body
|
29
|
-
p text
|
30
|
-
p message
|
31
|
-
puts "Durable" if message.durable
|
32
|
-
end
|
33
|
-
duration = Time.now - start_time - timeout/1000
|
34
|
-
puts "Received #{count} messages in #{duration} seconds at #{count/duration} messages per second"
|
35
|
-
end
|