torquebox-messaging 3.2.0-java → 4.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/lib/torquebox-messaging.rb +19 -20
  3. data/lib/torquebox/messaging.rb +80 -20
  4. data/lib/torquebox/messaging/context.rb +174 -0
  5. data/lib/torquebox/messaging/destination.rb +164 -215
  6. data/lib/torquebox/messaging/helpers.rb +34 -0
  7. data/lib/torquebox/messaging/hornetq.rb +70 -0
  8. data/lib/torquebox/messaging/hornetq/address_settings.rb +228 -0
  9. data/lib/torquebox/messaging/queue.rb +139 -301
  10. data/lib/torquebox/messaging/topic.rb +84 -46
  11. data/lib/wunderboss-jars/hornetq-commons-2.4.5.Final.jar +0 -0
  12. data/lib/wunderboss-jars/hornetq-core-client-2.4.5.Final.jar +0 -0
  13. data/lib/wunderboss-jars/hornetq-jms-client-2.4.5.Final.jar +0 -0
  14. data/lib/wunderboss-jars/hornetq-jms-server-2.4.5.Final.jar +0 -0
  15. data/lib/wunderboss-jars/hornetq-journal-2.4.5.Final.jar +0 -0
  16. data/lib/wunderboss-jars/hornetq-native-2.4.5.Final.jar +0 -0
  17. data/lib/wunderboss-jars/hornetq-server-2.4.5.Final.jar +0 -0
  18. data/lib/wunderboss-jars/javax.inject-1.jar +0 -0
  19. data/lib/wunderboss-jars/jboss-common-core-2.2.10.GA.jar +0 -0
  20. data/lib/wunderboss-jars/jboss-connector-api_1.5_spec-1.0.0.Final.jar +0 -0
  21. data/lib/wunderboss-jars/jboss-jms-api_2.0_spec-1.0.0.Final.jar +0 -0
  22. data/lib/wunderboss-jars/jboss-transaction-api_1.1_spec-1.0.0.Final.jar +0 -0
  23. data/lib/wunderboss-jars/jboss-transaction-spi-7.0.0.Final.jar +0 -0
  24. data/lib/wunderboss-jars/jnpserver-5.0.3.GA.jar +0 -0
  25. data/lib/wunderboss-jars/netty-all-4.0.13.Final.jar +0 -0
  26. data/lib/wunderboss-jars/wunderboss-messaging-1.x.incremental.174.jar +0 -0
  27. metadata +88 -98
  28. data/lib/gem_hook.rb +0 -51
  29. data/lib/hornetq-commons-2.3.1.Final.jar +0 -0
  30. data/lib/hornetq-core-client-2.3.1.Final.jar +0 -0
  31. data/lib/hornetq-jms-client-2.3.1.Final.jar +0 -0
  32. data/lib/hornetq-journal-2.3.1.Final.jar +0 -0
  33. data/lib/jboss-jms-api_1.1_spec-1.0.1.Final.jar +0 -0
  34. data/lib/jboss-logging-3.1.2.GA.jar +0 -0
  35. data/lib/jboss-logmanager-1.4.0.Final.jar +0 -0
  36. data/lib/jboss-transaction-api_1.1_spec-1.0.1.Final.jar +0 -0
  37. data/lib/netty-3.6.2.Final.jar +0 -0
  38. data/lib/org.torquebox.messaging-client.rb +0 -20
  39. data/lib/torquebox-messaging.jar +0 -0
  40. data/lib/torquebox/messaging/backgroundable.rb +0 -250
  41. data/lib/torquebox/messaging/backgroundable_processor.rb +0 -52
  42. data/lib/torquebox/messaging/connection.rb +0 -74
  43. data/lib/torquebox/messaging/connection_factory.rb +0 -115
  44. data/lib/torquebox/messaging/const_missing.rb +0 -28
  45. data/lib/torquebox/messaging/core.rb +0 -27
  46. data/lib/torquebox/messaging/datamapper_marshaling.rb +0 -43
  47. data/lib/torquebox/messaging/echo_processor.rb +0 -35
  48. data/lib/torquebox/messaging/edn_message.rb +0 -26
  49. data/lib/torquebox/messaging/ext/javax_jms_queue_browser.rb +0 -25
  50. data/lib/torquebox/messaging/future.rb +0 -131
  51. data/lib/torquebox/messaging/future_responder.rb +0 -109
  52. data/lib/torquebox/messaging/future_status.rb +0 -37
  53. data/lib/torquebox/messaging/json_message.rb +0 -26
  54. data/lib/torquebox/messaging/marshal_base64_message.rb +0 -26
  55. data/lib/torquebox/messaging/marshal_message.rb +0 -43
  56. data/lib/torquebox/messaging/message.rb +0 -137
  57. data/lib/torquebox/messaging/message_processor.rb +0 -209
  58. data/lib/torquebox/messaging/processor_middleware/chain.rb +0 -89
  59. data/lib/torquebox/messaging/processor_middleware/default_middleware.rb +0 -39
  60. data/lib/torquebox/messaging/processor_middleware/with_transaction.rb +0 -35
  61. data/lib/torquebox/messaging/session.rb +0 -173
  62. data/lib/torquebox/messaging/task.rb +0 -66
  63. data/lib/torquebox/messaging/text_message.rb +0 -36
  64. data/lib/torquebox/messaging/xa_connection.rb +0 -55
  65. data/lib/torquebox/messaging/xa_connection_factory.rb +0 -45
  66. data/lib/torquebox/messaging/xa_session.rb +0 -51
  67. data/licenses/cc0-1.0.txt +0 -121
  68. data/spec/backgroundable_spec.rb +0 -319
  69. data/spec/chain_spec.rb +0 -160
  70. data/spec/datamapper_marshaling_spec.rb +0 -25
  71. data/spec/default_middleware_spec.rb +0 -21
  72. data/spec/destination_spec.rb +0 -248
  73. data/spec/future_responder_spec.rb +0 -81
  74. data/spec/future_spec.rb +0 -163
  75. data/spec/message_processor_spec.rb +0 -211
  76. data/spec/message_spec.rb +0 -135
  77. data/spec/task_spec.rb +0 -111
@@ -0,0 +1,34 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module TorqueBox
17
+ module Messaging
18
+ # @api private
19
+ module Helpers
20
+ WB = org.projectodd.wunderboss.WunderBoss
21
+ WBDestination = org.projectodd.wunderboss.messaging.Destination
22
+ WBMessaging = org.projectodd.wunderboss.messaging.Messaging
23
+ WBQueue = org.projectodd.wunderboss.messaging.Queue
24
+ WBTopic = org.projectodd.wunderboss.messaging.Topic
25
+ WBContext = org.projectodd.wunderboss.messaging.Context
26
+
27
+ protected
28
+
29
+ def default_broker
30
+ WB.find_or_create_component(WBMessaging.java_class, 'default', nil)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'torquebox/messaging/hornetq/address_settings'
16
+
17
+ module TorqueBox
18
+ module Messaging
19
+ module HornetQ
20
+ extend TorqueBox::Messaging::Helpers
21
+
22
+ # Returns the destination controller for the given destination.
23
+ #
24
+ # The returned controller depends on the type of the given
25
+ # destination and, for queues, the requested type:
26
+ #
27
+ # ```
28
+ # destination type controller
29
+ # -------------------------------------------------------------------------
30
+ # Queue :jms org.hornetq.api.jms.management.JMSQueueControl
31
+ # Queue :core org.hornetq.api.core.management.QueueControl
32
+ # Topic <ignored> org.hornetq.api.jms.management.TopicControl
33
+ # ```
34
+ #
35
+ # Refer to the javadocs for those control classes for details on the
36
+ # available operations.
37
+ # @param destination [Destination] Should be a {Queue} or
38
+ # {Topic}.
39
+ # @param type [:core, :jms]
40
+ def self.destination_controller(destination, type = :jms)
41
+ if destination.instance_of?(Queue) && type == :core
42
+ prefix = "core.queue."
43
+ else
44
+ prefix = ""
45
+ end
46
+ server_manager
47
+ .getHornetQServer
48
+ .getManagementService
49
+ .getResource("#{prefix}#{jms_name(destination)}")
50
+ end
51
+
52
+ protected
53
+
54
+ def self.jms_name(dest)
55
+ if dest.respond_to?(:internal_destination)
56
+ dest.internal_destination.jms_name
57
+ else
58
+ dest
59
+ end
60
+ end
61
+
62
+ def self.server_manager
63
+ unless default_broker.respond_to?(:jms_server_manager)
64
+ fail RuntimeError.new("The current broker isn't a HornetQ broker")
65
+ end
66
+ default_broker.jms_server_manager
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,228 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'forwardable'
16
+
17
+ module TorqueBox
18
+ module Messaging
19
+ module HornetQ
20
+ # Sets the HornetQ-specific address options for the given match.
21
+ #
22
+ # This provides programatic access to options that are normally set
23
+ # in the xml configuration.
24
+ class AddressSettings
25
+ include TorqueBox::Messaging::Helpers
26
+ extend Forwardable
27
+
28
+ # Creates and registers address settings.
29
+ #
30
+ # Creating a new AddressOptions for a match that you have set
31
+ # options for already will replace those prior options.
32
+ #
33
+ # @param match_or_dest must be either a {Destination} or a fully
34
+ # qualified jms destination name (prefixed with 'jms.queue.'
35
+ # or 'jms.topic.'). It may contain HornetQ wildcard matchers
36
+ # (see
37
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/wildcard-syntax.html)
38
+ def initialize(match_or_dest)
39
+ server_manager = HornetQ.server_manager
40
+ import_hornetq
41
+
42
+ @address_settings = org.hornetq.core.settings.impl.AddressSettings.new
43
+ server_manager.add_address_settings(normalize_destination_match(match_or_dest), @address_settings)
44
+ end
45
+
46
+ # Specifies what should happen when an address reaches
47
+ # max_size_bytes in undelivered messages.
48
+ #
49
+ # See
50
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/paging.html
51
+ #
52
+ # The policy can be one of:
53
+ #
54
+ # * :block - publish calls will block until the current size
55
+ # drops below max_size_bytes
56
+ # * :drop - new messages are silently dropped
57
+ # * :fail - new messages are dropped and an exception is thrown on publish
58
+ # * :page - new messages will be paged to disk
59
+ #
60
+ # @param policy [Symbol] (:page) The policy to use.
61
+ def address_full_message_policy=(policy)
62
+ policy_const = case policy.to_s
63
+ when "block"
64
+ AddressFullMessagePolicy::BLOCK
65
+ when "drop"
66
+ AddressFullMessagePolicy::DROP
67
+ when "fail"
68
+ AddressFullMessagePolicy::FAIL
69
+ when "page"
70
+ AddressFullMessagePolicy::PAGE
71
+ else
72
+ fail ArgumentError.new("#{policy} isn't a valid full message policy")
73
+ end
74
+ @address_settings.address_full_message_policy = policy_const
75
+ end
76
+
77
+ # If set, any messages that fail to deliver to their original
78
+ # destination will be delivered here. See
79
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/undelivered-messages.html#undelivered-messages.configuring
80
+ #
81
+ # @param address ('jms.queue.DLQ') The address to use. It can
82
+ # either be a {Destination} object or a fully-qualified
83
+ # destination name.
84
+ def dead_letter_address=(address)
85
+ @address_settings.dead_letter_address = SimpleString.new(HornetQ.jms_name(address))
86
+ end
87
+
88
+ # If set, any messages with a :ttl that expires before
89
+ # delivery will be delivered here. See
90
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/message-expiry.html#message-expiry.configuring
91
+ #
92
+ # @param address ('jms.queue.ExpiryQueue') The address to use. It can
93
+ # either be a {Destination} object or a fully-qualified
94
+ # destination name.
95
+ def expiry_address=(address)
96
+ @address_settings.expiry_address = SimpleString.new(HornetQ.jms_name(address))
97
+ end
98
+
99
+ # If true, only the most recent message
100
+ # for a last-value property will be retained.
101
+ #
102
+ # Setting this option will also cause
103
+ # {#address_full_message_policy=} to be set to :drop, as HornetQ
104
+ # has a bug related to paging last value queues. See
105
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/last-value-queues.html
106
+ #
107
+ # @param val [true,false] (false)
108
+ def last_value_queue=(val)
109
+ @address_settings.last_value_queue = val
110
+ self.address_full_message_policy = :drop
111
+ end
112
+
113
+ # @!method send_to_dla_on_no_route=(val)
114
+ #
115
+ # If true, any message that can't be routed to its destination
116
+ # will be sent to the {#dead_letter_address=}.
117
+ #
118
+ # @param val [true,false] (false)
119
+ def_delegator(:@address_settings, :setSendToDLAOnNoRoute, :send_to_dla_on_no_route=)
120
+
121
+ # @!method expiry_delay=(delay)
122
+ #
123
+ # If > -1, this value (in millis) is used as the
124
+ # default :ttl for messages that don't have a :ttl > 0 set.
125
+ #
126
+ # @param delay [Number] (-1) The delay.
127
+ def_delegators(:@address_settings, :expiry_delay=)
128
+
129
+ # @!method max_delivery_attempts=(attempts)
130
+ #
131
+ # The number of times delivery will be attempted for a message
132
+ # before giving up.
133
+
134
+ # If {#dead_letter_address=} is set, the message will be
135
+ # delivered there, or removed otherwise. See
136
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/undelivered-messages.html#undelivered-messages.configuring
137
+ #
138
+ # @param attempts [Number] (10)
139
+ def_delegators(:@address_settings, :max_delivery_attempts=)
140
+
141
+ # @!method max_redelivery_delay=(delay)
142
+ #
143
+ # Specifies the maximum redelivery delay (in millis) when a
144
+ # {#redelivery_multiplier=} is used.
145
+ #
146
+ # @param delay [Number] (same as {#redelivery_delay=})
147
+ def_delegators(:@address_settings, :max_redelivery_delay=)
148
+
149
+ # @!method max_size_bytes=(bytes)
150
+ #
151
+ # The maximum size (in bytes) of retained messages
152
+ # on an address before {#address_full_message_policy=} is applied. See
153
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/paging.html
154
+ #
155
+ # @param bytes [Number] (20_971_520 (20MB))
156
+ def_delegators(:@address_settings, :max_size_bytes=)
157
+
158
+ # @!method page_cache_max_size=(size)
159
+ #
160
+ # HornetQ will keep up to this many page files in memory to
161
+ # optimize IO. See
162
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/paging.html
163
+ #
164
+ # @param size [Number] (5)
165
+ def_delegators(:@address_settings, :page_cache_max_size=)
166
+
167
+ # @!method page_size_bytes=(bytes)
168
+ #
169
+ # The size (in bytes) of the page files created when
170
+ # paging. See
171
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/paging.html
172
+ #
173
+ # @param bytes [Number] (10_485_760 (10MB))
174
+ def_delegators(:@address_settings, :page_size_bytes=)
175
+
176
+ # @!method redelivery_delay=(delay)
177
+ #
178
+ # Specifies the delay (in millis) between redelivery
179
+ # attempts. See
180
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/undelivered-messages.html#undelivered-messages.delay
181
+ #
182
+ # @param delay [Number] (0)
183
+ def_delegators(:@address_settings, :redelivery_delay=)
184
+
185
+ # @!method redelivery_multiplier=(multiplier)
186
+ #
187
+ # Controls the backoff for redeliveries. The
188
+ # delay between redelivery attempts is calculated as
189
+ # {#redelivery_delay=} * ({#redelivery_multiplier=} ^ attempt_count). This won't have
190
+ # any effect if you don't also set {#redelivery_delay=} and {#max_redelivery_delay=}.
191
+ #
192
+ # @param multiplier [Float] (1.0)
193
+ def_delegators(:@address_settings, :redelivery_multiplier=)
194
+
195
+ # @!method redistribution_delay=(delay)
196
+ #
197
+ # Specifies the delay (in millis) to wait before
198
+ # redistributing messages from a node in a cluster to other
199
+ # nodes when the queue no longer has consumers on the current
200
+ # node. See
201
+ # http://docs.jboss.org/hornetq/2.3.0.Final/docs/user-manual/html/clusters.html
202
+ #
203
+ # @param delay [Number] (1_000)
204
+ def_delegators(:@address_settings, :redistribution_delay=)
205
+
206
+ protected
207
+
208
+ def normalize_destination_match(match_or_dest)
209
+ if (match = HornetQ.jms_name(match_or_dest)) != match_or_dest
210
+ match
211
+ elsif match_or_dest == "#" ||
212
+ /^jms\.(queue|topic)\./ =~ match_or_dest
213
+ match_or_dest
214
+ else
215
+ error_message = "#{match_or_dest} isn't a valid match. See the "\
216
+ "docs for TorqueBox::Messaging::HornetQ::AddressOptions"
217
+ fail ArgumentError.new(error_message)
218
+ end
219
+ end
220
+
221
+ def import_hornetq
222
+ java_import org.hornetq.core.settings.impl.AddressFullMessagePolicy
223
+ java_import org.hornetq.api.core.SimpleString
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
@@ -1,311 +1,149 @@
1
- # Copyright 2008-2013 Red Hat, Inc, and individual contributors.
2
- #
3
- # This is free software; you can redistribute it and/or modify it
4
- # under the terms of the GNU Lesser General Public License as
5
- # published by the Free Software Foundation; either version 2.1 of
6
- # the License, or (at your option) any later version.
7
- #
8
- # This software is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with this software; if not, write to the Free
15
- # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
- # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
-
18
- require 'torquebox/messaging/destination'
19
- require 'torquebox/service_registry'
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ java_import java.util.concurrent.TimeUnit
16
+ java_import org.projectodd.wunderboss.messaging.ConcreteReply
20
17
 
21
18
  module TorqueBox
22
19
  module Messaging
20
+ # Represents a messaging queue.
21
+ #
22
+ # Obtain a queue object by calling {TorqueBox::Messaging.queue}.
23
23
  class Queue < Destination
24
24
 
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
- destinationizer.create_queue(name, durable, selector, exported)
43
- end
44
-
45
- new(name, options)
46
- end
47
- end
48
-
49
- # Publishes a message and waits for the reply
50
- #
51
- # @param message The message to publish
52
- # @param options Optional parameters (a Hash)
53
- # @return Replied message
54
- def publish_and_receive(message, options={})
55
- result = nil
56
- with_session do |session|
57
- result = session.publish_and_receive(self, message,
58
- normalize_options(options))
59
- end
60
- result
61
- end
62
-
63
- # Waits for a message and replies
64
- #
65
- # @param options Optional parameters (a Hash)
66
- # @param block The block to handle the received message. The return value of the block will be send back to the queue.
67
- # @return [void]
68
- def receive_and_publish(options={}, &block)
69
- with_session do |session|
70
- session.receive_and_publish(self, normalize_options(options), &block)
71
- end
72
- end
73
-
74
- # Returns true if queue is paused, false
75
- # otherwise.
76
- def paused?
77
- with_queue_control do |control|
78
- control.is_paused
79
- end
80
- end
81
-
82
- # Pauses a queue.
83
- #
84
- # Messages put into a queue will not be delivered even
85
- # if there are connected consumers.
86
- #
87
- # When executed on a paused queue, nothing happens.
88
- #
89
- # @return [void]
90
- def pause
91
- with_queue_control do |control|
92
- control.pause
93
- end
94
- end
95
-
96
- # Resumes a queue after it was paused.
97
- # When executed on a active queue, nothing happens.
98
- #
99
- # @return [void]
100
- def resume
101
- with_queue_control do |control|
102
- control.resume
103
- end
104
- end
105
-
106
- # Removes messages from the queue.
107
- #
108
- # @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be removed.
109
- #
110
- # @example Remove messages with type property set
111
- #
112
- # @queue.remove_messages("type = 'tomatoe' OR type = 'garlic'")
113
- #
114
- # @return [Integer] Number of removed messages
115
- def remove_messages(filter = nil)
116
- with_queue_control do |control|
117
- control.remove_messages(filter)
118
- end
119
- end
120
-
121
- # Removes message from the queue by its id.
122
- #
123
- # @param id [String] ID of the message
124
- # @return [Boolean] true if the message was removed, false otherwise.
125
- def remove_message(id)
126
- with_queue_control do |control|
127
- control.remove_message(id)
128
- end
129
- end
130
-
131
- # Counts messages in the queue.
132
- #
133
- # @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be counted.
134
- #
135
- # @example Count messages with :type property set to 'tomatoe' or 'garlic'
136
- #
137
- # @queue.count_messages("type = 'tomatoe' OR type = 'garlic'")
138
- #
139
- # @return [Fixnum] The number of counted messages
140
- def count_messages(filter = nil)
141
- with_queue_control do |control|
142
- control.count_messages(filter)
143
- end
144
- end
145
-
146
- # Expires messages from the queue.
147
- #
148
- # @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be expired.
149
- #
150
- # @return [Fixnum] The number of expired messages
151
- def expire_messages(filter = nil)
152
- with_queue_control do |control|
153
- control.expire_messages(filter)
154
- end
155
- end
156
-
157
- # Expires message from the queue by its id.
158
- #
159
- # @return [Boolean] Returns true if the message was expired, false otherwise.
160
- def expire_message(id)
161
- with_queue_control do |control|
162
- control.expire_message(id)
163
- end
164
- end
165
-
166
- # Sends message to dead letter address.
167
- #
168
- # @return [Boolean] Returns true if the message was sent, false otherwise.
169
- def send_message_to_dead_letter_address(id)
170
- with_queue_control do |control|
171
- control.send_message_to_dead_letter_address(id)
172
- end
173
- end
174
-
175
- # Sends messages to dead letter address.
176
- #
177
- # @param filter [String] Expression in a SQL92-like syntax based on properties set on the messages. If not set all messages will be send.
178
- #
179
- # @return [Fixnum] The number of sent messages
180
- def send_messages_to_dead_letter_address(filter = nil)
181
- with_queue_control do |control|
182
- control.send_messages_to_dead_letter_address(filter)
183
- end
184
- end
185
-
186
- # Returns the consumer count connected to the queue.
187
- #
188
- # @return [Fixnum] The number of consumers
189
- def consumer_count
190
- with_queue_control do |control|
191
- control.consumer_count
192
- end
193
- end
194
-
195
- # Returns the scheduled messages count for this queue.
196
- #
197
- # @return [Fixnum] The number of scheduled messages
198
- def scheduled_messages_count
199
- with_queue_control do |control|
200
- control.scheduled_count
201
- end
202
- end
203
-
204
- # Moves messages from the queue to another queue specified in the
205
- # +queue_name+ parameter. Optional +reject_duplicates+ parameter
206
- # specifies if the duplicates should be rejected.
207
- #
208
- # @param queue_name [String] The name of the queue to move the messages to
209
- # @param filter [String] Parameter to limit messages to move. If provided nil or empty string, *all messages* will be moved.
210
- # @param reject_duplicates [Boolean] Specifies if the duplicates should be rejected
211
- # @return [Fixnum] The number of moved messages
212
- def move_messages(queue_name, filter = nil, reject_duplicates = false)
213
- with_queue_control do |control|
214
- control.move_messages(filter, queue_name, reject_duplicates)
215
- end
216
- end
217
-
218
- # Moves message for specific id from the queue to another queue
219
- # specified in the queue_name parameter.
220
- #
221
- # @param queue_name [String] The name of the queue to move the messages to
222
- # @param id [String] Message ID
223
- # @param reject_duplicates [Boolean] Specifies if the duplicates should be rejected
224
- # @return [Boolean] true if the message was moved,false otherwise
225
- def move_message(queue_name, id, reject_duplicates = false)
226
- with_queue_control do |control|
227
- control.move_message(id, queue_name, reject_duplicates)
228
- end
229
- end
230
-
231
- # Returns current expiry address.
232
- #
233
- # @return [String] Current expiry address. Please note that the destination contains 'jms.queue' or 'jms.topic' prefixes.
234
- def expiry_address
235
- with_queue_control do |control|
236
- control.expiry_address
237
- end
238
- end
239
-
240
- # Sets the expiry address.
241
- #
242
- # Please note that you need to provide the
243
- # *full address* containing the destination name and
244
- # jms.queue or jms.topic prefixes, for example:
245
- #
246
- # @example Set the destination to /queues/customexpire
247
- #
248
- # @queue.expiry_address = "jms.queue./queues./customexpire"
249
- #
250
- # @example Set the destination to /topics/customexpire
251
- #
252
- # @queue.expiry_address = "jms.topic./topics./customexpire"
253
- #
254
- # @return [String] Current expiry address
255
- def expiry_address=(address)
256
- with_queue_control do |control|
257
- control.set_expiry_address(address)
258
- end
259
-
260
- expiry_address
261
- end
262
-
263
- # Returns current dead letter address.
264
- #
265
- # @return [String] Current dead letter address. Please note that the destination contains 'jms.queue' or 'jms.topic' prefixes,
266
- def dead_letter_address
267
- with_queue_control do |control|
268
- control.dead_letter_address
269
- end
270
- end
271
-
272
- # Sets the dead letter address.
273
- #
274
- # Please note that you need to provide the
275
- # *full address* containing the destination name and
276
- # +jms.queue+ or +jms.topic+ prefixes, for example:
277
- #
278
- # @example Set the destination to /queues/customdead
279
- #
280
- # @queue.dead_letter_address = "jms.queue./queues./customdead"
281
- #
282
- # @example Set the destination to /topics/customdead
283
- #
284
- # @queue.dead_letter_address = "jms.topic./topics./customdead"
285
- #
286
- # @return [String] Current dead letter address
287
- def dead_letter_address=(address)
288
- with_queue_control do |control|
289
- control.set_dead_letter_address(address)
290
- end
291
-
292
- dead_letter_address
293
- end
294
-
295
-
296
- def to_s
297
- "[Queue: #{super}]"
25
+ # Valid options for Queue creation.
26
+ QUEUE_OPTIONS = optset(WBMessaging::CreateQueueOption, :default_options)
27
+
28
+ # Valid options for {#request}.
29
+ REQUEST_OPTIONS = optset(PUBLISH_OPTIONS, :timeout, :timeout_val)
30
+
31
+ # Sends a message this queue and waits for a response.
32
+ #
33
+ # Implements the request-response pattern, and is used in
34
+ # conjunction with {#respond}.
35
+ #
36
+ # Can optionally be given block that will be called with
37
+ # the message.
38
+ #
39
+ # If no context is provided, a new context will be created, then
40
+ # closed.
41
+ #
42
+ # @param message [Object] The message to send.
43
+ # @param options [Hash] Options for message publication.
44
+ # @option options :encoding [Symbol] (:marshal) one of: :edn, :json,
45
+ # :marshal, :marshal, :marshal_base64, :text
46
+ # @option options :priority [Symbol, Number] (:normal) 0-9, or
47
+ # one of: :low, :normal, :high, :critical
48
+ # @option options :ttl [Number] (0) time to live, in millis, 0
49
+ # == forever
50
+ # @option options :persistent [true, false] (true) whether
51
+ # undelivered messages survive restarts
52
+ # @option options :properties [Hash] a hash to which selectors
53
+ # may be applied
54
+ # @option options :context [Context] a context to use;
55
+ # caller expected to close
56
+ # @option options :timeout [Number] (0) Time in millis,
57
+ # after which the :timeout_val is returned. 0
58
+ # means wait forever.
59
+ # @option options :timeout_val [Object] The value to
60
+ # return when a timeout occurs.
61
+ # @return The message, or the return value of the block if a
62
+ # block is given.
63
+ def request(message, options = {}, &block)
64
+ validate_options(options, REQUEST_OPTIONS)
65
+ options = apply_default_options(options)
66
+ options = coerce_context(options)
67
+ options = normalize_publish_options(options)
68
+ encoding = options[:encoding] || Messaging.default_encoding
69
+ future = @internal_destination.request(message,
70
+ Codecs[encoding],
71
+ Codecs.java_codecs,
72
+ extract_options(options, WBQueue::RequestOption))
73
+ timeout = options[:timeout] || 0
74
+ result = if timeout == 0
75
+ future.get
76
+ else
77
+ begin
78
+ future.get(timeout, TimeUnit::MILLISECONDS)
79
+ rescue java.util.concurrent.TimeoutException
80
+ nil
81
+ end
82
+ end
83
+ msg = if result
84
+ result.body
85
+ else
86
+ options[:timeout_val]
87
+ end
88
+ if block
89
+ block.call(msg)
90
+ else
91
+ msg
92
+ end
93
+ end
94
+
95
+ # Valid options for {#respond}
96
+ RESPOND_OPTIONS = optset(WBQueue::RespondOption, :decode)
97
+
98
+ # Registers a block to receive each request message sent to this
99
+ # destination, and returns the result of the block call to the
100
+ # requestor.
101
+ #
102
+ # If given a context, the context must be remote, and the mode
103
+ # of that context is ignored, since it is used solely to
104
+ # generate sub-contexts for each listener thread. Closing the
105
+ # given context will also close the listener.
106
+ #
107
+ # If no context is provided, a new context will be created, then
108
+ # closed when the responder is closed.
109
+ #
110
+ # @param options [Hash] Options for the listener.
111
+ # @option options :concurrency [Number] (1) The number of
112
+ # threads handling messages.
113
+ # @option options :selector [String] A JMS (SQL 92) expression
114
+ # matching message properties
115
+ # @option options :decode [true, false] If true, the decoded
116
+ # message body is passed to the block. Otherwise, the
117
+ # base message object is passed.
118
+ # @option options :ttl [Number] (60000) The time for the
119
+ # response message to live, in millis.
120
+ # @option options :context [Context] a *remote* context to
121
+ # use; caller expected to close
122
+ # @return A listener object that can be stopped by
123
+ # calling .close on it.
124
+ def respond(options = {}, &block)
125
+ validate_options(options, RESPOND_OPTIONS)
126
+ options = apply_default_options(options)
127
+ options = coerce_context(options)
128
+ handler = MessageHandler.new do |message|
129
+ ConcreteReply.new(block.call(options.fetch(:decode, true) ? message.body : message),
130
+ nil)
131
+ end
132
+ @internal_destination.respond(handler,
133
+ Codecs.java_codecs,
134
+ extract_options(options, WBQueue::RespondOption))
135
+ end
136
+
137
+ protected
138
+
139
+ def initialize(name, options = {})
140
+ validate_options(options, QUEUE_OPTIONS)
141
+ coerced_opts = coerce_context(options)
142
+ create_options = extract_options(coerced_opts, WBMessaging::CreateQueueOption)
143
+ super(default_broker.find_or_create_queue(name, create_options),
144
+ options)
298
145
  end
299
146
 
300
- # @api private
301
- #
302
- # Retrieves the JMSQueueControl implementation for current
303
- # queue.
304
- def with_queue_control
305
- TorqueBox::ServiceRegistry.lookup("jboss.messaging.default") do |server|
306
- yield server.management_service.get_resource("jms.queue.#{@name}")
307
- end
308
- end
309
147
  end
310
148
  end
311
149
  end