torquebox-messaging 1.1.1-java → 2.0.0.beta1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/gem_hook.rb +26 -3
  2. data/lib/torquebox-messaging.jar +0 -0
  3. data/lib/torquebox-messaging.rb +2 -32
  4. data/lib/torquebox/messaging.rb +16 -0
  5. data/lib/torquebox/messaging/backgroundable.rb +32 -15
  6. data/lib/torquebox/messaging/backgroundable_processor.rb +32 -0
  7. data/lib/torquebox/messaging/connection.rb +127 -0
  8. data/lib/torquebox/messaging/connection_factory.rb +70 -0
  9. data/lib/torquebox/messaging/const_missing.rb +28 -0
  10. data/lib/torquebox/messaging/core.rb +27 -0
  11. data/lib/torquebox/messaging/destination.rb +68 -111
  12. data/lib/torquebox/messaging/ext/javax_jms_queue_browser.rb +1 -3
  13. data/lib/torquebox/messaging/future_responder.rb +10 -7
  14. data/lib/torquebox/messaging/json_message.rb +50 -0
  15. data/lib/torquebox/messaging/marshal_base64_message.rb +44 -0
  16. data/lib/torquebox/messaging/marshal_message.rb +43 -0
  17. data/lib/torquebox/messaging/message.rb +123 -0
  18. data/lib/torquebox/messaging/message_processor.rb +47 -0
  19. data/lib/torquebox/messaging/processor_wrapper.rb +38 -0
  20. data/lib/torquebox/messaging/queue.rb +61 -0
  21. data/lib/torquebox/messaging/session.rb +168 -0
  22. data/lib/torquebox/messaging/task.rb +7 -6
  23. data/lib/torquebox/messaging/text_message.rb +36 -0
  24. data/lib/torquebox/messaging/topic.rb +54 -0
  25. data/lib/torquebox/messaging/xa_connection.rb +58 -0
  26. data/lib/torquebox/messaging/xa_connection_factory.rb +59 -0
  27. data/lib/torquebox/messaging/xa_session.rb +30 -0
  28. data/licenses/lgpl-2.1.txt +7 -9
  29. data/spec/backgroundable_spec.rb +17 -24
  30. data/spec/destination_spec.rb +31 -318
  31. data/spec/future_responder_spec.rb +1 -1
  32. data/spec/json_message_spec.rb +50 -0
  33. data/spec/message_processor_spec.rb +54 -0
  34. data/spec/message_spec.rb +114 -0
  35. data/spec/task_spec.rb +11 -5
  36. metadata +38 -77
  37. data/lib/acl-spi-3.0.0.CR2.jar +0 -0
  38. data/lib/activation-1.1.jar +0 -0
  39. data/lib/authorization-spi-3.0.0.CR2.jar +0 -0
  40. data/lib/dtdparser-1.21.jar +0 -0
  41. data/lib/hornetq-core-2.1.2.Final.jar +0 -0
  42. data/lib/hornetq-jms-client-2.1.2.Final.jar +0 -0
  43. data/lib/hornetq-logging-2.1.2.Final.jar +0 -0
  44. data/lib/identity-spi-3.0.0.CR2.jar +0 -0
  45. data/lib/jaxb-api-2.1.9.jar +0 -0
  46. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  47. data/lib/jboss-jms-api_1.1_spec-1.0.0.Final.jar +0 -0
  48. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  49. data/lib/jboss-reflect-2.2.0.GA.jar +0 -0
  50. data/lib/jbosssx-bare-3.0.0.CR2.jar +0 -0
  51. data/lib/jbossxacml-2.0.5.CR1.jar +0 -0
  52. data/lib/jbossxb-2.0.3.GA.jar +0 -0
  53. data/lib/jnp-client-5.0.5.Final.jar +0 -0
  54. data/lib/jruby-complete-1.6.3.jar +0 -0
  55. data/lib/netty-3.2.1.Final.jar +0 -0
  56. data/lib/picketbox-acl-impl-3.0.0.CR2.jar +0 -0
  57. data/lib/picketbox-bare-3.0.0.CR2.jar +0 -0
  58. data/lib/picketbox-identity-impl-3.0.0.CR2.jar +0 -0
  59. data/lib/picketbox-spi-bare-3.0.0.CR2.jar +0 -0
  60. data/lib/torquebox-base-core.jar +0 -0
  61. data/lib/torquebox-base-metadata.jar +0 -0
  62. data/lib/torquebox-base-spi.jar +0 -0
  63. data/lib/torquebox-mc-support.jar +0 -0
  64. data/lib/torquebox-messaging-core.jar +0 -0
  65. data/lib/torquebox/messaging/client.rb +0 -75
  66. data/lib/torquebox/messaging/ext/javax_jms_session.rb +0 -153
  67. data/lib/xercesImpl-2.9.1.jar +0 -0
  68. data/lib/xml-apis-1.3.04.jar +0 -0
  69. data/spec/client_spec.rb +0 -116
  70. data/spec/dispatcher-queues.yml +0 -4
  71. data/spec/dispatcher_not_running.rb +0 -54
  72. data/spec/ext/java_jmx_session_spec.rb +0 -71
  73. data/spec/queues.yml +0 -6
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,75 +0,0 @@
1
- # Copyright 2008-2011 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
- begin
19
- require 'torquebox-messaging'
20
- rescue LoadError=>e
21
- # ignore!
22
- end
23
-
24
- require 'torquebox/naming'
25
- require 'torquebox/messaging/ext/javax_jms_session'
26
-
27
- module TorqueBox
28
- module Messaging
29
-
30
- class Client
31
-
32
- AUTO_ACK = javax.jms::Session::AUTO_ACKNOWLEDGE
33
- CLIENT_ACK = javax.jms::Session::CLIENT_ACKNOWLEDGE
34
- DUPS_OK_ACK = javax.jms::Session::DUPS_OK_ACKNOWLEDGE
35
-
36
-
37
- def self.canonical_ack_mode(ack_mode)
38
- case ( ack_mode )
39
- when Fixnum
40
- return ack_mode
41
- when :auto
42
- return AUTO_ACK
43
- when :client
44
- return CLIENT_ACK
45
- when :dups_ok
46
- return DUPS_OK_ACK
47
- end
48
- end
49
-
50
- def self.connect(options={}, &block)
51
- transacted = options.fetch(:transacted, true)
52
- ack_mode = options.fetch(:ack_mode, AUTO_ACK)
53
- naming_host = options[:naming_host]
54
- naming_port = options[:naming_port]
55
- connection_factory = nil
56
- TorqueBox::Naming.connect( naming_host, naming_port ) do |context|
57
- connection_factory = context['/ConnectionFactory']
58
- connection = connection_factory.createConnection
59
- connection.client_id = options[:client_id]
60
- session = connection.createSession( transacted, canonical_ack_mode( ack_mode ) )
61
- connection.start
62
- session.naming_context = context
63
- session.connection = connection
64
- return session if ( block.nil? )
65
- begin
66
- block.call( session )
67
- ensure
68
- connection.close()
69
- end
70
- end
71
- end
72
- end
73
-
74
- end
75
- end
@@ -1,153 +0,0 @@
1
- # Copyright 2008-2011 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/javax_jms_text_message'
19
-
20
- module javax.jms::Session
21
-
22
- attr_accessor :connection
23
- attr_accessor :naming_context
24
-
25
- def publish(destination, message, options = {})
26
- destination = lookup_destination( destination ) unless destination.is_a?( Java::javax.jms.Destination )
27
- producer = createProducer( destination )
28
- jms_message = create_text_message
29
- populate_message_headers(jms_message, options)
30
- populate_message_properties(jms_message, options[:properties])
31
- jms_message.encode message
32
- producer.send( jms_message,
33
- options.fetch(:delivery_mode, producer.delivery_mode),
34
- options.fetch(:priority, producer.priority),
35
- options.fetch(:ttl, producer.time_to_live) )
36
- jms_message
37
- ensure
38
- producer.close unless producer.nil?
39
- end
40
-
41
- # Returns decoded message, by default. Pass :decode=>false to
42
- # return the original JMS TextMessage. Pass :timeout to give up
43
- # after a number of milliseconds
44
- def receive(destination_name, options={})
45
- decode = options.fetch(:decode, true)
46
- timeout = options.fetch(:timeout, 0)
47
- selector = options.fetch(:selector, nil)
48
- destination = lookup_destination( destination_name )
49
- if options[:durable] && destination.class.name =~ /Topic/
50
- raise ArgumentError.new( "You must set the :client_id via Topic.new's connect_options to use :durable" ) unless connection.client_id
51
- consumer = createDurableSubscriber( destination,
52
- options.fetch(:subscriber_name, TorqueBox::Messaging::Topic::DEFAULT_SUBSCRIBER_NAME),
53
- selector,
54
- false )
55
- else
56
- consumer = createConsumer( destination, selector )
57
- end
58
- jms_message = consumer.receive( timeout )
59
- if jms_message
60
- decode ? jms_message.decode : jms_message
61
- end
62
- ensure
63
- consumer.close unless consumer.nil?
64
- end
65
-
66
- # Implement the request-response pattern. Sends a message to the
67
- # request destination and waits for a reply on the response
68
- # destination.
69
- #
70
- # Options:
71
- #
72
- # :timeout - specifies the time in miliseconds to wait for answer,
73
- # default: 10000 (10s)
74
- # :decode - pass false to return the original JMS TextMessage,
75
- # default: true
76
- #
77
- def publish_and_receive(destination, message, options = {})
78
- options[:timeout] ||= 10000 # 10s
79
- decode = options.fetch(:decode, false)
80
- options[:properties] ||= {}
81
- options[:properties]["synchronous"] = "true"
82
- wrapped_message = { :timeout => options[:timeout], :message => message }
83
- jms_message = publish(destination, wrapped_message, options)
84
- commit if transacted?
85
-
86
- options[:selector] = "JMSCorrelationID='#{jms_message.jms_message_id}'"
87
- response = receive(destination, options)
88
- commit if transacted?
89
-
90
- if response
91
- decode ? response.decode : response
92
- end
93
- end
94
-
95
- # Receiving end of the request-response pattern. The return value of
96
- # the block passed to this method is the response sent back to the
97
- # client. If no block is given then request is returned as the
98
- # response.
99
- def receive_and_publish(destination, options = {})
100
- selector = "synchronous = 'true'"
101
- selector = "#{selector} and (#{options[:selector]})" if options[:selector]
102
- receive_options = options.merge(:decode => false,
103
- :selector => selector)
104
-
105
- request = receive(destination, receive_options)
106
- unless request.nil?
107
- decoded_request = request.decode
108
- request_message = decoded_request[:message]
109
- # Base the response ttl off the original request timeout
110
- request_timeout = decoded_request[:timeout]
111
- options[:ttl] ||= request_timeout
112
-
113
- response = block_given? ? yield(request_message) : request_message
114
-
115
- options[:correlation_id] = request.jms_message_id
116
- publish(destination, response, options)
117
- end
118
- commit if transacted?
119
- end
120
-
121
- def lookup_destination(destination_name)
122
- @naming_context[ destination_name ]
123
- end
124
-
125
- def populate_message_headers(jms_message, options)
126
- return if options.nil?
127
- options.each do |key, value|
128
- case key.to_s
129
- when 'correlation_id' then jms_message.setJMSCorrelationID(value)
130
- when 'reply_to' then jms_message.setJMSReplyTo(value)
131
- when 'type' then jms_message.setJMSType(value)
132
- end
133
- end
134
- end
135
-
136
- def populate_message_properties(jms_message, properties)
137
- return if properties.nil?
138
- properties.each do |key, value|
139
- case value
140
- when Integer
141
- jms_message.set_long_property(key.to_s, value)
142
- when Float
143
- jms_message.set_double_property(key.to_s, value)
144
- when TrueClass, FalseClass
145
- jms_message.set_boolean_property(key.to_s, value)
146
- else
147
- jms_message.set_string_property(key.to_s, value.to_s)
148
- end
149
- end
150
- end
151
-
152
- end
153
-
Binary file
Binary file
data/spec/client_spec.rb DELETED
@@ -1,116 +0,0 @@
1
-
2
-
3
- require 'torquebox-messaging-container'
4
- require 'torquebox-naming-container'
5
- require 'torquebox-container-foundation'
6
-
7
- require 'torquebox/messaging/client'
8
-
9
- describe TorqueBox::Messaging::Client do
10
-
11
- describe "sending and receiving" do
12
- before(:each) do
13
- @container = TorqueBox::Container::Foundation.new
14
- @container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
15
- @container.enable( TorqueBox::Messaging::MessageBroker )
16
- @container.start
17
-
18
- @queues_yml = @container.deploy( File.join( File.dirname(__FILE__), 'queues.yml' ) )
19
- @container.process_deployments(true)
20
- end
21
-
22
- after(:each) do
23
- @container.undeploy( @queues_yml )
24
- @container.stop
25
- end
26
-
27
- it "should be able to send to a queue from two threads/two sessions" do
28
-
29
- received_message = nil
30
-
31
- consumer_thread = Thread.new {
32
- TorqueBox::Messaging::Client.connect() do |session|
33
- received_message = session.receive( '/queues/foo' )
34
- session.commit
35
- end
36
- }
37
-
38
- producer_thread = Thread.new {
39
- TorqueBox::Messaging::Client.connect() do |session|
40
- session.publish( '/queues/foo', "howdy" )
41
- session.commit
42
- end
43
- }
44
-
45
- consumer_thread.join
46
-
47
- received_message.should_not be_nil
48
- received_message.should eql( "howdy" )
49
- end
50
-
51
-
52
- it "should be able to send to a queue from one thread/one session" do
53
-
54
- received_message = nil
55
-
56
- TorqueBox::Messaging::Client.connect() do |session|
57
- session.publish( '/queues/foo', "howdy" )
58
- session.commit
59
- received_message = session.receive( '/queues/foo' )
60
- session.commit
61
- end
62
-
63
- received_message.should_not be_nil
64
- received_message.should eql( "howdy" )
65
- end
66
-
67
- it "should be able to send and receive a non-String message" do
68
- message = {:string => "a string", :symbol => :a_symbol, :hash => {}, :array => []}
69
- received_message = nil
70
-
71
- TorqueBox::Messaging::Client.connect() do |session|
72
- session.publish( '/queues/foo', message )
73
- session.commit
74
- received_message = session.receive( '/queues/foo' )
75
- session.commit
76
- end
77
-
78
- received_message.should_not be_nil
79
- received_message.should eql( message )
80
- end
81
-
82
- it "should properly decode a non-String message" do
83
- received_message = nil
84
- TorqueBox::Messaging::Client.connect() do |session|
85
- session.publish( '/queues/foo', [] )
86
- session.commit
87
- received_message = session.receive( '/queues/foo', :decode => false )
88
- session.commit
89
- end
90
- received_message.decode.should eql( [] )
91
- end
92
-
93
- it "should properly decode a String message" do
94
- received_message = nil
95
- TorqueBox::Messaging::Client.connect() do |session|
96
- session.publish( '/queues/foo', "foo" )
97
- session.commit
98
- received_message = session.receive( '/queues/foo', :decode => false )
99
- session.commit
100
- end
101
- received_message.decode.should eql( "foo" )
102
- end
103
-
104
- it "should timeout if asked" do
105
- received_message = nil
106
- TorqueBox::Messaging::Client.connect() do |session|
107
- received_message = session.receive( '/queues/foo', :timeout => 1 )
108
- end
109
- received_message.should be_nil
110
- end
111
-
112
- end
113
-
114
- end
115
-
116
-
@@ -1,4 +0,0 @@
1
-
2
- /queues/questions:
3
-
4
- /queues/answers:
@@ -1,54 +0,0 @@
1
- #require 'spec_helper'
2
-
3
- require 'rubygems'
4
- require 'torquebox-naming'
5
- require 'torquebox-naming-container'
6
- require 'torquebox-messaging-container'
7
- require 'torquebox/messaging/message_processor'
8
- require 'torquebox/messaging/destination'
9
-
10
- QUEUE_QUESTIONS = TorqueBox::Messaging::Queue.new("/queues/questions")
11
- QUEUE_ANSWERS = TorqueBox::Messaging::Queue.new("/queues/answers")
12
-
13
- TESTING_ON_WINDOWS = ( java.lang::System.getProperty( "os.name" ) =~ /.*windows*/i )
14
-
15
- class Upcaser < TorqueBox::Messaging::MessageProcessor
16
- def on_message(body)
17
- QUEUE_ANSWERS.publish( body.upcase )
18
- end
19
- end
20
-
21
- describe "dispatcher test" do
22
- before(:each) do
23
- @container = TorqueBox::Container::Foundation.new
24
- @container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=true}
25
- @container.enable( TorqueBox::Messaging::MessageBroker )
26
- @container.start
27
-
28
- @queues_yml = @container.deploy( File.join( File.dirname(__FILE__), 'dispatcher-queues.yml' ) )
29
- @container.process_deployments(true)
30
- puts "Deployed queues"
31
- end
32
-
33
- after(:each) do
34
- puts "UNDEPLOY queues"
35
- @container.undeploy( @queues_yml )
36
- puts "UNDEPLOYED queues"
37
- puts "STOP container"
38
- @container.stop
39
- puts "STOPPED container"
40
- end
41
-
42
- unless TESTING_ON_WINDOWS
43
- it "should associate a processor with a queue" do
44
- dispatcher = TorqueBox::Messaging::Dispatcher.new( :skip_naming=>true ) do
45
- map Upcaser, QUEUE_QUESTIONS
46
- end
47
- dispatcher.start
48
- QUEUE_QUESTIONS.publish "lkjsdf"
49
- QUEUE_ANSWERS.receive(:timeout => 2000).should == "LKJSDF"
50
- dispatcher.stop
51
- end
52
- end
53
-
54
- end