torquebox-messaging 2.3.2-java → 3.0.0.beta1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hornetq-commons-2.3.0.CR1.jar +0 -0
- data/lib/hornetq-core-client-2.3.0.CR1.jar +0 -0
- data/lib/hornetq-jms-client-2.3.0.CR1.jar +0 -0
- data/lib/hornetq-journal-2.3.0.CR1.jar +0 -0
- data/lib/jboss-logging-3.1.2.GA.jar +0 -0
- data/lib/jboss-logmanager-1.4.0.Final.jar +0 -0
- data/lib/netty-3.6.2.Final.jar +0 -0
- data/lib/torquebox/messaging/backgroundable.rb +16 -8
- data/lib/torquebox/messaging/backgroundable_processor.rb +2 -1
- data/lib/torquebox/messaging/connection.rb +21 -74
- data/lib/torquebox/messaging/connection_factory.rb +52 -13
- data/lib/torquebox/messaging/datamapper_marshaling.rb +1 -0
- data/lib/torquebox/messaging/destination.rb +77 -8
- data/lib/torquebox/messaging/echo_processor.rb +1 -0
- data/lib/torquebox/messaging/edn_message.rb +0 -11
- data/lib/torquebox/messaging/future_responder.rb +2 -2
- data/lib/torquebox/messaging/json_message.rb +0 -24
- data/lib/torquebox/messaging/marshal_base64_message.rb +0 -18
- data/lib/torquebox/messaging/marshal_message.rb +4 -5
- data/lib/torquebox/messaging/message.rb +10 -0
- data/lib/torquebox/messaging/message_processor.rb +162 -3
- data/lib/torquebox/messaging/processor_middleware/chain.rb +1 -0
- data/lib/torquebox/messaging/processor_middleware/default_middleware.rb +1 -0
- data/lib/torquebox/messaging/processor_middleware/with_transaction.rb +1 -0
- data/lib/torquebox/messaging/queue.rb +210 -41
- data/lib/torquebox/messaging/session.rb +4 -8
- data/lib/torquebox/messaging/task.rb +8 -6
- data/lib/torquebox/messaging/topic.rb +23 -11
- data/lib/torquebox/messaging/xa_connection.rb +22 -25
- data/lib/torquebox/messaging/xa_connection_factory.rb +2 -17
- data/lib/torquebox/messaging/xa_session.rb +21 -0
- data/lib/torquebox-messaging.jar +0 -0
- data/lib/torquebox-messaging.rb +9 -5
- data/licenses/cc0-1.0.txt +121 -0
- data/spec/backgroundable_spec.rb +21 -0
- data/spec/destination_spec.rb +81 -14
- data/spec/message_processor_spec.rb +151 -1
- data/spec/task_spec.rb +8 -1
- metadata +51 -65
- data/lib/hornetq-core-2.2.21.Final.jar +0 -0
- data/lib/hornetq-jms-2.2.21.Final.jar +0 -0
- data/lib/netty-3.2.6.Final.jar +0 -0
- data/licenses/lgpl-2.1.txt +0 -502
- data/spec/json_message_spec.rb +0 -50
@@ -15,6 +15,7 @@
|
|
15
15
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
16
16
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
17
17
|
|
18
|
+
# @api private
|
18
19
|
module Torquebox
|
19
20
|
module Messaging
|
20
21
|
# A message processor that echos any messages sent to it back to
|
@@ -15,23 +15,12 @@
|
|
15
15
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
16
16
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
17
17
|
|
18
|
-
require 'edn'
|
19
|
-
|
20
18
|
module TorqueBox
|
21
19
|
module Messaging
|
22
20
|
class EdnMessage < Message
|
23
21
|
ENCODING = :edn
|
24
22
|
JMS_TYPE = :text
|
25
|
-
|
26
|
-
def encode(message)
|
27
|
-
@jms_message.text = message.to_edn
|
28
|
-
end
|
29
|
-
|
30
|
-
def decode
|
31
|
-
EDN.read(@jms_message.text) unless @jms_message.text.nil?
|
32
|
-
end
|
33
23
|
end
|
34
|
-
|
35
24
|
Message.register_encoding( EdnMessage )
|
36
25
|
end
|
37
26
|
end
|
@@ -28,10 +28,10 @@ module TorqueBox
|
|
28
28
|
# @param [Integer] message_ttl The time-to-live used on messages
|
29
29
|
# to prevent them from staying in the queue indefinately if
|
30
30
|
# the result is never accessed.
|
31
|
-
def initialize(response_queue, correlation_id, message_ttl =
|
31
|
+
def initialize(response_queue, correlation_id, message_ttl = nil)
|
32
32
|
@queue = response_queue
|
33
33
|
@correlation_id = correlation_id
|
34
|
-
@message_ttl = message_ttl
|
34
|
+
@message_ttl = message_ttl || 600_000
|
35
35
|
end
|
36
36
|
|
37
37
|
# Signal that processing has started.
|
@@ -20,31 +20,7 @@ module TorqueBox
|
|
20
20
|
class JSONMessage < Message
|
21
21
|
ENCODING = :json
|
22
22
|
JMS_TYPE = :text
|
23
|
-
|
24
|
-
def require_json
|
25
|
-
# We can't ship our own json, as it may collide with the gem
|
26
|
-
# requirement for the app.
|
27
|
-
if !defined?( JSON )
|
28
|
-
begin
|
29
|
-
require 'json'
|
30
|
-
rescue LoadError => ex
|
31
|
-
raise RuntimeError.new( "Unable to load the json gem. Verify that is installed and in your Gemfile (if using Bundler)" )
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def encode(message)
|
37
|
-
require_json
|
38
|
-
@jms_message.text = JSON.fast_generate( message ) unless message.nil?
|
39
|
-
end
|
40
|
-
|
41
|
-
def decode
|
42
|
-
require_json
|
43
|
-
JSON.parse( @jms_message.text, :symbolize_names => true ) unless @jms_message.text.nil?
|
44
|
-
end
|
45
|
-
|
46
23
|
end
|
47
|
-
|
48
24
|
Message.register_encoding( JSONMessage )
|
49
25
|
end
|
50
26
|
end
|
@@ -15,30 +15,12 @@
|
|
15
15
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
16
16
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
17
17
|
|
18
|
-
require 'base64'
|
19
|
-
|
20
18
|
module TorqueBox
|
21
19
|
module Messaging
|
22
20
|
class MarshalBase64Message < Message
|
23
21
|
ENCODING = :marshal_base64
|
24
22
|
JMS_TYPE = :text
|
25
|
-
|
26
|
-
def encode(message)
|
27
|
-
unless message.nil?
|
28
|
-
marshalled = Marshal.dump( message )
|
29
|
-
@jms_message.text = Base64.encode64( marshalled )
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def decode
|
34
|
-
unless @jms_message.text.nil?
|
35
|
-
serialized = Base64.decode64( @jms_message.text )
|
36
|
-
Marshal.restore( serialized )
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
23
|
end
|
41
|
-
|
42
24
|
Message.register_encoding( MarshalBase64Message )
|
43
25
|
end
|
44
26
|
end
|
@@ -15,6 +15,8 @@
|
|
15
15
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
16
16
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
17
17
|
|
18
|
+
require 'torquebox/codecs'
|
19
|
+
|
18
20
|
module TorqueBox
|
19
21
|
module Messaging
|
20
22
|
class MarshalMessage < Message
|
@@ -22,10 +24,7 @@ module TorqueBox
|
|
22
24
|
JMS_TYPE = :bytes
|
23
25
|
|
24
26
|
def encode(message)
|
25
|
-
|
26
|
-
marshalled = Marshal.dump( message )
|
27
|
-
@jms_message.write_bytes( marshalled.to_java_bytes )
|
28
|
-
end
|
27
|
+
@jms_message.write_bytes(TorqueBox::Codecs.encode(message, ENCODING).to_java_bytes)
|
29
28
|
end
|
30
29
|
|
31
30
|
def decode
|
@@ -33,7 +32,7 @@ module TorqueBox
|
|
33
32
|
bytes = Java::byte[length].new
|
34
33
|
@jms_message.read_bytes( bytes )
|
35
34
|
@jms_message.reset
|
36
|
-
|
35
|
+
TorqueBox::Codecs.decode(String.from_java_bytes(bytes), ENCODING)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -15,6 +15,8 @@
|
|
15
15
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
16
16
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
17
17
|
|
18
|
+
require 'torquebox/codecs'
|
19
|
+
|
18
20
|
module TorqueBox
|
19
21
|
module Messaging
|
20
22
|
class Message
|
@@ -80,6 +82,14 @@ module TorqueBox
|
|
80
82
|
super || @jms_message.respond_to?(symbol, include_private)
|
81
83
|
end
|
82
84
|
|
85
|
+
def encode(message)
|
86
|
+
@jms_message.text = TorqueBox::Codecs.encode(message, self.class::ENCODING)
|
87
|
+
end
|
88
|
+
|
89
|
+
def decode
|
90
|
+
TorqueBox::Codecs.decode(@jms_message.text, self.class::ENCODING)
|
91
|
+
end
|
92
|
+
|
83
93
|
class << self
|
84
94
|
alias :__new__ :new
|
85
95
|
|
@@ -25,9 +25,18 @@ module TorqueBox
|
|
25
25
|
attr_accessor :message
|
26
26
|
|
27
27
|
def initialize
|
28
|
-
@message = nil
|
28
|
+
@message = nil
|
29
|
+
@proxy = nil
|
29
30
|
end
|
30
|
-
|
31
|
+
|
32
|
+
def initialize_proxy(group)
|
33
|
+
@proxy = MessageProcessorProxy.new(group)
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method, *args, &block)
|
37
|
+
@proxy.send( method, *args, &block )
|
38
|
+
end
|
39
|
+
|
31
40
|
def on_message(body)
|
32
41
|
throw "Your subclass must implement on_message(body)"
|
33
42
|
end
|
@@ -39,12 +48,162 @@ module TorqueBox
|
|
39
48
|
def process!(message)
|
40
49
|
@message = message
|
41
50
|
begin
|
42
|
-
on_message(
|
51
|
+
value = on_message(message.decode)
|
52
|
+
reply(value) if synchronous?
|
43
53
|
rescue Exception => e
|
44
54
|
on_error( e )
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
58
|
+
def reply(value)
|
59
|
+
TorqueBox::Messaging::Queue.new(@message.jms_message.jms_destination.queue_name).publish(value, :correlation_id => @message.jms_message.jms_message_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
|
64
|
+
# List all available message processors for current application.
|
65
|
+
#
|
66
|
+
# @return [Array<TorqueBox::Messaging::MessageProcessorProxy>] List of
|
67
|
+
# proxy objets to read and manage state of selected message
|
68
|
+
# processor
|
69
|
+
def list
|
70
|
+
processors = []
|
71
|
+
|
72
|
+
TorqueBox::MSC.get_services(/^#{messaging_service_name.canonical_name}\.\".*\"$/) do |service|
|
73
|
+
processors << MessageProcessorProxy.new(service.value)
|
74
|
+
end
|
75
|
+
|
76
|
+
processors
|
77
|
+
end
|
78
|
+
|
79
|
+
# Lookup a message processor by its destination and class name.
|
80
|
+
#
|
81
|
+
# @param [String] The destination name (queue, topic) to which
|
82
|
+
# a message processor is bound.
|
83
|
+
#
|
84
|
+
# @param [String] The class name of the message processor
|
85
|
+
# implementation.
|
86
|
+
def lookup(destination_name, class_name)
|
87
|
+
sn = messaging_service_name.append("#{destination_name}.#{class_name}")
|
88
|
+
|
89
|
+
# Try to find a message procesor for specified parameters
|
90
|
+
group = TorqueBox::ServiceRegistry::lookup(sn)
|
91
|
+
|
92
|
+
return MessageProcessorProxy.new(group) if group
|
93
|
+
|
94
|
+
# Ooops, no processor is found. Most probably wrong data.
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def messaging_service_name
|
101
|
+
TorqueBox::MSC.deployment_unit.service_name.append('torquebox').append('messaging')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class MessageProcessorProxy
|
107
|
+
def initialize(group)
|
108
|
+
@group = group
|
109
|
+
|
110
|
+
raise "Cannot create MessageProcessorProxy for non-existing MessageProcessorGroup" if @group.nil?
|
111
|
+
end
|
112
|
+
|
113
|
+
attr_reader :destination_name, :class_name
|
114
|
+
|
115
|
+
# Updates the concurrency,
|
116
|
+
#
|
117
|
+
# @note This method sets the concurrency and changes immediately
|
118
|
+
# the number of consumers for specified destination.
|
119
|
+
def concurrency=(size)
|
120
|
+
raise "Setting concurrency for '#{name}' to value < 0 is not allowed. You tried '#{size}'." if size < 0
|
121
|
+
|
122
|
+
return size if size == @group.concurrency
|
123
|
+
|
124
|
+
@group.update_concurrency(size)
|
125
|
+
|
126
|
+
concurrency
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns the concurrency
|
130
|
+
#
|
131
|
+
# @return Integer
|
132
|
+
def concurrency
|
133
|
+
@group.concurrency
|
134
|
+
end
|
135
|
+
|
136
|
+
# Returns the group name
|
137
|
+
#
|
138
|
+
# @return String
|
139
|
+
def name
|
140
|
+
@group.name
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns the destination (queue or topic) name
|
144
|
+
#
|
145
|
+
# @return String
|
146
|
+
def destination_name
|
147
|
+
@group.destination_name
|
148
|
+
end
|
149
|
+
|
150
|
+
# Returns the message processor implementation
|
151
|
+
# class name
|
152
|
+
#
|
153
|
+
# @return String
|
154
|
+
def class_name
|
155
|
+
@group.message_processor_class.name
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns the message selector
|
159
|
+
#
|
160
|
+
# If there is no message selector specified,
|
161
|
+
# returns empty string
|
162
|
+
#
|
163
|
+
# @return String
|
164
|
+
def message_selector
|
165
|
+
@group.message_selector
|
166
|
+
end
|
167
|
+
|
168
|
+
# Returns true if the message processor is a durable
|
169
|
+
# subscriber, false otherwise
|
170
|
+
#
|
171
|
+
# @return Boolean
|
172
|
+
def durable?
|
173
|
+
@group.durable
|
174
|
+
end
|
175
|
+
|
176
|
+
# Returns true if the message processor is synchronous,
|
177
|
+
# false otherwise
|
178
|
+
#
|
179
|
+
# @return Boolean
|
180
|
+
def synchronous?
|
181
|
+
@group.synchronous
|
182
|
+
end
|
183
|
+
|
184
|
+
# Returns true if the message processor is started,
|
185
|
+
# false otherwise
|
186
|
+
#
|
187
|
+
# @return Boolean
|
188
|
+
def started?
|
189
|
+
@group.status.eql?("STARTED")
|
190
|
+
end
|
191
|
+
|
192
|
+
# Starts the message processor
|
193
|
+
#
|
194
|
+
def start
|
195
|
+
@group.start
|
196
|
+
end
|
197
|
+
|
198
|
+
# Stops the message processor
|
199
|
+
#
|
200
|
+
def stop
|
201
|
+
@group.stop
|
202
|
+
end
|
203
|
+
|
204
|
+
def to_s
|
205
|
+
"<MessageProcessorProxy: #{name}>"
|
206
|
+
end
|
48
207
|
end
|
49
208
|
end
|
50
209
|
end
|
@@ -22,22 +22,36 @@ module TorqueBox
|
|
22
22
|
module Messaging
|
23
23
|
class Queue < Destination
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
class << self
|
26
|
+
|
27
|
+
# Creates the queue, starts and return a Queue object.
|
28
|
+
#
|
29
|
+
# @param name The name of the queue
|
30
|
+
# @param options Optional parameters (a Hash), including:
|
31
|
+
# @option options [String] :selector The selector for the queue
|
32
|
+
# @option options [Boolean] :durable If the queue should be durable
|
33
|
+
# @option options [Boolean] :exported If the queue should be visible in remote JNDI lookups
|
34
|
+
# @return [Queue] if the service is created and started
|
35
|
+
# @return [nil] if the service is not created in the specified time (30 s)
|
36
|
+
def start(name, options={})
|
37
|
+
selector = options.fetch(:selector, "")
|
38
|
+
durable = options.fetch(:durable, true)
|
39
|
+
exported = options.fetch(:exported, false)
|
40
|
+
|
41
|
+
with_destinationizer do |destinationizer|
|
42
|
+
latch = destinationizer.create_queue(name, durable, selector, exported)
|
43
|
+
return nil unless TorqueBox::Messaging::Destination.wait_for_latch(latch)
|
44
|
+
end
|
34
45
|
|
35
|
-
|
36
|
-
TorqueBox::ServiceRegistry.lookup("jboss.messaging.default.jms.manager") do |server|
|
37
|
-
server.destroyQueue( name )
|
46
|
+
new(name, options)
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
50
|
+
# Publishes a message and waits for the reply
|
51
|
+
#
|
52
|
+
# @param message The message to publish
|
53
|
+
# @param options Optional parameters (a Hash)
|
54
|
+
# @return Replied message
|
41
55
|
def publish_and_receive(message, options={})
|
42
56
|
result = nil
|
43
57
|
with_session do |session|
|
@@ -47,6 +61,11 @@ module TorqueBox
|
|
47
61
|
result
|
48
62
|
end
|
49
63
|
|
64
|
+
# Waits for a message and replies
|
65
|
+
#
|
66
|
+
# @param options Optional parameters (a Hash)
|
67
|
+
# @param block The block to handle the received message. The return value of the block will be send back to the queue.
|
68
|
+
# @return [void]
|
50
69
|
def receive_and_publish(options={}, &block)
|
51
70
|
with_session do |session|
|
52
71
|
session.receive_and_publish(self, normalize_options(options), &block)
|
@@ -67,6 +86,8 @@ module TorqueBox
|
|
67
86
|
# if there are connected consumers.
|
68
87
|
#
|
69
88
|
# When executed on a paused queue, nothing happens.
|
89
|
+
#
|
90
|
+
# @return [void]
|
70
91
|
def pause
|
71
92
|
with_queue_control do |control|
|
72
93
|
control.pause
|
@@ -75,6 +96,8 @@ module TorqueBox
|
|
75
96
|
|
76
97
|
# Resumes a queue after it was paused.
|
77
98
|
# When executed on a active queue, nothing happens.
|
99
|
+
#
|
100
|
+
# @return [void]
|
78
101
|
def resume
|
79
102
|
with_queue_control do |control|
|
80
103
|
control.resume
|
@@ -83,61 +106,207 @@ module TorqueBox
|
|
83
106
|
|
84
107
|
# Removes messages from the queue.
|
85
108
|
#
|
86
|
-
#
|
87
|
-
# selected messages from the queue. By default
|
88
|
-
# *all* messages will be removed.
|
89
|
-
#
|
90
|
-
# The :filter parameter is a String where you define
|
91
|
-
# expressions in a SQL92-like syntax based on properties
|
92
|
-
# set on the messages.
|
93
|
-
#
|
94
|
-
# Example:
|
109
|
+
# @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be removed.
|
95
110
|
#
|
96
|
-
#
|
111
|
+
# @example Remove messages with type property set
|
97
112
|
#
|
98
|
-
#
|
99
|
-
# to 'tomatoe' or 'garlic'
|
113
|
+
# @queue.remove_messages("type = 'tomatoe' OR type = 'garlic'")
|
100
114
|
#
|
101
|
-
#
|
115
|
+
# @return [Integer] Number of removed messages
|
102
116
|
def remove_messages(filter = nil)
|
103
117
|
with_queue_control do |control|
|
104
118
|
control.remove_messages(filter)
|
105
119
|
end
|
106
120
|
end
|
107
121
|
|
108
|
-
#
|
122
|
+
# Removes message from the queue by its id.
|
109
123
|
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
|
124
|
+
# @param id [String] ID of the message
|
125
|
+
# @return [Boolean] true if the message was removed, false otherwise.
|
126
|
+
def remove_message(id)
|
127
|
+
with_queue_control do |control|
|
128
|
+
control.remove_message(id)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Counts messages in the queue.
|
113
133
|
#
|
114
|
-
#
|
115
|
-
# expressions in a SQL92-like syntax based on properties
|
116
|
-
# set on the messages.
|
134
|
+
# @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be counted.
|
117
135
|
#
|
118
|
-
#
|
136
|
+
# @example Count messages with :type property set to 'tomatoe' or 'garlic'
|
119
137
|
#
|
120
|
-
#
|
138
|
+
# @queue.count_messages("type = 'tomatoe' OR type = 'garlic'")
|
121
139
|
#
|
122
|
-
#
|
123
|
-
# to 'tomatoe' or 'garlic'
|
140
|
+
# @return [Fixnum] The number of counted messages
|
124
141
|
def count_messages(filter = nil)
|
125
142
|
with_queue_control do |control|
|
126
143
|
control.count_messages(filter)
|
127
144
|
end
|
128
145
|
end
|
129
146
|
|
130
|
-
#
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
147
|
+
# Expires messages from the queue.
|
148
|
+
#
|
149
|
+
# @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be expired.
|
150
|
+
#
|
151
|
+
# @return [Fixnum] The number of expired messages
|
152
|
+
def expire_messages(filter = nil)
|
153
|
+
with_queue_control do |control|
|
154
|
+
control.expire_messages(filter)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Expires message from the queue by its id.
|
159
|
+
#
|
160
|
+
# @return [Boolean] Returns true if the message was expired, false otherwise.
|
161
|
+
def expire_message(id)
|
162
|
+
with_queue_control do |control|
|
163
|
+
control.expire_message(id)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Sends message to dead letter address.
|
168
|
+
#
|
169
|
+
# @return [Boolean] Returns true if the message was sent, false otherwise.
|
170
|
+
def send_message_to_dead_letter_address(id)
|
171
|
+
with_queue_control do |control|
|
172
|
+
control.send_message_to_dead_letter_address(id)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# Sends messages to dead letter address.
|
177
|
+
#
|
178
|
+
# @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be send.
|
179
|
+
#
|
180
|
+
# @return [Fixnum] The number of sent messages
|
181
|
+
def send_messages_to_dead_letter_address(filter = nil)
|
182
|
+
with_queue_control do |control|
|
183
|
+
control.send_messages_to_dead_letter_address(filter)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Returns the consumer count connected to the queue.
|
188
|
+
#
|
189
|
+
# @return [Fixnum] The number of consumers
|
190
|
+
def consumer_count
|
191
|
+
with_queue_control do |control|
|
192
|
+
control.consumer_count
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the scheduled messages count for this queue.
|
197
|
+
#
|
198
|
+
# @return [Fixnum] The number of scheduled messages
|
199
|
+
def scheduled_messages_count
|
200
|
+
with_queue_control do |control|
|
201
|
+
control.scheduled_count
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Moves messages from the queue to another queue specified in the
|
206
|
+
# +queue_name+ parameter. Optional +reject_duplicates+ parameter
|
207
|
+
# specifies if the duplicates should be rejected.
|
208
|
+
#
|
209
|
+
# @param queue_name [String] The name of the queue to move the messages to
|
210
|
+
# @param filter [String] Parameter to limit messages to move. If provided nil or empty string, *all messages* will be moved.
|
211
|
+
# @param reject_duplicates [Boolean] Specifies if the duplicates should be rejected
|
212
|
+
# @return [Fixnum] The number of moved messages
|
213
|
+
def move_messages(queue_name, filter = nil, reject_duplicates = false)
|
214
|
+
with_queue_control do |control|
|
215
|
+
control.move_messages(filter, queue_name, reject_duplicates)
|
135
216
|
end
|
136
217
|
end
|
137
218
|
|
219
|
+
# Moves message for specific id from the queue to another queue
|
220
|
+
# specified in the queue_name parameter.
|
221
|
+
#
|
222
|
+
# @param queue_name [String] The name of the queue to move the messages to
|
223
|
+
# @param id [String] Message ID
|
224
|
+
# @param reject_duplicates [Boolean] Specifies if the duplicates should be rejected
|
225
|
+
# @return [Boolean] true if the message was moved,false otherwise
|
226
|
+
def move_message(queue_name, id, reject_duplicates = false)
|
227
|
+
with_queue_control do |control|
|
228
|
+
control.move_message(id, queue_name, reject_duplicates)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Returns current expiry address.
|
233
|
+
#
|
234
|
+
# @return [String] Current expiry address. Please note that the destination contains 'jms.queue' or 'jms.topic' prefixes.
|
235
|
+
def expiry_address
|
236
|
+
with_queue_control do |control|
|
237
|
+
control.expiry_address
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# Sets the expiry address.
|
242
|
+
#
|
243
|
+
# Please note that you need to provide the
|
244
|
+
# *full address* containing the destination name and
|
245
|
+
# jms.queue or jms.topic prefixes, for example:
|
246
|
+
#
|
247
|
+
# @example Set the destination to /queues/customexpire
|
248
|
+
#
|
249
|
+
# @queue.expiry_address = "jms.queue./queues./customexpire"
|
250
|
+
#
|
251
|
+
# @example Set the destination to /topics/customexpire
|
252
|
+
#
|
253
|
+
# @queue.expiry_address = "jms.topic./topics./customexpire"
|
254
|
+
#
|
255
|
+
# @return [String] Current expiry address
|
256
|
+
def expiry_address=(address)
|
257
|
+
with_queue_control do |control|
|
258
|
+
control.set_expiry_address(address)
|
259
|
+
end
|
260
|
+
|
261
|
+
expiry_address
|
262
|
+
end
|
263
|
+
|
264
|
+
# Returns current dead letter address.
|
265
|
+
#
|
266
|
+
# @return [String] Current dead letter address. Please note that the destination contains 'jms.queue' or 'jms.topic' prefixes,
|
267
|
+
def dead_letter_address
|
268
|
+
with_queue_control do |control|
|
269
|
+
control.dead_letter_address
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# Sets the dead letter address.
|
274
|
+
#
|
275
|
+
# Please note that you need to provide the
|
276
|
+
# *full address* containing the destination name and
|
277
|
+
# +jms.queue+ or +jms.topic+ prefixes, for example:
|
278
|
+
#
|
279
|
+
# @example Set the destination to /queues/customdead
|
280
|
+
#
|
281
|
+
# @queue.dead_letter_address = "jms.queue./queues./customdead"
|
282
|
+
#
|
283
|
+
# @example Set the destination to /topics/customdead
|
284
|
+
#
|
285
|
+
# @queue.dead_letter_address = "jms.topic./topics./customdead"
|
286
|
+
#
|
287
|
+
# @return [String] Current dead letter address
|
288
|
+
def dead_letter_address=(address)
|
289
|
+
with_queue_control do |control|
|
290
|
+
control.set_dead_letter_address(address)
|
291
|
+
end
|
292
|
+
|
293
|
+
dead_letter_address
|
294
|
+
end
|
295
|
+
|
296
|
+
|
138
297
|
def to_s
|
139
298
|
"[Queue: #{super}]"
|
140
299
|
end
|
300
|
+
|
301
|
+
# @api private
|
302
|
+
#
|
303
|
+
# Retrieves the JMSQueueControl implementation for current
|
304
|
+
# queue.
|
305
|
+
def with_queue_control
|
306
|
+
TorqueBox::ServiceRegistry.lookup("jboss.messaging.default") do |server|
|
307
|
+
yield server.management_service.get_resource("jms.queue.#{@name}")
|
308
|
+
end
|
309
|
+
end
|
141
310
|
end
|
142
311
|
end
|
143
312
|
end
|