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
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'shoulda'
5
+ end
6
+
7
+ group :develop do
8
+ gem 'awesome_print'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ atomic (1.1.10-java)
11
+ awesome_print (1.1.0)
12
+ i18n (0.6.4)
13
+ minitest (4.7.5)
14
+ multi_json (1.7.7)
15
+ shoulda (3.5.0)
16
+ shoulda-context (~> 1.0, >= 1.0.1)
17
+ shoulda-matchers (>= 1.4.1, < 3.0)
18
+ shoulda-context (1.1.4)
19
+ shoulda-matchers (2.2.0)
20
+ activesupport (>= 3.0.0)
21
+ thread_safe (0.1.0)
22
+ atomic
23
+ tzinfo (0.3.37)
24
+
25
+ PLATFORMS
26
+ java
27
+
28
+ DEPENDENCIES
29
+ awesome_print
30
+ shoulda
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.5.0.alpha (2012-07-19)
2
+
3
+ * Upgrade to HornetQ 2.3
4
+ * HornetQ removed its own built-in logging classes, so corresponding
5
+ logging classes removed from jruby-hornetq
6
+
1
7
  ## 0.4.0 (2011-04-01)
2
8
 
3
9
  * Upgrade to HornetQ 2.2.2
data/README.md CHANGED
@@ -3,11 +3,9 @@ jruby-hornetq
3
3
 
4
4
  * http://github.com/ClarityServices/jruby-hornetq
5
5
 
6
- Feedback is welcome and appreciated :)
7
-
8
6
  ### Introduction
9
7
 
10
- jruby-hornetq create a Ruby friendly API into the HornetQ Java libraries without
8
+ jruby-hornetq create a Ruby friendly API into the HornetQ Java libraries without
11
9
  compromising performance. It does this by sprinkling "Ruby-goodness" into the
12
10
  existing HornetQ Java classes and interfaces, I.e. By adding Ruby methods to
13
11
  the existing classes and interfaces. Since jruby-hornetq exposes the HornetQ
@@ -37,7 +35,7 @@ HornetQ
37
35
 
38
36
  For information on the HornetQ messaging and queuing system, see: http://www.jboss.org/hornetq
39
37
 
40
- For more documentation on any of the classes, see: http://docs.jboss.org/hornetq/2.2.2.Final/api/index.html
38
+ For more documentation on any of the classes, see: http://docs.jboss.org/hornetq/2.3.0.Final/docs/api/hornetq-client/
41
39
 
42
40
  Concepts & Terminology
43
41
  ----------------------
@@ -51,7 +49,7 @@ messages. The consumer does not have to be running in order to receive messages.
51
49
  ### Address
52
50
 
53
51
  In traditional messaging and queuing systems there is only a queue when both
54
- read and writing messages. With the advent of AMQP and in HornetQ we now have
52
+ read and writing messages. With the advent of AMQP and in HornetQ we now have
55
53
  the concept of an Address which is different from a Queue.
56
54
 
57
55
  An Address can be thought of the address we would put on an envelope before
@@ -69,7 +67,7 @@ overhead of a disk write every time it is read or written (produced or consumed)
69
67
  ### Broker
70
68
 
71
69
  HornetQ is a broker based architecture which requires the use of one or more
72
- centralized brokers. A broker is much like the "server" through which all
70
+ centralized brokers. A broker is much like the "server" through which all
73
71
  messages pass through.
74
72
 
75
73
  An in-vm broker can be used for passing messages around within a Java
@@ -98,7 +96,7 @@ jruby-hornetq is primarily intended to make it easy to use the HornetQ client
98
96
  core API. It also supports running the HornetQ broker for scenarios such as
99
97
  in-vm messaging.
100
98
 
101
- The examples below address some of the messaging patterns that are used in
99
+ The examples below address some of the messaging patterns that are used in
102
100
  messaging and queuing.
103
101
 
104
102
  Producer-Consumer
@@ -106,29 +104,29 @@ Producer-Consumer
106
104
 
107
105
  Producer: Write messages to a queue:
108
106
 
107
+
109
108
  require 'rubygems'
110
109
  require 'hornetq'
111
-
112
- HornetQ::Client::Factory.create_session(:connection => {:uri => 'hornetq://localhost'}) do |session|
113
- # Create Producer so that we can send messages to the Address 'jms.queue.ExampleQueue'
114
- producer = session.create_producer('jms.queue.ExampleQueue')
115
-
116
- # Create a non-durable message to send
117
- message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
118
- message << "#{Time.now}: ### Hello, World ###"
119
-
120
- producer.send(message)
121
- end
122
110
 
111
+ connection = HornetQ::Client::Connection.new(:uri => 'hornetq://localhost/')
112
+ session = connection.create_session(:username=>'guest',:password=>'secret')
113
+
114
+ producer = session.create_producer('jms.queue.CMDBDataServicesQueue')
115
+ message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
116
+ message.body_buffer.write_string('Hello World')
117
+ producer.send(message)
118
+ session.close
119
+ connection.close
123
120
 
124
- Consumer: Read message from a queue:
121
+
122
+ Consumer: Read message from a queue:
125
123
 
126
124
  require 'rubygems'
127
125
  require 'hornetq'
128
-
126
+
129
127
  HornetQ::Client::Factory.start(:connection => {:uri => 'hornetq://localhost'}) do |session|
130
128
  consumer = session.create_consumer('jms.queue.ExampleQueue')
131
-
129
+
132
130
  # Receive a single message, return immediately if no message available
133
131
  if message = consumer.receive_immediate
134
132
  puts "Received:[#{message.body}]"
@@ -145,25 +143,25 @@ Server: Receive requests and send back a reply
145
143
 
146
144
  require 'rubygems'
147
145
  require 'hornetq'
148
-
146
+
149
147
  # Shutdown Server after 5 minutes of inactivity, set to 0 to wait forever
150
148
  timeout = 300000
151
-
149
+
152
150
  HornetQ::Client::Factory.start(:connection => {:uri => 'hornetq://localhost'}) do |session|
153
151
  server = session.create_server('jms.queue.ExampleQueue', timeout)
154
-
155
- puts "Waiting for Requests..."
152
+
153
+ puts "Waiting for Requests..."
156
154
  server.run do |request_message|
157
155
  puts "Received:[#{request_message.body}]"
158
-
156
+
159
157
  # Create Reply Message
160
158
  reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
161
159
  reply_message.body = "Echo [#{request_message.body}]"
162
-
160
+
163
161
  # The result of the block is the message to be sent back to the client
164
162
  reply_message
165
163
  end
166
-
164
+
167
165
  # Server will stop after timeout period after no messages received
168
166
  server.close
169
167
  end
@@ -173,17 +171,17 @@ Client: Send a request and wait for a reply
173
171
 
174
172
  require 'rubygems'
175
173
  require 'hornetq'
176
-
174
+
177
175
  # Wait 5 seconds for a reply
178
176
  timeout = 5000
179
-
177
+
180
178
  HornetQ::Client::Factory.start(:connection => {:uri => 'hornetq://localhost'}) do |session|
181
179
  requestor = session.create_requestor('jms.queue.ExampleQueue')
182
-
180
+
183
181
  # Create non-durable message
184
182
  message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
185
183
  message.body = "Request Current Time"
186
-
184
+
187
185
  # Send message to the queue
188
186
  puts "Send request message and wait for Reply"
189
187
  if reply = requestor.request(message, timeout)
@@ -192,7 +190,7 @@ Client: Send a request and wait for a reply
192
190
  else
193
191
  puts "Time out, No reply received after #{timeout/1000} seconds"
194
192
  end
195
-
193
+
196
194
  requestor.close
197
195
  end
198
196
 
@@ -228,7 +226,7 @@ The libraries required for the HornetQ Client and to start a simple Core API
228
226
  only Broker are included with the Gem.
229
227
 
230
228
  ### GenePool
231
-
229
+
232
230
  GenePool is used to implement session pooling
233
231
 
234
232
  Running the Broker
@@ -314,4 +312,4 @@ See the License for the specific language governing permissions and
314
312
  limitations under the License.
315
313
 
316
314
  jruby-hornetq includes files from HornetQ, which is also licensed under
317
- the Apache License, Version 2.0: http://www.jboss.org/hornetq
315
+ the Apache License, Version 2.0: http://www.jboss.org/hornetq
data/Rakefile CHANGED
@@ -1,23 +1,28 @@
1
1
  raise "jruby-hornetq must be built with JRuby: try again with `jruby -S rake'" unless defined?(JRUBY_VERSION)
2
2
 
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
3
6
  require 'rake/clean'
4
7
  require 'rake/testtask'
5
8
  require 'date'
6
9
  require 'java'
10
+ require 'hornetq/version'
7
11
 
8
12
  desc "Build gem"
9
13
  task :gem do |t|
10
14
  gemspec = Gem::Specification.new do |s|
11
- s.name = 'jruby-hornetq'
12
- s.version = '0.4.0'
13
- s.authors = ['Reid Morrison', 'Brad Pardee']
14
- s.email = ['rubywmq@gmail.com', 'bpardee@gmail.com']
15
- s.homepage = 'https://github.com/ClarityServices/jruby-hornetq'
16
- s.date = Date.today.to_s
15
+ s.name = 'jruby-hornetq'
16
+ s.version = HornetQ::VERSION
17
+ s.authors = ['Reid Morrison', 'Brad Pardee']
18
+ s.email = ['reidmo@gmail.com', 'bpardee@gmail.com']
19
+ s.homepage = 'https://github.com/ClarityServices/jruby-hornetq'
20
+ s.date = Date.today.to_s
17
21
  s.description = 'JRuby-HornetQ is a Java and Ruby library that exposes the HornetQ Java API in a ruby friendly way. For JRuby only.'
18
- s.summary = 'JRuby interface into HornetQ'
19
- s.files = FileList["./**/*"].exclude('*.gem', './nbproject/*').map{|f| f.sub(/^\.\//, '')}
20
- s.has_rdoc = true
22
+ s.summary = 'JRuby interface into HornetQ'
23
+ s.files = FileList["./**/*"].exclude(/.gem$/, /.log$/,/^nbproject/).map{|f| f.sub(/^\.\//, '')}
24
+ s.license = "Apache License V2.0"
25
+ s.has_rdoc = true
21
26
  s.executables = %w(hornetq_server)
22
27
  s.add_dependency "gene_pool", "~> 1.1.1"
23
28
  end
@@ -10,7 +10,7 @@
10
10
  # This sample sends a total of 100 requests in batches of 10.
11
11
  # One thread sends requests and the other processes replies.
12
12
  # Once 80% of the replies are back, it will send the next batch
13
- #
13
+ #
14
14
  # Before running this sample, start server.rb first
15
15
  #
16
16
 
@@ -37,23 +37,23 @@ HornetQ::Client::Connection.connection(config[:connection]) do |connection|
37
37
  # number of outstanding requests to have open at any time
38
38
  # Default: 0.8
39
39
  # (:max_outstanding_responses)
40
-
40
+
41
41
  pattern_config = {
42
42
  :connection => connection,
43
43
  :server_address => server_address,
44
44
  :completion_ratio => 0.8
45
45
  }
46
-
46
+
47
47
  requestor = BatchRequestorPattern.new(connection, server_address) do |message|
48
48
  # Display an @ symbol for every reply received
49
49
  print '@'
50
50
  end
51
-
51
+
52
52
  times = (batch_size/window_size).to_i
53
53
  puts "Performing #{times} loops"
54
-
54
+
55
55
  times.times do |i|
56
-
56
+
57
57
  window_size.times do |i|
58
58
  message = @session.create_message(true)
59
59
  message.type = :text
@@ -61,10 +61,10 @@ HornetQ::Client::Connection.connection(config[:connection]) do |connection|
61
61
  requestor.send(message)
62
62
  print "."
63
63
  end
64
-
64
+
65
65
  # Wait for at least 80% of responses before sending more requests
66
66
  requestor.wait_for_outstanding_replies
67
-
67
+
68
68
  end
69
69
  puts "Done sending requests, waiting for remaining replies"
70
70
  requestor.wait_for_all_outstanding_replies
@@ -16,13 +16,13 @@
16
16
  require 'sync'
17
17
 
18
18
  class BatchRequestorPattern
19
-
19
+
20
20
  attr_accessor :batch_size, :window_size, :completion_ratio
21
21
  attr_reader :reply_address, :reply_count, :send_count
22
-
23
- #
22
+
23
+ #
24
24
  # Returns a new BatchRequestorPattern
25
- #
25
+ #
26
26
  # Parameters:
27
27
  # * connection: The HornetQ connection. Used for creating sessions for the
28
28
  # pattern to run
@@ -31,18 +31,18 @@ class BatchRequestorPattern
31
31
  # It can be used to perform specialized handling such as:
32
32
  # ** Aborting a batch process
33
33
  # ** Moving the response to another queue for re-queuing later
34
- #
34
+ #
35
35
  # Implementation:
36
- #
36
+ #
37
37
  # Creates a temporary reply to queue for receiving responses from the server
38
38
  # Consists of the server_address following by a '.' and a UUID
39
- #
39
+ #
40
40
  # Uses Connection#on_message to process replies in a separate thread
41
- #
41
+ #
42
42
  # If the connection is started, it will start consuming replies immediately,
43
43
  # otherwise it will only start processing replies once the connection has
44
44
  # been started.
45
- #
45
+ #
46
46
  # Sending of messages should be done by only one thread at a time since
47
47
  # this pattern shares the same session and producer for sending messages
48
48
  #
@@ -59,9 +59,9 @@ class BatchRequestorPattern
59
59
  connection = params.delete(:connection)
60
60
  server_address = params.delete(:server_address)
61
61
  @completion_ratio = params.delete(:completion_ratio).to_f
62
-
62
+
63
63
  raise "Invalid :completion_ratio of #{@completion_ratio}. Must be between 0 and 1 inclusive" unless @completion_ratio.between?(0,1)
64
-
64
+
65
65
  @session = connection.create_session
66
66
  @producer = @session.create_producer(server_address)
67
67
  @reply_address = "#{server_address}.#{Java::java.util::UUID.randomUUID.toString}"
@@ -70,19 +70,19 @@ class BatchRequestorPattern
70
70
  @reply_count = 0
71
71
  @send_count = 0
72
72
  @reply_block = reply_block
73
-
73
+
74
74
  # Start consuming replies. The Address and Queue names are the same
75
75
  connection.on_message(:queue_name => @reply_address) {|message| process_reply(message) }
76
76
  end
77
-
77
+
78
78
  # Return the current message count
79
79
  def reply_count
80
80
  @reply_count_sync.synchronize(:SH) { @reply_count }
81
81
  end
82
-
82
+
83
83
  # Send a message to the server, setting the reply to address to the temporary
84
84
  # address created by this pattern
85
- #
85
+ #
86
86
  # Sending of messages should be done by only one thread at a time since
87
87
  # this pattern shares the same session and producer for sending messages
88
88
  #
@@ -92,17 +92,17 @@ class BatchRequestorPattern
92
92
  @producer.send(message)
93
93
  @send_count += 1
94
94
  end
95
-
96
- # Retry Sending a message to the server, setting the reply to address to the
95
+
96
+ # Retry Sending a message to the server, setting the reply to address to the
97
97
  # temporary address created by this pattern
98
- #
98
+ #
99
99
  # Only call this method when a reply is received and we want to resend a
100
100
  # previous request
101
- #
102
- # Note: This method will decrement the number of messages received by 1
103
- # and will Not increment the number of messages sent, since it is
101
+ #
102
+ # Note: This method will decrement the number of messages received by 1
103
+ # and will Not increment the number of messages sent, since it is
104
104
  # considered to have already been sent
105
- #
105
+ #
106
106
  # ReSending and Sending of messages should be done by only one thread at a time since
107
107
  # this pattern shares the same session and producer for sending messages
108
108
  # #TODO Should we rather just add a Sync around the producer?
@@ -111,53 +111,53 @@ class BatchRequestorPattern
111
111
  # Returns the total number of messages sent so far in this batch
112
112
  def resend(message)
113
113
  message.reply_to_address = @reply_address
114
-
114
+
115
115
  # Decrement Reply Message counter
116
- @reply_count_sync.synchronize(:EX) { @reply_count -= 1 }
116
+ @reply_count_sync.synchronize(:EX) { @reply_count -= 1 }
117
117
  @producer.send(message)
118
118
  end
119
-
119
+
120
120
  # Receive Reply messages, calling the supplied reply handler block to support
121
121
  # custom error handling
122
- #
122
+ #
123
123
  # Returns result of reply block supplied to constructor
124
124
  def process_reply(message)
125
125
  # Increment reply message counter
126
126
  @reply_count_sync.synchronize(:EX) { @reply_count += 1 }
127
-
127
+
128
128
  result = @reply_block.call(message) if @reply_block
129
129
  message.acknowledge
130
130
  result
131
131
  end
132
-
132
+
133
133
  # Release resources used by this pattern
134
134
  def close
135
135
  @producer.close
136
136
  @session.close
137
137
  end
138
-
138
+
139
139
  # Wait for replies from server until the required number of responses has been
140
140
  # received based on the completion ratio
141
- #
141
+ #
142
142
  # For example a completion ration of 0.8 will wait for at least 80% of replies
143
143
  # to be received. So if 10 requests were sent this method would only return
144
144
  # once 8 or more replies have been received
145
- #
145
+ #
146
146
  # #TODO Need a Timeout here
147
147
  def wait_for_outstanding_replies
148
148
  while self.reply_count >= self.completion_ratio * self.send_count
149
149
  sleep 0.1
150
150
  end
151
151
  end
152
-
152
+
153
153
  # Wait for replies from server until the required number of responses has been
154
154
  # received based on the completion ratio
155
- #
155
+ #
156
156
  # #TODO Need a Timeout here
157
157
  def wait_for_all_outstanding_replies
158
158
  while self.reply_count >= self.send_count
159
159
  sleep 0.1
160
160
  end
161
161
  end
162
-
162
+
163
163
  end