org.torquebox.torquebox-messaging-client 1.0.0.Beta22-java → 1.0.0.Beta23-java

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gem_hook.rb CHANGED
@@ -2,3 +2,4 @@
2
2
  require 'torquebox/messaging/client'
3
3
  require 'torquebox/messaging/task'
4
4
  require 'torquebox/messaging/destination'
5
+ require 'torquebox/messaging/message_processor'
Binary file
Binary file
@@ -1,15 +1,17 @@
1
1
  module TorqueboxMessagingClient
2
- VERSION = '1.0.0.Beta22'
3
- MAVEN_VERSION = '1.0.0.Beta22'
2
+ VERSION = '1.0.0.Beta23'
3
+ MAVEN_VERSION = '1.0.0.Beta23'
4
4
  end
5
5
  begin
6
6
  require 'java'
7
7
  require File.dirname(__FILE__) + '/torquebox-messaging-client.jar'
8
- require File.dirname(__FILE__) + '/jboss-jms-api_1.1_spec-1.0.0.Beta1.jar'
8
+ require File.dirname(__FILE__) + '/jboss-jms-api_1.1_spec-1.0.0.Final.jar'
9
9
  require File.dirname(__FILE__) + '/hornetq-core-2.1.2.Final.jar'
10
10
  require File.dirname(__FILE__) + '/hornetq-jms-client-2.1.2.Final.jar'
11
11
  require File.dirname(__FILE__) + '/netty-3.2.1.Final.jar'
12
12
  require File.dirname(__FILE__) + '/hornetq-logging-2.1.2.Final.jar'
13
+ require File.dirname(__FILE__) + '/jnp-client-5.0.5.Final.jar'
14
+ require File.dirname(__FILE__) + '/jboss-common-core-2.2.17.GA.jar'
13
15
  require File.dirname(__FILE__) + '/jboss-logging-3.0.0.Beta4.jar'
14
16
  require File.dirname(__FILE__) + '/torquebox-interp-spi.jar'
15
17
  require File.dirname(__FILE__) + '/torquebox-interp-core.jar'
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -18,6 +18,15 @@ module TorqueBox
18
18
  end
19
19
  end
20
20
 
21
+ def receive options={}
22
+ result = nil
23
+ Client.connect(options) do |session|
24
+ result = session.receive( name, options )
25
+ session.commit if session.transacted?
26
+ end
27
+ result
28
+ end
29
+
21
30
  def start
22
31
  TorqueBox::Kernel.lookup("JMSServerManager") do |server|
23
32
  destination.name = name
@@ -5,8 +5,8 @@ module javax.jms::Session
5
5
  attr_accessor :connection
6
6
  attr_accessor :naming_context
7
7
 
8
- def publish(destination_name, message)
9
- destination = lookup_destination( destination_name )
8
+ def publish(destination, message)
9
+ destination = lookup_destination( destination ) unless destination.is_a?( Java::javax.jms.Destination )
10
10
  producer = createProducer( destination )
11
11
  jms_message = create_text_message
12
12
  jms_message.encode message
@@ -15,13 +15,52 @@ module javax.jms::Session
15
15
  end
16
16
 
17
17
  # Returns decoded message, by default. Pass :decode=>false to
18
- # return the original JMS TextMessage
18
+ # return the original JMS TextMessage. Pass :timeout to give up
19
+ # after a number of milliseconds
19
20
  def receive(destination_name, options={})
20
21
  decode = options.fetch(:decode, true)
22
+ timeout = options.fetch(:timeout, 0)
21
23
  destination = lookup_destination( destination_name )
22
24
  consumer = createConsumer( destination )
23
- jms_message = consumer.receive
24
- decode ? jms_message.decode : jms_message
25
+ jms_message = consumer.receive( timeout )
26
+ if jms_message
27
+ decode ? jms_message.decode : jms_message
28
+ end
29
+ end
30
+
31
+ # Sends a message to specified destination, creates a temporary
32
+ # queue and waits for reply (request-reply pattern).
33
+ #
34
+ # Options:
35
+ #
36
+ # :timeout - specifies the time in miliseconds to wait for answer,
37
+ # default: 10000 (10s)
38
+ # :decode - pass false to return the original JMS TextMessage,
39
+ # default: true
40
+ #
41
+ def send_and_receive(destination_name, message, options = {})
42
+ decode = options.fetch(:decode, true)
43
+ timeout = options.fetch(:timeout, 10000) # 10s
44
+ destination = lookup_destination( destination_name )
45
+
46
+ request_producer = createProducer( destination )
47
+
48
+ reply_queue = createTemporaryQueue
49
+ reply_receiver = createConsumer( reply_queue )
50
+
51
+ jms_message = createTextMessage
52
+ jms_message.jmsreply_to = reply_queue
53
+ jms_message.jmsdelivery_mode = Java::javax.jms.DeliveryMode.NON_PERSISTENT
54
+ jms_message.encode message
55
+
56
+ request_producer.send( jms_message )
57
+ commit
58
+ jms_message = reply_receiver.receive( timeout )
59
+ commit
60
+
61
+ if jms_message
62
+ decode ? jms_message.decode : jms_message
63
+ end
25
64
  end
26
65
 
27
66
  def lookup_destination(destination_name)
data/spec/client_spec.rb CHANGED
@@ -29,7 +29,6 @@ describe TorqueBox::Messaging::Client do
29
29
  received_message = nil
30
30
 
31
31
  consumer_thread = Thread.new {
32
- sleep( 2 )
33
32
  TorqueBox::Messaging::Client.connect() do |session|
34
33
  received_message = session.receive( '/queues/foo' )
35
34
  session.commit
@@ -105,13 +104,14 @@ describe TorqueBox::Messaging::Client do
105
104
  received_message.get_string_property( 'torquebox_encoding' ).should be_nil
106
105
  end
107
106
 
108
- it "should be able to get a reference to JMSServerManager" do
109
- @container["JMSServerManager"].should_not be_nil
110
- require 'org/torquebox/interp/core/kernel'
111
- TorqueBox::Kernel.kernel = @container.kernel
112
- TorqueBox::Kernel.lookup("JMSServerManager").should_not be_nil
107
+ it "should timeout if asked" do
108
+ received_message = nil
109
+ TorqueBox::Messaging::Client.connect() do |session|
110
+ received_message = session.receive( '/queues/foo', :timeout => 1 )
111
+ end
112
+ received_message.should be_nil
113
113
  end
114
-
114
+
115
115
  end
116
116
 
117
117
  end
@@ -1,4 +1,7 @@
1
1
 
2
+ require 'org.torquebox.torquebox-container-foundation'
3
+ require 'org.torquebox.torquebox-naming-container'
4
+ require 'org.torquebox.torquebox-messaging-container'
2
5
  require 'torquebox/messaging/destination'
3
6
 
4
7
  describe TorqueBox::Messaging::Destination do
@@ -31,4 +34,46 @@ describe TorqueBox::Messaging::Destination do
31
34
  topic.destroy
32
35
  end
33
36
 
37
+ describe "sending and receiving" do
38
+ before(:each) do
39
+ @container = TorqueBox::Container::Foundation.new
40
+ @container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
41
+ @container.enable( TorqueBox::Messaging::MessageBroker )
42
+ @container.start
43
+ end
44
+
45
+ after(:each) do
46
+ @container.stop
47
+ end
48
+
49
+ it "should be able to publish to and receive from a queue" do
50
+ queue = TorqueBox::Messaging::Queue.new "/queues/foo"
51
+ queue.start
52
+
53
+ queue.publish "howdy"
54
+ message = queue.receive
55
+
56
+ queue.destroy
57
+ message.should eql( "howdy" )
58
+ end
59
+
60
+ it "should publish to multiple topic consumers" do
61
+ topic = TorqueBox::Messaging::Topic.new "/topics/foo"
62
+ topic.start
63
+ threads, count = [], 10
64
+
65
+ # Use a threadsafe "array"
66
+ msgs = java.util.Collections.synchronizedList( [] )
67
+
68
+ # Ensure all clients are blocking on the receipt of a message
69
+ count.times { threads << Thread.new { msgs << topic.receive } }
70
+ sleep(1)
71
+ topic.publish "howdy"
72
+ threads.each {|t| t.join}
73
+
74
+ topic.destroy
75
+ msgs.to_a.should eql( ["howdy"] * count )
76
+ end
77
+ end
78
+
34
79
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - Beta22
10
- version: 1.0.0.Beta22
9
+ - Beta23
10
+ version: 1.0.0.Beta23
11
11
  platform: java
12
12
  authors: []
13
13
 
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-30 00:00:00 -05:00
18
+ date: 2010-12-06 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,8 +29,8 @@ dependencies:
29
29
  - 1
30
30
  - 0
31
31
  - 0
32
- - Beta22
33
- version: 1.0.0.Beta22
32
+ - Beta23
33
+ version: 1.0.0.Beta23
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
@@ -44,8 +44,8 @@ dependencies:
44
44
  - 1
45
45
  - 0
46
46
  - 0
47
- - Beta22
48
- version: 1.0.0.Beta22
47
+ - Beta23
48
+ version: 1.0.0.Beta23
49
49
  type: :development
50
50
  version_requirements: *id002
51
51
  - !ruby/object:Gem::Dependency
@@ -59,8 +59,8 @@ dependencies:
59
59
  - 1
60
60
  - 0
61
61
  - 0
62
- - Beta22
63
- version: 1.0.0.Beta22
62
+ - Beta23
63
+ version: 1.0.0.Beta23
64
64
  type: :development
65
65
  version_requirements: *id003
66
66
  - !ruby/object:Gem::Dependency
@@ -89,11 +89,13 @@ files:
89
89
  - licenses/lgpl-2.1.txt
90
90
  - lib/torquebox-messaging-client.jar
91
91
  - lib/org.torquebox.torquebox-messaging-client.rb
92
- - lib/jboss-jms-api_1.1_spec-1.0.0.Beta1.jar
92
+ - lib/jboss-jms-api_1.1_spec-1.0.0.Final.jar
93
93
  - lib/hornetq-core-2.1.2.Final.jar
94
94
  - lib/hornetq-jms-client-2.1.2.Final.jar
95
95
  - lib/netty-3.2.1.Final.jar
96
96
  - lib/hornetq-logging-2.1.2.Final.jar
97
+ - lib/jnp-client-5.0.5.Final.jar
98
+ - lib/jboss-common-core-2.2.17.GA.jar
97
99
  - lib/jboss-logging-3.0.0.Beta4.jar
98
100
  - lib/torquebox-interp-spi.jar
99
101
  - lib/torquebox-interp-core.jar