jruby-hornetq 0.2.5.alpha → 0.3.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -12,10 +12,10 @@ module HornetQ::Client
|
|
12
12
|
# or when Consumer::on_message_statistics is called. In this case on_message_statistics::statistics
|
13
13
|
# can be called several times during processing without affecting the end time.
|
14
14
|
# The start time and message count is never reset for this instance
|
15
|
-
def initialize(
|
15
|
+
def initialize(params={}, &proc)
|
16
16
|
@proc = proc
|
17
17
|
|
18
|
-
if
|
18
|
+
if params[:statistics]
|
19
19
|
@message_count = 0
|
20
20
|
@start_time = Time.now
|
21
21
|
end
|
@@ -54,7 +54,7 @@ module HornetQ::Client
|
|
54
54
|
raise "First call Consumer::on_message with :statistics=>true before calling MessageConsumer::statistics()" unless @message_count
|
55
55
|
duration =(@last_time || Time.now) - @start_time
|
56
56
|
{
|
57
|
-
:
|
57
|
+
:count => @message_count,
|
58
58
|
:duration => duration,
|
59
59
|
:messages_per_second => (@message_count/duration).to_i
|
60
60
|
}
|
@@ -1,11 +1,94 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# For each thread that will be processing messages concurrently a separate
|
2
|
+
# session is required.
|
3
|
+
#
|
4
|
+
# Interface org.hornetq.api.core.client.ClientSession
|
5
|
+
#
|
6
|
+
# See: http://hornetq.sourceforge.net/docs/hornetq-2.1.0.Final/api/index.html?org/hornetq/api/core/client/ClientSession.html
|
7
|
+
#
|
8
|
+
# Other methods still directly accessible through this class:
|
9
|
+
#
|
10
|
+
# add_failure_listener(SessionFailureListener listener)
|
11
|
+
# Adds a FailureListener to the session which is notified if a failure occurs on the session
|
12
|
+
#
|
13
|
+
# binding_query(SimpleString address)
|
14
|
+
# Queries information on a binding
|
15
|
+
#
|
16
|
+
# close()
|
17
|
+
# Closes this session
|
18
|
+
#
|
19
|
+
# commit()
|
20
|
+
# Commits the current transaction
|
21
|
+
#
|
22
|
+
# ClientMessage create_message(boolean durable)
|
23
|
+
# Creates a ClientMessage.
|
24
|
+
# ClientMessage create_message(byte type, boolean durable)
|
25
|
+
# Creates a ClientMessage.
|
26
|
+
# ClientMessage create_message(byte type, boolean durable, long expiration, long timestamp, byte priority)
|
27
|
+
# Creates a ClientMessage.
|
28
|
+
#
|
29
|
+
# ClientProducer create_producer()
|
30
|
+
# Creates a producer with no default address.
|
31
|
+
# ClientProducer create_producer(SimpleString address)
|
32
|
+
# Creates a producer which sends messages to the given address
|
33
|
+
# ClientProducer create_producer(SimpleString address, int rate)
|
34
|
+
# Creates a producer which sends messages to the given address
|
35
|
+
# ClientProducer create_producer(String address)
|
36
|
+
# Creates a producer which sends messages to the given address
|
37
|
+
#
|
38
|
+
# void create_queue(String address, String queueName)
|
39
|
+
# Creates a non-temporary queue non-durable queue.
|
40
|
+
# void create_queue(String address, String queueName, boolean durable)
|
41
|
+
# Creates a non-temporary queue.
|
42
|
+
# void create_queue(String address, String queueName, String filter, boolean durable)
|
43
|
+
# Creates a non-temporaryqueue.
|
44
|
+
#
|
45
|
+
# void create_temporary_queue(String address, String queueName)
|
46
|
+
# Creates a temporary queue.
|
47
|
+
# void create_temporary_queue(String address, String queueName, String filter)
|
48
|
+
# Creates a temporary queue with a filter.
|
49
|
+
#
|
50
|
+
# void delete_queue(String queueName)
|
51
|
+
# Deletes the queue.
|
52
|
+
# int version()
|
53
|
+
# Returns the server's incrementingVersion.
|
54
|
+
#
|
55
|
+
# XAResource xa_resource()
|
56
|
+
# Returns the XAResource associated to the session.
|
57
|
+
#
|
58
|
+
# auto_commit_acks?
|
59
|
+
# Returns whether the session will automatically commit its transaction every time a message is acknowledged by a ClientConsumer created by this session, false else
|
60
|
+
# auto_commit_sends?
|
61
|
+
# Returns whether the session will automatically commit its transaction every time a message is sent by a ClientProducer created by this session, false else
|
62
|
+
# block_on_acknowledge?
|
63
|
+
# Returns whether the ClientConsumer created by the session will block when they acknowledge a message
|
64
|
+
# closed?
|
65
|
+
# Returns whether the session is closed or not.
|
66
|
+
# rollback_only?
|
67
|
+
# Returns true if the current transaction has been flagged to rollback, false else
|
68
|
+
# xa?
|
69
|
+
# Return true if the session supports XA, false else
|
70
|
+
#
|
71
|
+
# ClientSession.QueueQuery queue_query(SimpleString queueName)
|
72
|
+
# Queries information on a queue
|
73
|
+
#
|
74
|
+
# boolean removeFailureListener(SessionFailureListener listener)
|
75
|
+
# Removes a FailureListener to the session
|
76
|
+
#
|
77
|
+
# void rollback()
|
78
|
+
# Rolls back the current transaction
|
79
|
+
# void rollback(boolean considerLastMessageAsDelivered)
|
80
|
+
# Rolls back the current transaction
|
81
|
+
#
|
82
|
+
# void set_send_acknowledgement_handler(SendAcknowledgementHandler handler)
|
83
|
+
# Sets a SendAcknowledgementHandler for this session
|
84
|
+
#
|
85
|
+
# void start()
|
86
|
+
# Starts the session
|
87
|
+
# void stop()
|
88
|
+
# Stops the session
|
89
|
+
|
4
90
|
module Java::org.hornetq.api.core.client::ClientSession
|
5
91
|
|
6
|
-
# Document Methods from Java Docs:
|
7
|
-
# create_queue(address, queue_name, durable?)
|
8
|
-
|
9
92
|
# Creates a ClientConsumer to consume or browse messages matching the filter
|
10
93
|
# from the queue with the given name, calls the supplied block, then close the
|
11
94
|
# consumer
|
@@ -34,12 +117,13 @@ module Java::org.hornetq.api.core.client::ClientSession
|
|
34
117
|
#
|
35
118
|
# Example
|
36
119
|
# # Just browse the messages without consuming them
|
37
|
-
# session.consumer(:queue_name => 'my_queue', :browse_only => true) do |consumer|
|
120
|
+
# session.consumer(:queue_name => ##'my_queue', :browse_only => true) do |consumer|
|
38
121
|
# msg = consumer.receive_immediate
|
39
122
|
# p msg
|
40
123
|
# msg.acknowledge
|
41
124
|
# end
|
42
125
|
def consumer(params={}, &block)
|
126
|
+
raise "Missing mandatory code block" unless block
|
43
127
|
consumer = nil
|
44
128
|
begin
|
45
129
|
consumer = create_consumer_from_params(params)
|
@@ -49,23 +133,101 @@ module Java::org.hornetq.api.core.client::ClientSession
|
|
49
133
|
end
|
50
134
|
end
|
51
135
|
|
52
|
-
#
|
136
|
+
# Consume or browse all messages matching the filter from the queue with the
|
137
|
+
# given name, calls the supplied block for every message received from the
|
138
|
+
# queue. Once the timeout has been reached it closes the consumer
|
139
|
+
#
|
140
|
+
# Parameters:
|
141
|
+
# :timeout How to timeout waiting for messages
|
142
|
+
# -1 : Wait forever
|
143
|
+
# 0 : Return immediately if no message is available (default)
|
144
|
+
# x : Wait for x milli-seconds for a message to be received from the server
|
145
|
+
# Note: Messages may still be on the queue, but the server has not supplied any messages
|
146
|
+
# in the time interval specified
|
147
|
+
# Default: 0
|
148
|
+
# :queue_name => The name of the queue to consume messages from. Mandatory
|
149
|
+
# :filter => Only consume messages matching the filter: Default: nil
|
150
|
+
# :browse_only => Whether to just browse the queue or consume messages
|
151
|
+
# true | false. Default: false
|
152
|
+
# :window_size => The consumer window size.
|
153
|
+
# :max_rate => The maximum rate to consume messages.
|
154
|
+
#
|
155
|
+
# :statistics Capture statistics on how many messages have been read
|
156
|
+
# true : This method will capture statistics on the number of messages received
|
157
|
+
# and the time it took to process them.
|
158
|
+
# Statistics are cumulative between calls to ::each and will only be
|
159
|
+
# reset when ::each is called again with :statistics => true
|
160
|
+
#
|
161
|
+
# Note: If either :window_size or :max_rate is supplied, then BOTH are required
|
162
|
+
#
|
163
|
+
# Returns the statistics gathered when :statistics => true, otherwise nil
|
164
|
+
#
|
165
|
+
# Example
|
166
|
+
# session.consume(:queue_name => 'my_queue', :timeout => 1000) do |message|
|
167
|
+
# p message
|
168
|
+
# message.acknowledge
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# Example
|
172
|
+
# # Just browse the messages without consuming them
|
173
|
+
# session.consume(:queue_name => 'my_queue', :timeout => 1000, :browse_only => true) do |message|
|
174
|
+
# p message
|
175
|
+
# message.acknowledge
|
176
|
+
# end
|
177
|
+
def consume(params, &block)
|
178
|
+
raise "Missing mandatory code block" unless block
|
179
|
+
c = self.create_consumer_from_params(params)
|
180
|
+
begin
|
181
|
+
c.each(params, &block)
|
182
|
+
ensure
|
183
|
+
c.close
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Create a consumer using named parameters. The following Java create_consumer
|
188
|
+
# methods are still directly accessible:
|
189
|
+
# create_consumer(String queueName)
|
190
|
+
# Creates a ClientConsumer to consume messages from the queue with the given name
|
191
|
+
# create_consumer(String queueName, boolean browseOnly)
|
192
|
+
# Creates a ClientConsumer to consume or browse messages from the queue with the given name.
|
193
|
+
# create_consumer(String queueName, String filter)
|
194
|
+
# Creates a ClientConsumer to consume messages matching the filter from the queue with the given name.
|
195
|
+
# create_consumer(String queueName, String filter, boolean browseOnly)
|
196
|
+
# Creates a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
|
197
|
+
# create_consumer(String queueName, String filter, int windowSize, int maxRate, boolean browseOnly)
|
198
|
+
# Creates a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
|
199
|
+
#
|
200
|
+
# The parameters for creating the consumer are as follows:
|
201
|
+
# :queue_name => The name of the queue to consume messages from. Mandatory
|
202
|
+
# :filter => Only consume messages matching the filter: Default: nil
|
203
|
+
# :browse_only => Whether to just browse the queue or consume messages
|
204
|
+
# true | false. Default: false
|
205
|
+
# :window_size => The consumer window size.
|
206
|
+
# :max_rate => The maximum rate to consume messages.
|
207
|
+
#
|
208
|
+
# Note: If either :window_size or :max_rate is supplied, then BOTH are required
|
209
|
+
#
|
210
|
+
# Returns a new Consumer that can be used for consuming messages from
|
211
|
+
# the queue
|
53
212
|
def create_consumer_from_params(params={})
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
213
|
+
if params.kind_of?(Hash)
|
214
|
+
raise("Missing mandatory parameter :queue_name") unless queue_name = params[:queue_name]
|
215
|
+
|
216
|
+
if params[:max_rate] || params[:window_size]
|
217
|
+
self.create_consumer(
|
218
|
+
queue_name,
|
219
|
+
params[:filter],
|
220
|
+
params[:window_size],
|
221
|
+
params[:max_rate],
|
222
|
+
params.fetch(:browse_only, false))
|
223
|
+
else
|
224
|
+
self.create_consumer(
|
225
|
+
queue_name,
|
226
|
+
params[:filter],
|
227
|
+
params.fetch(:browse_only, false))
|
228
|
+
end
|
64
229
|
else
|
65
|
-
self.create_consumer(
|
66
|
-
queue_name,
|
67
|
-
params[:filter],
|
68
|
-
params[:browse_only].nil? ? false : params[:browse_only])
|
230
|
+
self.create_consumer(params)
|
69
231
|
end
|
70
232
|
end
|
71
233
|
|
@@ -130,8 +292,7 @@ module Java::org.hornetq.api.core.client::ClientSession
|
|
130
292
|
# Creates a RequestorPattern to send a request and to synchronously wait for
|
131
293
|
# the reply, call the supplied block, then close the requestor
|
132
294
|
# Returns the result from the block
|
133
|
-
def requestor(request_address)
|
134
|
-
requestor = nil
|
295
|
+
def requestor(request_address,&block)
|
135
296
|
begin
|
136
297
|
requestor = self.create_requestor(request_address)
|
137
298
|
block.call(requestor)
|
@@ -150,7 +311,6 @@ module Java::org.hornetq.api.core.client::ClientSession
|
|
150
311
|
# replies, call the supplied block, then close the server
|
151
312
|
# Returns the result from the block
|
152
313
|
def server(input_queue, timeout=0, &block)
|
153
|
-
server = nil
|
154
314
|
begin
|
155
315
|
server = self.create_server(input_queue, timeout)
|
156
316
|
block.call(server)
|
@@ -158,7 +318,8 @@ module Java::org.hornetq.api.core.client::ClientSession
|
|
158
318
|
server.close if server
|
159
319
|
end
|
160
320
|
end
|
161
|
-
|
321
|
+
|
322
|
+
# Create a queue if it doesn't already exist
|
162
323
|
def create_queue_ignore_exists(address, queue, durable)
|
163
324
|
begin
|
164
325
|
create_queue(address, queue, durable)
|
@@ -2,7 +2,24 @@
|
|
2
2
|
|
3
3
|
# For the HornetQ Java documentation for this class see:
|
4
4
|
# http://hornetq.sourceforge.net/docs/hornetq-2.1.0.Final/api/index.html?org/hornetq/api/core/client/ClientConsumer.html
|
5
|
-
|
5
|
+
#
|
6
|
+
# Other methods still directly accessible through this class:
|
7
|
+
#
|
8
|
+
# void close()
|
9
|
+
# Closes the consumer
|
10
|
+
#
|
11
|
+
# boolean closed?
|
12
|
+
# Returns whether the consumer is closed or not
|
13
|
+
#
|
14
|
+
# Note: receive can be used directly, but it is recommended to use #each where possible
|
15
|
+
#
|
16
|
+
# ClientMessage receive()
|
17
|
+
# Receives a message from a queue
|
18
|
+
# ClientMessage receive(long timeout)
|
19
|
+
# Receives a message from a queue
|
20
|
+
# ClientMessage receive_immediate()
|
21
|
+
# Receives a message from a queue
|
22
|
+
#
|
6
23
|
class Java::org.hornetq.core.client.impl::ClientConsumerImpl
|
7
24
|
|
8
25
|
# For each message available to be consumed call the block supplied
|
@@ -23,27 +40,27 @@ class Java::org.hornetq.core.client.impl::ClientConsumerImpl
|
|
23
40
|
# and the time it took to process them.
|
24
41
|
# Statistics are cumulative between calls to ::each and will only be
|
25
42
|
# reset when ::each is called again with :statistics => true
|
26
|
-
def each(
|
43
|
+
def each(params={}, &proc)
|
27
44
|
raise "Consumer::each requires a code block to be executed for each message received" unless proc
|
28
45
|
|
29
46
|
message_count = nil
|
30
47
|
start_time = nil
|
31
|
-
timeout = (
|
48
|
+
timeout = (params[:timeout] || 0).to_i
|
32
49
|
|
33
|
-
if
|
50
|
+
if params[:statistics]
|
34
51
|
message_count = 0
|
35
52
|
start_time = Time.now
|
36
53
|
end
|
37
54
|
|
38
55
|
# Receive messages according to timeout
|
39
|
-
while message =
|
56
|
+
while message = receive_with_timeout(timeout) do
|
40
57
|
proc.call(message)
|
41
58
|
message_count += 1 if message_count
|
42
59
|
end
|
43
60
|
|
44
61
|
unless message_count.nil?
|
45
62
|
duration = Time.now - start_time
|
46
|
-
{:
|
63
|
+
{ :count => message_count,
|
47
64
|
:duration => duration,
|
48
65
|
:messages_per_second => (message_count/duration).to_i}
|
49
66
|
end
|
@@ -67,11 +84,11 @@ class Java::org.hornetq.core.client.impl::ClientConsumerImpl
|
|
67
84
|
#
|
68
85
|
# The statistics gathered are returned when :statistics => true and :async => false
|
69
86
|
#
|
70
|
-
def on_message(
|
87
|
+
def on_message(params={}, &proc)
|
71
88
|
raise "Consumer::on_message requires a code block to be executed for each message received" unless proc
|
72
89
|
|
73
|
-
@listener = HornetQ::Client::MessageHandler.new(
|
74
|
-
|
90
|
+
@listener = HornetQ::Client::MessageHandler.new(params, &proc)
|
91
|
+
setMessageHandler @listener
|
75
92
|
end
|
76
93
|
|
77
94
|
# Return the current statistics for a running ::on_message
|
@@ -1,6 +1,119 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
1
|
+
#
|
2
|
+
# Message
|
3
|
+
#
|
4
|
+
# A Message is a routable instance that has a payload.
|
5
|
+
#
|
6
|
+
# The payload (the "body") is opaque to the messaging system. A Message also has
|
7
|
+
# a fixed set of headers (required by the messaging system) and properties
|
8
|
+
# (defined by the users) that can be used by the messaging system to route the
|
9
|
+
# message (e.g. to ensure it matches a queue filter).
|
10
|
+
#
|
11
|
+
# See: http://hornetq.sourceforge.net/docs/hornetq-2.1.0.Final/api/org/hornetq/api/core/client/ClientMessage.html
|
12
|
+
#
|
13
|
+
# Other methods still directly accessible through this class:
|
14
|
+
#
|
15
|
+
# void acknowledge()
|
16
|
+
# Acknowledge reception of this message. If the session responsible to
|
17
|
+
# acknowledge this message has :auto_commit_acks => true, the
|
18
|
+
# transaction will automatically commit the current transaction.
|
19
|
+
# Otherwise, this acknowledgement will not be committed until the
|
20
|
+
# client commits the session transaction
|
21
|
+
#
|
22
|
+
# Message attribute methods available directly from the Java Message class:
|
23
|
+
#
|
24
|
+
# String address()
|
25
|
+
# Returns the address this message is sent to.
|
26
|
+
# void address=(SimpleString address)
|
27
|
+
# Sets the address to send this message to
|
28
|
+
#
|
29
|
+
# int body_size()
|
30
|
+
# Return the size (in bytes) of this message's body
|
31
|
+
#
|
32
|
+
# int delivery_count()
|
33
|
+
# Returns the number of times this message was delivered
|
34
|
+
#
|
35
|
+
# boolean durable?()
|
36
|
+
# Returns whether this message is durable or not
|
37
|
+
# void durable=(boolean durable)
|
38
|
+
# Sets whether this message is durable or not.
|
39
|
+
#
|
40
|
+
# int encode_size()
|
41
|
+
# Returns the size of the encoded message
|
42
|
+
#
|
43
|
+
# boolean expired?()
|
44
|
+
# Returns whether this message is expired or not
|
45
|
+
#
|
46
|
+
# long expiration()
|
47
|
+
# Returns the expiration time of this message
|
48
|
+
# void expiration=(long expiration)
|
49
|
+
# Sets the expiration of this message.
|
50
|
+
#
|
51
|
+
# boolean large_message?()
|
52
|
+
# Returns whether this message is a large message or a regular message
|
53
|
+
#
|
54
|
+
# long message_id()
|
55
|
+
# Returns the messageID
|
56
|
+
#
|
57
|
+
# byte priority()
|
58
|
+
# Returns the message priority.
|
59
|
+
# Values range from 0 (less priority) to 9 (more priority) inclusive.
|
60
|
+
# void priority=(byte priority)
|
61
|
+
# Sets the message priority.
|
62
|
+
# Value must be between 0 and 9 inclusive.
|
63
|
+
#
|
64
|
+
# #TODO Add timestamp_time attribute that converts to/from expiration under the covers
|
65
|
+
# long timestamp()
|
66
|
+
# Returns the message timestamp. The timestamp corresponds to the time
|
67
|
+
# this message was handled by a HornetQ server.
|
68
|
+
# void timestamp=(long timestamp)
|
69
|
+
# Sets the message timestamp.
|
70
|
+
#
|
71
|
+
# byte type()
|
72
|
+
# Returns this message type
|
73
|
+
# See: type_sym below for dealing with message types using Ruby Symbols
|
74
|
+
#
|
75
|
+
# org.hornetq.utils.UUID user_id()
|
76
|
+
# Returns the userID - this is an optional user specified UUID that can be set to identify the message and will be passed around with the message
|
77
|
+
# void user_id=(org.hornetq.utils.UUID userID)
|
78
|
+
# Sets the user ID
|
79
|
+
#
|
80
|
+
# Methods available directly for dealing with properties:
|
81
|
+
#
|
82
|
+
# boolean contains_property?(key)
|
83
|
+
# Returns true if this message contains a property with the given key, false else
|
84
|
+
#
|
85
|
+
# Note: Several other property methods are available directly, but since JRuby
|
86
|
+
# deals with the conversion for you they are not documented here
|
87
|
+
#
|
88
|
+
# Other methods still directly accessible through this class from its child classes:
|
89
|
+
#
|
90
|
+
# HornetQBuffer body_buffer()
|
91
|
+
# Returns the message body as a HornetQBuffer
|
92
|
+
#
|
93
|
+
# Map<String,Object> toMap()
|
94
|
+
#
|
95
|
+
#
|
96
|
+
# Methods for dealing with large messages:
|
97
|
+
#
|
98
|
+
# void save_to_output_stream(OutputStream out)
|
99
|
+
# Saves the content of the message to the OutputStream.
|
100
|
+
# It will block until the entire content is transfered to the OutputStream.
|
101
|
+
#
|
102
|
+
# void body_input_stream=(InputStream bodyInputStream)
|
103
|
+
# Sets the body's IntputStream.
|
104
|
+
# This method is used when sending large messages
|
105
|
+
#
|
106
|
+
# void output_stream=(OutputStream out)
|
107
|
+
# Sets the OutputStream that will receive the content of a message received
|
108
|
+
# in a non blocking way. This method is used when consuming large messages
|
109
|
+
#
|
110
|
+
# boolean wait_output_stream_completion(long timeMilliseconds)
|
111
|
+
# Wait the outputStream completion of the message. This method is used when consuming large messages
|
112
|
+
# timeMilliseconds - - 0 means wait forever
|
113
|
+
#
|
114
|
+
# Developer notes:
|
115
|
+
# Cannot add to the interface Java::org.hornetq.api.core::Message because these
|
116
|
+
# methods access instance variables in the Java object
|
4
117
|
class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
|
5
118
|
# Attributes
|
6
119
|
# attr_accessor :address, :type, :durable, :expiration, :priority, :timestamp, :user_id
|
@@ -31,18 +144,78 @@ class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
|
|
31
144
|
|
32
145
|
put_string_property(Java::OrgHornetqCoreClientImpl::ClientMessageImpl::REPLYTO_HEADER_NAME, val)
|
33
146
|
end
|
147
|
+
|
148
|
+
# Returns the message type as one of the following symbols
|
149
|
+
# :text => org.hornetq.api.core.Message::TEXT_TYPE
|
150
|
+
# :bytes => org.hornetq.api.core.Message::BYTES_TYPE
|
151
|
+
# :map => org.hornetq.api.core.Message::MAP_TYPE
|
152
|
+
# :object => org.hornetq.api.core.Message::OBJECT_TYPE
|
153
|
+
# :stream => org.hornetq.api.core.Message::STREAM_TYPE
|
154
|
+
# :default => org.hornetq.api.core.Message::DEFAULT_TYPE
|
155
|
+
# :unknown => Any other value for message type
|
156
|
+
#
|
157
|
+
# If the type is none of the above, nil is returned
|
158
|
+
#
|
159
|
+
def type_sym
|
160
|
+
case self.type
|
161
|
+
when Java::org.hornetq.api.core.Message::TEXT_TYPE #3
|
162
|
+
:text
|
163
|
+
when Java::org.hornetq.api.core.Message::BYTES_TYPE #4
|
164
|
+
:bytes
|
165
|
+
when Java::org.hornetq.api.core.Message::MAP_TYPE #5
|
166
|
+
:map
|
167
|
+
when Java::org.hornetq.api.core.Message::OBJECT_TYPE #2
|
168
|
+
:object
|
169
|
+
when Java::org.hornetq.api.core.Message::STREAM_TYPE #6
|
170
|
+
:stream
|
171
|
+
when Java::org.hornetq.api.core.Message::DEFAULT_TYPE #0
|
172
|
+
:default
|
173
|
+
else
|
174
|
+
:unknown
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Set the message type using a Ruby symbol
|
179
|
+
# Parameters
|
180
|
+
# sym: Must be any one of the following symbols
|
181
|
+
# :text => org.hornetq.api.core.Message::TEXT_TYPE
|
182
|
+
# :bytes => org.hornetq.api.core.Message::BYTES_TYPE
|
183
|
+
# :map => org.hornetq.api.core.Message::MAP_TYPE
|
184
|
+
# :object => org.hornetq.api.core.Message::OBJECT_TYPE
|
185
|
+
# :stream => org.hornetq.api.core.Message::STREAM_TYPE
|
186
|
+
# :default => org.hornetq.api.core.Message::DEFAULT_TYPE
|
187
|
+
#
|
188
|
+
def type_sym=(sym)
|
189
|
+
case sym
|
190
|
+
when :text
|
191
|
+
self.type = Java::org.hornetq.api.core.Message::TEXT_TYPE #3
|
192
|
+
when :bytes
|
193
|
+
self.type = Java::org.hornetq.api.core.Message::BYTES_TYPE #4
|
194
|
+
when :map
|
195
|
+
self.type = Java::org.hornetq.api.core.Message::MAP_TYPE #5
|
196
|
+
when :object
|
197
|
+
self.type = Java::org.hornetq.api.core.Message::OBJECT_TYPE #2
|
198
|
+
when :stream
|
199
|
+
self.type = Java::org.hornetq.api.core.Message::STREAM_TYPE #6
|
200
|
+
when :default
|
201
|
+
self.type = Java::org.hornetq.api.core.Message::DEFAULT_TYPE #0
|
202
|
+
else
|
203
|
+
raise "Invalid message type_sym:#{sym.to_s}"
|
204
|
+
end
|
205
|
+
end
|
34
206
|
|
35
207
|
# Return the body for this message
|
36
208
|
# TODO: Do remaining message Types
|
37
209
|
def body
|
38
210
|
# Allow this buffer to be read multiple times
|
39
|
-
body_buffer
|
211
|
+
buf = body_buffer
|
212
|
+
buf.reset_reader_index
|
213
|
+
available = body_size
|
214
|
+
|
215
|
+
return nil if available == 0
|
40
216
|
|
41
217
|
case type
|
42
218
|
when Java::org.hornetq.api.core.Message::BYTES_TYPE #4
|
43
|
-
buf = body_buffer
|
44
|
-
buf.reset_reader_index
|
45
|
-
available = body_size
|
46
219
|
result = ""
|
47
220
|
bytes_size = 1024
|
48
221
|
bytes = Java::byte[bytes_size].new
|
@@ -145,29 +318,6 @@ class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
|
|
145
318
|
property_exists(key.to_s) == true
|
146
319
|
end
|
147
320
|
|
148
|
-
# call-seq:
|
149
|
-
# body_buffer
|
150
|
-
#
|
151
|
-
# Return the message body as a HornetQBuffer
|
152
|
-
#
|
153
|
-
|
154
|
-
# call-seq:
|
155
|
-
# to_map
|
156
|
-
#
|
157
|
-
# Return the Message as a Map
|
158
|
-
#
|
159
|
-
|
160
|
-
# call-seq:
|
161
|
-
# remove_property(key)
|
162
|
-
#
|
163
|
-
# Remove a property
|
164
|
-
|
165
|
-
# call-seq:
|
166
|
-
# contains_property(key)
|
167
|
-
#
|
168
|
-
# Returns true if this message contains a property with the given key
|
169
|
-
# TODO: Symbols?
|
170
|
-
|
171
321
|
# Return TypedProperties
|
172
322
|
def getProperties
|
173
323
|
properties
|
@@ -187,19 +337,24 @@ class Java::OrgHornetqCoreClientImpl::ClientMessageImpl
|
|
187
337
|
def attributes
|
188
338
|
{
|
189
339
|
:address => address.nil? ? '' : address.to_string,
|
190
|
-
:
|
191
|
-
:
|
340
|
+
:body_size => body_size,
|
341
|
+
:delivery_count => delivery_count,
|
342
|
+
:durable? => durable?,
|
343
|
+
:encode_size => encode_size,
|
344
|
+
:expired? => expired?,
|
192
345
|
:expiration => expiration,
|
193
|
-
:
|
346
|
+
:large_message? => large_message?,
|
347
|
+
:message_id => message_id,
|
348
|
+
:priority => priority,
|
194
349
|
:timestamp => timestamp,
|
350
|
+
:type_sym => type_sym,
|
195
351
|
:user_id => user_id,
|
196
|
-
:encode_size => encode_size
|
197
352
|
}
|
198
353
|
end
|
199
354
|
|
200
355
|
# Does not include the body since it can only read once
|
201
356
|
def inspect
|
202
|
-
"#{self.class.name}:\nAttributes: #{attributes.inspect}\nProperties: #{properties.inspect}"
|
357
|
+
"#{self.class.name}:\nBody: #{body.inspect}\nAttributes: #{attributes.inspect}\nProperties: #{properties.inspect}"
|
203
358
|
end
|
204
359
|
|
205
360
|
end
|