jsparrow 1.1.0 → 1.1.1
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/README.rdoc +13 -14
- data/VERSION.yml +1 -1
- data/lib/client.rb +161 -0
- data/lib/connection.rb +15 -175
- data/lib/jsparrow.rb +1 -0
- data/sample/sample.rb +5 -6
- data/spec/client_spec.rb +86 -0
- data/spec/connection_spec.rb +13 -102
- data/spec/messaging_spec.rb +3 -3
- data/spec/spec_helper.rb +15 -24
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -10,16 +10,16 @@ Make gem install:
|
|
10
10
|
|
11
11
|
=== Example
|
12
12
|
|
13
|
-
=====
|
13
|
+
===== Five steps to send and receive JMS messages to/from a JMS provider.
|
14
14
|
|
15
|
-
WARNING: OpenJMS will be used as JMS
|
15
|
+
WARNING: OpenJMS will be used as JMS provider, but any other could be used with no problems.
|
16
16
|
|
17
17
|
1) Create my_jsparrow_test.rb file and require the gems
|
18
18
|
|
19
19
|
require 'rubygems'
|
20
20
|
require 'jsparrow'
|
21
21
|
|
22
|
-
2) Setup indispensable informations to connect your JMS
|
22
|
+
2) Setup indispensable informations to connect your JMS provider
|
23
23
|
|
24
24
|
JSparrow::Connection.configure do |connection|
|
25
25
|
connection.use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar'
|
@@ -29,20 +29,17 @@ WARNING: OpenJMS will be used as JMS middleware, but any other could be used wit
|
|
29
29
|
# :security_principal => 'user',
|
30
30
|
# :security_credentials => 'password'
|
31
31
|
|
32
|
-
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
|
33
|
-
|
32
|
+
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
|
33
|
+
|
34
|
+
connection.enable_queues :my_queue => 'MyQueue'
|
34
35
|
end
|
35
36
|
|
36
|
-
3) Create the client and
|
37
|
+
3) Create the client and start it
|
37
38
|
|
38
39
|
jms_client = JSparrow::Connection.new_client
|
39
|
-
jms_client.enable_queues :my_queue => 'MyQueue'
|
40
|
-
|
41
|
-
4) After appropriate setup, start the client
|
42
|
-
|
43
40
|
jms_client.start
|
44
41
|
|
45
|
-
|
42
|
+
4) OK! Now you can send and receive messages right now!
|
46
43
|
|
47
44
|
jms_client.queue_sender(:my_queue).send_text_message('jsparrow rocks!') do |msg|
|
48
45
|
msg.set_string_property('recipient', 'jsparrow-example')
|
@@ -57,17 +54,19 @@ WARNING: OpenJMS will be used as JMS middleware, but any other could be used wit
|
|
57
54
|
puts "message: #{msg.text}" # message: jsparrow rocks!
|
58
55
|
end
|
59
56
|
|
60
|
-
|
57
|
+
5) After you receive your amazing messages, stop the client
|
61
58
|
|
62
59
|
jms_client.stop
|
63
60
|
|
64
|
-
So, now that you
|
61
|
+
So, now that you wrote code and save it, start the OpenJMS server, create the queue (MyQueue), and run above script:
|
65
62
|
|
66
63
|
jruby my_jsparrow_test.rb
|
67
64
|
|
68
65
|
jsparrow rocks! =)
|
69
66
|
|
70
|
-
|
67
|
+
=== Sample
|
68
|
+
|
69
|
+
===== A very simple sample code
|
71
70
|
|
72
71
|
Or, if you don't want write code, only do it:
|
73
72
|
|
data/VERSION.yml
CHANGED
data/lib/client.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Classes Java usadas nesse arquivo
|
2
|
+
import 'javax.naming.InitialContext'
|
3
|
+
|
4
|
+
module JSparrow
|
5
|
+
module Connection
|
6
|
+
|
7
|
+
#
|
8
|
+
# Cliente JMS que possibilita a conexao com o servidor de aplicacoes Java EE
|
9
|
+
# que prove o servico JMS.
|
10
|
+
#
|
11
|
+
class Client
|
12
|
+
def initialize(connection_config, jndi_context_builder)
|
13
|
+
@connection_config = connection_config
|
14
|
+
@jndi_context_builder = jndi_context_builder
|
15
|
+
|
16
|
+
# Conexoes, filas, topicos, senders e receivers que serao habilitados
|
17
|
+
@connection_factories = {}
|
18
|
+
@queues = {}
|
19
|
+
@queue_senders = {}
|
20
|
+
@queue_receivers = {}
|
21
|
+
@topics = {}
|
22
|
+
@topic_senders = {}
|
23
|
+
@topic_receivers = {}
|
24
|
+
|
25
|
+
# Foi iniciado?
|
26
|
+
@started = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def is_started?
|
30
|
+
@started
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
raise InvalidClientStateError.new('started', 'start') if is_started?
|
35
|
+
|
36
|
+
begin
|
37
|
+
@jndi_context = @jndi_context_builder.build
|
38
|
+
rescue => cause
|
39
|
+
raise ClientInitializationError.new(@connection_config, cause)
|
40
|
+
end
|
41
|
+
|
42
|
+
@connection_factories, @queues, @topics = lookup_resources
|
43
|
+
|
44
|
+
@started = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_stoped?
|
48
|
+
!@started
|
49
|
+
end
|
50
|
+
|
51
|
+
def stop
|
52
|
+
raise InvalidClientStateError.new('stoped', 'stop') if is_stoped?
|
53
|
+
|
54
|
+
@jndi_context.close
|
55
|
+
|
56
|
+
@started = false
|
57
|
+
end
|
58
|
+
|
59
|
+
def queue_connection_factory_enabled?
|
60
|
+
@connection_config.enabled_connection_factories.include?(:queue_connection_factory)
|
61
|
+
end
|
62
|
+
|
63
|
+
def queue_connection_factory
|
64
|
+
@connection_factories[:queue_connection_factory]
|
65
|
+
end
|
66
|
+
|
67
|
+
def queue_enabled?(queue_name)
|
68
|
+
@connection_config.enabled_queues.include?(queue_name)
|
69
|
+
end
|
70
|
+
|
71
|
+
def queue(queue_name)
|
72
|
+
raise NameError, "Queue '#{queue_name}' does not exist." unless queue_enabled?(queue_name)
|
73
|
+
|
74
|
+
@queues[queue_name]
|
75
|
+
end
|
76
|
+
|
77
|
+
def queue_sender(queue_name)
|
78
|
+
@queue_senders[queue_name] ||=
|
79
|
+
Messaging::Sender.new(queue_connection_factory, queue(queue_name))
|
80
|
+
end
|
81
|
+
|
82
|
+
def queue_receiver(queue_name)
|
83
|
+
@queue_receivers[queue_name] ||=
|
84
|
+
Messaging::Receiver.new(queue_connection_factory, queue(queue_name))
|
85
|
+
end
|
86
|
+
|
87
|
+
def topic_connection_factory_enabled?
|
88
|
+
@connection_config.enabled_connection_factories.include?(:topic_connection_factory)
|
89
|
+
end
|
90
|
+
|
91
|
+
def topic_connection_factory
|
92
|
+
@connection_factories[:topic_connection_factory]
|
93
|
+
end
|
94
|
+
|
95
|
+
def topic_enabled?(topic_name)
|
96
|
+
@connection_config.enabled_topics.include?(topic_name)
|
97
|
+
end
|
98
|
+
|
99
|
+
def topic(topic_name)
|
100
|
+
raise NameError, "Topic '#{topic_name}' does not exist." unless topic_enabled?(topic_name)
|
101
|
+
|
102
|
+
@topics[topic_name]
|
103
|
+
end
|
104
|
+
|
105
|
+
def topic_sender(topic_name)
|
106
|
+
@topic_senders[topic_name] ||=
|
107
|
+
Messaging::Sender.new(topic_connection_factory, topic(topic_name))
|
108
|
+
end
|
109
|
+
|
110
|
+
def topic_receiver(topic_name)
|
111
|
+
@topic_receivers[topic_name] ||=
|
112
|
+
Messaging::Receiver.new(topic_connection_factory, topic(topic_name))
|
113
|
+
end
|
114
|
+
|
115
|
+
# -- Private methods -- #
|
116
|
+
private
|
117
|
+
|
118
|
+
def lookup_resources
|
119
|
+
@lookuped_connection_factories = lookup_resource(@connection_config.enabled_connection_factories)
|
120
|
+
@lookuped_queues = lookup_resource(@connection_config.enabled_queues)
|
121
|
+
@lookuped_topic = lookup_resource(@connection_config.enabled_topics)
|
122
|
+
|
123
|
+
return @lookuped_connection_factories, @lookuped_queues, @lookuped_topic
|
124
|
+
end
|
125
|
+
|
126
|
+
def lookup_resource(jndi_names = {})
|
127
|
+
lookuped = {}
|
128
|
+
|
129
|
+
return lookuped unless jndi_names
|
130
|
+
|
131
|
+
jndi_names.each do |key, jndi_name|
|
132
|
+
lookuped[key] = @jndi_context.lookup(jndi_name)
|
133
|
+
end
|
134
|
+
|
135
|
+
lookuped
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class ClientInitializationError < StandardError
|
140
|
+
attr_reader :config, :cause
|
141
|
+
|
142
|
+
def initialize(config, cause)
|
143
|
+
super("Could not open connection to server. Verify the config's config.")
|
144
|
+
|
145
|
+
@config = config
|
146
|
+
@cause = cause
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class InvalidClientStateError < StandardError
|
151
|
+
attr_reader :state, :operation
|
152
|
+
|
153
|
+
def initialize(state, operation)
|
154
|
+
super("Could not did #{operation} because client is #{state}.")
|
155
|
+
|
156
|
+
@state = state
|
157
|
+
@operation = operation
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/lib/connection.rb
CHANGED
@@ -6,35 +6,37 @@ module JSparrow
|
|
6
6
|
module Connection
|
7
7
|
|
8
8
|
#
|
9
|
-
# Metodo usado para configurar a conexao com o
|
9
|
+
# Metodo usado para configurar a conexao com o provedor de JMS.
|
10
10
|
#
|
11
11
|
def self.configure
|
12
|
-
@@
|
12
|
+
@@config = Configuration.new
|
13
13
|
|
14
|
-
yield @@
|
14
|
+
yield @@config
|
15
|
+
|
16
|
+
@@config
|
15
17
|
end
|
16
18
|
|
17
19
|
#
|
18
|
-
# Metodo usado para obter a configuracao para conexao com o
|
20
|
+
# Metodo usado para obter a configuracao para conexao com o provedor de JMS.
|
19
21
|
#
|
20
|
-
def self.
|
21
|
-
@@
|
22
|
+
def self.configuration
|
23
|
+
@@config
|
22
24
|
end
|
23
25
|
|
24
26
|
#
|
25
27
|
# Metodo usado para criar um novo Client JMS.
|
26
28
|
#
|
27
29
|
def self.new_client
|
28
|
-
jndi_context_builder = JNDI::ContextBuilder.new(@@
|
30
|
+
jndi_context_builder = JNDI::ContextBuilder.new(@@config.jms_client_jar, @@config.jndi_properties)
|
29
31
|
|
30
|
-
Client.new(@@
|
32
|
+
Client.new(@@config, jndi_context_builder)
|
31
33
|
end
|
32
34
|
|
33
35
|
#
|
34
36
|
# Configuracoes necessarias para que clientes JMS se conetem
|
35
|
-
# ao
|
37
|
+
# ao provedor de mensageria via contexto JNDI.
|
36
38
|
#
|
37
|
-
class
|
39
|
+
class Configuration
|
38
40
|
attr_reader :jms_client_jar, :jndi_properties,
|
39
41
|
:enabled_connection_factories, :enabled_queues, :enabled_topics
|
40
42
|
|
@@ -58,182 +60,20 @@ module JSparrow
|
|
58
60
|
@enabled_topics = jndi_names
|
59
61
|
end
|
60
62
|
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Cliente JMS que possibilita a conexao com o servidor de aplicacoes Java EE
|
64
|
-
# que prove o servico JMS.
|
65
|
-
#
|
66
|
-
class Client
|
67
|
-
def initialize(connection_properties, jndi_context_builder)
|
68
|
-
@connection_properties = connection_properties
|
69
|
-
@jndi_context_builder = jndi_context_builder
|
70
|
-
|
71
|
-
@jndi_name_of_enabled_connection_factories = @connection_properties.enabled_connection_factories
|
72
|
-
@jndi_name_of_enabled_queues = {}
|
73
|
-
@jndi_name_of_enabled_topics = {}
|
74
|
-
|
75
|
-
# Conexoes, filas, topicos, senders e receivers que serao habilitados
|
76
|
-
@connection_factories = {}
|
77
|
-
@queues = {}
|
78
|
-
@queue_senders = {}
|
79
|
-
@queue_receivers = {}
|
80
|
-
@topics = {}
|
81
|
-
@topic_senders = {}
|
82
|
-
@topic_receivers = {}
|
83
|
-
|
84
|
-
# Foi startado?
|
85
|
-
@started = false
|
86
|
-
end
|
87
|
-
|
88
|
-
def is_started?
|
89
|
-
@started
|
90
|
-
end
|
91
|
-
|
92
|
-
def start
|
93
|
-
raise InvalidClientStateError.new('started', 'start') if is_started?
|
94
|
-
|
95
|
-
begin
|
96
|
-
@jndi_context = @jndi_context_builder.build
|
97
|
-
rescue => cause
|
98
|
-
raise ClientInitializationError.new(@connection_properties, cause)
|
99
|
-
end
|
100
|
-
|
101
|
-
@connection_factories = lookup_resource(@jndi_name_of_enabled_connection_factories)
|
102
|
-
@queues = lookup_resource(@jndi_name_of_enabled_queues)
|
103
|
-
@topics = lookup_resource(@jndi_name_of_enabled_topics)
|
104
|
-
|
105
|
-
@started = true
|
106
|
-
end
|
107
|
-
|
108
|
-
def is_stoped?
|
109
|
-
!@started
|
110
|
-
end
|
111
|
-
|
112
|
-
def stop
|
113
|
-
raise InvalidClientStateError.new('stoped', 'stop') if is_stoped?
|
114
|
-
|
115
|
-
@jndi_context.close
|
116
|
-
|
117
|
-
@started = false
|
118
|
-
end
|
119
|
-
|
120
|
-
def queue_connection_factory_enabled?
|
121
|
-
@jndi_name_of_enabled_connection_factories.include?(:queue_connection_factory)
|
122
|
-
end
|
123
|
-
|
124
|
-
def queue_connection_factory
|
125
|
-
@connection_factories[:queue_connection_factory]
|
126
|
-
end
|
127
|
-
|
128
|
-
def topic_connection_factory_enabled?
|
129
|
-
@jndi_name_of_enabled_connection_factories.include?(:topic_connection_factory)
|
130
|
-
end
|
131
|
-
|
132
|
-
def topic_connection_factory
|
133
|
-
@connection_factories[:topic_connection_factory]
|
134
|
-
end
|
135
|
-
|
136
|
-
def enable_queues(jndi_names = {})
|
137
|
-
raise InvalidClientStateError.new('started', 'enable_queues') if is_started?
|
138
|
-
|
139
|
-
@jndi_name_of_enabled_queues = jndi_names
|
140
|
-
end
|
141
|
-
|
142
|
-
def queue_enabled?(queue_name)
|
143
|
-
@jndi_name_of_enabled_queues.include?(queue_name)
|
144
|
-
end
|
145
|
-
|
146
|
-
def queue(queue_name)
|
147
|
-
raise NameError, "Queue '#{queue_name}' does not exist." unless queue_enabled?(queue_name)
|
148
|
-
|
149
|
-
@queues[queue_name]
|
150
|
-
end
|
151
|
-
|
152
|
-
def queue_sender(queue_name)
|
153
|
-
@queue_senders[queue_name] ||=
|
154
|
-
Messaging::Sender.new(queue_connection_factory, queue(queue_name))
|
155
|
-
end
|
156
|
-
|
157
|
-
def queue_receiver(queue_name)
|
158
|
-
@queue_receivers[queue_name] ||=
|
159
|
-
Messaging::Receiver.new(queue_connection_factory, queue(queue_name))
|
160
|
-
end
|
161
|
-
|
162
|
-
def enable_topics(jndi_names = {})
|
163
|
-
raise InvalidClientStateError.new('started', 'enable_topics') if is_started?
|
164
|
-
|
165
|
-
@jndi_name_of_enabled_topics = jndi_names
|
166
|
-
end
|
167
|
-
|
168
|
-
def topic_enabled?(topic_name)
|
169
|
-
@jndi_name_of_enabled_topics.include?(topic_name)
|
170
|
-
end
|
171
|
-
|
172
|
-
def topic(topic_name)
|
173
|
-
raise NameError, "Topic '#{topic_name}' does not exist." unless topic_enabled?(topic_name)
|
174
|
-
|
175
|
-
@topics[topic_name]
|
176
|
-
end
|
177
|
-
|
178
|
-
def topic_sender(topic_name)
|
179
|
-
@topic_senders[topic_name] ||=
|
180
|
-
Messaging::Sender.new(topic_connection_factory, topic(topic_name))
|
181
|
-
end
|
182
|
-
|
183
|
-
def topic_receiver(topic_name)
|
184
|
-
@topic_receivers[topic_name] ||=
|
185
|
-
Messaging::Receiver.new(topic_connection_factory, topic(topic_name))
|
186
|
-
end
|
187
|
-
|
188
|
-
# -- Private methods -- #
|
189
|
-
private
|
190
|
-
|
191
|
-
def lookup_resource(jndi_names = {})
|
192
|
-
lookuped = {}
|
193
|
-
|
194
|
-
jndi_names.each do |key, jndi_name|
|
195
|
-
lookuped[key] = @jndi_context.lookup(jndi_name)
|
196
|
-
end
|
197
|
-
|
198
|
-
lookuped
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
class ClientInitializationError < StandardError
|
203
|
-
attr_reader :properties, :cause
|
204
|
-
|
205
|
-
def initialize(properties, cause)
|
206
|
-
super("Could not open connection to server. Verify the properties's properties.")
|
207
|
-
|
208
|
-
@properties = properties
|
209
|
-
@cause = cause
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
class InvalidClientStateError < StandardError
|
214
|
-
attr_reader :state, :operation
|
215
|
-
|
216
|
-
def initialize(state, operation)
|
217
|
-
super("Could not did #{operation} because client is #{state}.")
|
218
|
-
|
219
|
-
@state = state
|
220
|
-
@operation = operation
|
221
|
-
end
|
222
|
-
end
|
223
63
|
end
|
224
64
|
|
225
65
|
module JNDI
|
226
66
|
|
227
67
|
#
|
228
|
-
# Builder para construcao de contexto JNDI para conexao com o
|
68
|
+
# Builder para construcao de contexto JNDI para conexao com o provedor
|
229
69
|
# de JMS.
|
230
70
|
#
|
231
71
|
class ContextBuilder
|
232
72
|
attr_accessor :jms_client_jar, :jndi_properties
|
233
73
|
|
234
74
|
def initialize(jms_client_jar, jndi_properties)
|
235
|
-
@jms_client_jar
|
236
|
-
@jndi_properties
|
75
|
+
@jms_client_jar = jms_client_jar
|
76
|
+
@jndi_properties = jndi_properties
|
237
77
|
end
|
238
78
|
|
239
79
|
#
|
data/lib/jsparrow.rb
CHANGED
data/sample/sample.rb
CHANGED
@@ -9,20 +9,19 @@ JSparrow::Connection.configure do |connection|
|
|
9
9
|
# :security_principal => 'user',
|
10
10
|
# :security_credentials => 'password'
|
11
11
|
|
12
|
-
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
|
13
|
-
|
12
|
+
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
|
13
|
+
|
14
|
+
connection.enable_queues :test_queue => 'TestQueue'
|
14
15
|
end
|
15
16
|
|
16
17
|
jms_client = JSparrow::Connection.new_client
|
17
|
-
jms_client.enable_queues :pardal_queue => 'PardalQueue'
|
18
|
-
|
19
18
|
jms_client.start
|
20
19
|
|
21
|
-
jms_client.queue_sender(:
|
20
|
+
jms_client.queue_sender(:test_queue).send_text_message('jsparrow rocks!') do |msg|
|
22
21
|
msg.set_string_property('recipient', 'jsparrow-example')
|
23
22
|
end
|
24
23
|
|
25
|
-
jms_client.queue_receiver(:
|
24
|
+
jms_client.queue_receiver(:test_queue).receive_message(
|
26
25
|
:timeout => 5000,
|
27
26
|
:selector => "recipient = 'jsparrow-example'"
|
28
27
|
) do |msg|
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.dirname(File.expand_path(__FILE__)) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Cenario que testa o start e stop do cliente JMS.
|
5
|
+
#
|
6
|
+
describe JSparrow::Connection::Client, ', quando criado,' do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
@jms_client = create_jms_client
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'deveria permitir ser iniciado e parado' do
|
13
|
+
@jms_client.start
|
14
|
+
|
15
|
+
@jms_client.is_started?.should be true
|
16
|
+
@jms_client.is_stoped?.should be false
|
17
|
+
|
18
|
+
@jms_client.stop
|
19
|
+
|
20
|
+
@jms_client.is_started?.should be false
|
21
|
+
@jms_client.is_stoped?.should be true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Cenario de configuracao do cliente JMS, quando sao informadas as propriedades de ambiente
|
27
|
+
# para conexao com o servidor de aplicacoes e a inicializacao do contexto JNDI inicial,
|
28
|
+
# onde estao criadas as connection factories, queues e topics.
|
29
|
+
#
|
30
|
+
# Importante: nesse momento o cliente JMS ainda nao sera iniciado, ja que nao deve haver
|
31
|
+
# configuracao depois inicia-lo.
|
32
|
+
#
|
33
|
+
describe JSparrow::Connection::Client, ', quando esta sendo configurado, mas ainda nao iniciado,' do
|
34
|
+
|
35
|
+
before(:all) do
|
36
|
+
@jms_client = create_jms_client
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'deveria ter uma connection factory especifica para queues' do
|
40
|
+
@jms_client.queue_connection_factory_enabled?.should be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'deveria ter uma connection factory especifica para topics' do
|
44
|
+
@jms_client.topic_connection_factory_enabled?.should be true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'deveria ter uma Queue especifica' do
|
48
|
+
@jms_client.queue_enabled?(:test_queue).should eql true
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'deveria ter um Topic especifico' do
|
52
|
+
@jms_client.topic_enabled?(:test_topic).should eql true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Cenario pos-configuracao do cliente JMS, quando as queues e os topicos ja devem estar
|
58
|
+
# disponiveis, e entao e possivel obter sender/receiver para elas.
|
59
|
+
#
|
60
|
+
describe JSparrow::Connection::Client, ', depois de ter sido configurado,' do
|
61
|
+
|
62
|
+
before(:all) do
|
63
|
+
@jms_client = create_jms_client
|
64
|
+
@jms_client.start
|
65
|
+
end
|
66
|
+
|
67
|
+
after(:all) do
|
68
|
+
@jms_client.stop
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'deveria possibilitar obter um Sender para uma Queue especifica' do
|
72
|
+
@jms_client.queue_sender(:test_queue).should_not be nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'deveria possibilitar obter um Receiver para uma Queue especifica' do
|
76
|
+
@jms_client.queue_receiver(:test_queue).should_not be nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'deveria possibilitar obter um Sender para um Topic especifico' do
|
80
|
+
@jms_client.topic_sender(:test_topic).should_not be nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'deveria possibilitar obter um Receiver para um Topic especifico' do
|
84
|
+
@jms_client.topic_receiver(:test_topic).should_not be nil
|
85
|
+
end
|
86
|
+
end
|
data/spec/connection_spec.rb
CHANGED
@@ -1,120 +1,31 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
#
|
4
|
-
# Cenario que testa
|
4
|
+
# Cenario que testa a configuracao a conexao com o provedor de JMS.
|
5
5
|
#
|
6
|
-
describe JSparrow::Connection
|
6
|
+
describe JSparrow::Connection, ', quando configurado,' do
|
7
7
|
|
8
8
|
before(:all) do
|
9
|
-
@
|
9
|
+
@config = configure_connection
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'deveria
|
13
|
-
@
|
14
|
-
|
15
|
-
@jms_client.is_started?.should be true
|
16
|
-
@jms_client.is_stoped?.should be false
|
17
|
-
|
18
|
-
@jms_client.stop
|
19
|
-
|
20
|
-
@jms_client.is_started?.should be false
|
21
|
-
@jms_client.is_stoped?.should be true
|
12
|
+
it 'deveria ter jms_client_jar' do
|
13
|
+
@config.jms_client_jar.should_not be nil
|
22
14
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Cenario de configuracao do cliente JMS, quando sao informadas as propriedades de ambiente
|
27
|
-
# para conexao com o servidor de aplicacoes e a inicializacao do contexto JNDI inicial,
|
28
|
-
# onde estao criadas as connection factories, queues e topics.
|
29
|
-
#
|
30
|
-
# Importante: nesse momento o cliente JMS ainda nao sera iniciado, ja que nao deve haver
|
31
|
-
# configuracao depois inicia-lo.
|
32
|
-
#
|
33
|
-
describe JSparrow::Connection::Client, ', quando esta sendo configurado, mas ainda nao iniciado,' do
|
34
15
|
|
35
|
-
|
36
|
-
@
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'deveria ter uma connection factory especifica para queues' do
|
40
|
-
@jms_client.queue_connection_factory_enabled?.should be true
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'deveria ter uma connection factory especifica para topics' do
|
44
|
-
@jms_client.topic_connection_factory_enabled?.should be true
|
16
|
+
it 'deveria ter jndi_properties' do
|
17
|
+
@config.jndi_properties.should_not be nil
|
45
18
|
end
|
46
|
-
|
47
|
-
it 'deveria permitir habilitar uma Queue especifica' do
|
48
|
-
@jms_client.enable_queues :pardal_queue => 'PardalQueue'
|
49
19
|
|
50
|
-
|
20
|
+
it 'deveria ter enabled_connection_factories' do
|
21
|
+
@config.enabled_connection_factories.should_not be nil
|
51
22
|
end
|
52
|
-
|
53
|
-
it 'deveria permitir habilitar um Topic especifico' do
|
54
|
-
@jms_client.enable_topics :pardal_topic => 'PardalTopic'
|
55
|
-
|
56
|
-
@jms_client.topic_enabled?(:pardal_topic).should eql true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Cenario de configuracao do cliente JMS apos ter sido iniciado.
|
62
|
-
#
|
63
|
-
# Importante: Como o cliente JMS ja esta iniciado, deve lancar erro, nao permitindo
|
64
|
-
# qualquer configuracao.
|
65
|
-
#
|
66
|
-
describe JSparrow::Connection::Client, ', quando esta sendo configurado, apos iniciado,' do
|
67
23
|
|
68
|
-
|
69
|
-
@
|
70
|
-
@jms_client.start
|
24
|
+
it 'deveria ter enabled_queues' do
|
25
|
+
@config.enabled_queues.should_not be nil
|
71
26
|
end
|
72
|
-
|
73
|
-
after(:all) do
|
74
|
-
@jms_client.stop
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'nao deveria permitir habilitar uma Queue especifica' do
|
78
|
-
lambda {
|
79
|
-
@jms_client.enable_queues(:pardal_queue => 'PardalQueue')
|
80
|
-
}.should raise_error JSparrow::Connection::InvalidClientStateError
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'nao deveria permitir habilitar um Topic especifico' do
|
84
|
-
lambda {
|
85
|
-
@jms_client.enable_topics(:pardal_topic => 'PardalTopic')
|
86
|
-
}.should raise_error JSparrow::Connection::InvalidClientStateError
|
87
|
-
end
|
88
|
-
end
|
89
27
|
|
90
|
-
|
91
|
-
|
92
|
-
# disponiveis, e entao e possivel obter sender/receiver para elas.
|
93
|
-
#
|
94
|
-
describe JSparrow::Connection::Client, ', depois de ter sido configurado,' do
|
95
|
-
|
96
|
-
before(:all) do
|
97
|
-
@jms_client = create_and_setup_jms_client
|
98
|
-
@jms_client.start
|
99
|
-
end
|
100
|
-
|
101
|
-
after(:all) do
|
102
|
-
@jms_client.stop
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'deveria possibilitar obter um Sender para uma Queue especifica' do
|
106
|
-
@jms_client.queue_sender(:pardal_queue).should_not be nil
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'deveria possibilitar obter um Receiver para uma Queue especifica' do
|
110
|
-
@jms_client.queue_receiver(:pardal_queue).should_not be nil
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'deveria possibilitar obter um Sender para um Topic especifico' do
|
114
|
-
@jms_client.topic_sender(:pardal_topic).should_not be nil
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'deveria possibilitar obter um Receiver para um Topic especifico' do
|
118
|
-
@jms_client.topic_receiver(:pardal_topic).should_not be nil
|
28
|
+
it 'deveria ter enabled_topics' do
|
29
|
+
@config.enabled_topics.should_not be nil
|
119
30
|
end
|
120
31
|
end
|
data/spec/messaging_spec.rb
CHANGED
@@ -8,11 +8,11 @@ require File.dirname(File.expand_path(__FILE__)) + '/spec_helper.rb'
|
|
8
8
|
describe JSparrow::Messaging, ', quando tem um Sender e um Receiver para uma Queue especifica,' do
|
9
9
|
|
10
10
|
before(:all) do
|
11
|
-
@jms_client =
|
11
|
+
@jms_client = create_jms_client
|
12
12
|
@jms_client.start
|
13
13
|
|
14
|
-
@sender = @jms_client.queue_sender(:
|
15
|
-
@receiver = @jms_client.queue_receiver(:
|
14
|
+
@sender = @jms_client.queue_sender(:test_queue)
|
15
|
+
@receiver = @jms_client.queue_receiver(:test_queue)
|
16
16
|
end
|
17
17
|
|
18
18
|
after(:all) do
|
data/spec/spec_helper.rb
CHANGED
@@ -17,32 +17,23 @@ module JSparrowHelperMethods
|
|
17
17
|
JSparrow::Connection.new_client
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
jms_client = JSparrow::Connection.new_client
|
24
|
-
jms_client.enable_queues :pardal_queue => 'PardalQueue'
|
25
|
-
jms_client.enable_topics :pardal_topic => 'PardalTopic'
|
26
|
-
|
27
|
-
jms_client
|
28
|
-
end
|
29
|
-
|
30
|
-
# --- Private methods --- #
|
31
|
-
private
|
32
|
-
|
33
|
-
def configure_connection
|
34
|
-
JSparrow::Connection.configure do |connection|
|
35
|
-
connection.use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar'
|
20
|
+
def configure_connection
|
21
|
+
JSparrow::Connection.configure do |connection|
|
22
|
+
connection.use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar'
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
24
|
+
connection.use_jndi_properties :initial_context_factory => 'org.exolab.jms.jndi.InitialContextFactory',
|
25
|
+
:provider_url => 'tcp://localhost:3035'
|
26
|
+
# :security_principal => 'user',
|
27
|
+
# :security_credentials => 'password'
|
28
|
+
|
29
|
+
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory',
|
30
|
+
:topic_connection_factory => 'ConnectionFactory'
|
31
|
+
|
32
|
+
connection.enable_queues :test_queue => 'TestQueue'
|
33
|
+
|
34
|
+
connection.enable_topics :test_topic => 'TestTopic'
|
45
35
|
end
|
36
|
+
end
|
46
37
|
end
|
47
38
|
|
48
39
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsparrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Silva
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- README.rdoc
|
28
28
|
- Rakefile
|
29
29
|
- VERSION.yml
|
30
|
+
- lib/client.rb
|
30
31
|
- lib/connection.rb
|
31
32
|
- lib/error.rb
|
32
33
|
- lib/jms.rb
|
@@ -36,6 +37,7 @@ files:
|
|
36
37
|
- lib/jsparrow.rb
|
37
38
|
- lib/messaging.rb
|
38
39
|
- sample/sample.rb
|
40
|
+
- spec/client_spec.rb
|
39
41
|
- spec/connection_spec.rb
|
40
42
|
- spec/messaging_spec.rb
|
41
43
|
- spec/spec_helper.rb
|
@@ -68,6 +70,7 @@ signing_key:
|
|
68
70
|
specification_version: 3
|
69
71
|
summary: JSparrow is a JMS client based on JRuby
|
70
72
|
test_files:
|
73
|
+
- spec/client_spec.rb
|
71
74
|
- spec/connection_spec.rb
|
72
75
|
- spec/messaging_spec.rb
|
73
76
|
- spec/spec_helper.rb
|