ruote-stomp 2.2.0.b → 2.2.0.c
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +1 -0
- data/CREDITS.txt +1 -0
- data/README.rdoc +8 -3
- data/lib/ruote-stomp/launchitem_listener.rb +0 -2
- data/lib/ruote-stomp/participant.rb +5 -18
- data/lib/ruote-stomp/receiver.rb +14 -24
- data/lib/ruote-stomp/version.rb +1 -3
- data/lib/ruote-stomp/workitem_listener.rb +0 -1
- data/lib/ruote-stomp.rb +29 -20
- data/ruote-stomp.gemspec +6 -9
- data/spec/launchitem_listener_spec.rb +29 -19
- data/spec/participant_spec.rb +3 -7
- data/spec/receiver_spec.rb +44 -60
- data/spec/ruote_stomp_spec.rb +0 -4
- data/spec/spec_helper.rb +16 -15
- data/spec/support/ruote_helpers.rb +0 -2
- data/spec/support/ruote_matchers.rb +0 -6
- data/spec/workitem_listener_spec.rb +3 -15
- metadata +39 -26
- data/spec/participant_spec_kit.rb +0 -192
- data/spec/receiver_spec_kit.rb +0 -126
- data/spec/workitem_listener_spec_kit.rb +0 -66
data/CHANGELOG.txt
CHANGED
data/CREDITS.txt
CHANGED
data/README.rdoc
CHANGED
@@ -17,7 +17,7 @@ http://ruote.rubyforge.org/part_implementations.html
|
|
17
17
|
* Flexible participant for sending workitems
|
18
18
|
* Flexible receiver for receiving replies
|
19
19
|
* Flexible launch item listener for launching processes over Stomp
|
20
|
-
* Fully evented (thanks to the
|
20
|
+
* Fully evented (thanks to the onstomp gem)
|
21
21
|
|
22
22
|
== SYNOPSIS:
|
23
23
|
|
@@ -26,7 +26,7 @@ Please review the code for information (rdocs to be updated soon.)
|
|
26
26
|
== REQUIREMENTS:
|
27
27
|
|
28
28
|
* ruote[http://ruote.rubyforge.org] 2.2.0 or later
|
29
|
-
*
|
29
|
+
* onstomp[https://github.com/meadvillerb/onstomp] 1.0.4 or later
|
30
30
|
* a server that supports Stomp (stompserver, ActiveMQ, RabbitMQ)
|
31
31
|
|
32
32
|
== INSTALL:
|
@@ -60,8 +60,13 @@ ruote-amqp, which this works is based on)
|
|
60
60
|
Permission is hereby granted, free of charge, to any person obtaining
|
61
61
|
a copy of this software and associated documentation files (the
|
62
62
|
'Software'), to deal in the Software without restriction, including
|
63
|
-
|
63
|
+
<<<<<<< Updated upstream
|
64
|
+
without limitation the rights to use, copy, modify, merge, send,
|
64
65
|
distribute, sublicense, and/or sell copies of the Software, and to
|
66
|
+
=======
|
67
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
68
|
+
distribute, sublicense, and/or sell copies of tshe Software, and to
|
69
|
+
>>>>>>> Stashed changes
|
65
70
|
permit persons to whom the Software is furnished to do so, subject to
|
66
71
|
the following conditions:
|
67
72
|
|
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
1
|
require 'ruote/part/local_participant'
|
3
2
|
require 'ruote-stomp'
|
4
3
|
|
5
|
-
|
6
4
|
module RuoteStomp
|
7
|
-
|
8
5
|
#
|
9
6
|
# = Stomp Participants
|
10
7
|
#
|
@@ -122,12 +119,12 @@ module RuoteStomp
|
|
122
119
|
}.merge(options.inject({}) { |h, (k, v)|
|
123
120
|
h[k.to_s] = v; h
|
124
121
|
})
|
125
|
-
|
126
|
-
|
122
|
+
#
|
123
|
+
# the inject is here to make sure that all options have String keys
|
127
124
|
end
|
128
125
|
|
129
126
|
# Process the workitem at hand. By default the workitem will be
|
130
|
-
#
|
127
|
+
# sended to the direct exchange specified in the +queue+
|
131
128
|
# workitem parameter. You can specify a +message+ workitem
|
132
129
|
# parameter to have that sent instead of the workitem.
|
133
130
|
#
|
@@ -138,7 +135,6 @@ module RuoteStomp
|
|
138
135
|
|
139
136
|
raise 'no queue specified (outbound delivery)' unless target_queue
|
140
137
|
|
141
|
-
#q = MQ.queue(target_queue, :durable => true)
|
142
138
|
forget = determine_forget(workitem)
|
143
139
|
|
144
140
|
opts = {
|
@@ -148,12 +144,9 @@ module RuoteStomp
|
|
148
144
|
if message = workitem.fields['message'] || workitem.params['message']
|
149
145
|
|
150
146
|
forget = true # sending a message implies 'forget' => true
|
151
|
-
$stomp.
|
152
|
-
#q.publish(message, opts)
|
153
|
-
|
147
|
+
$stomp.send target_queue, message, opts
|
154
148
|
else
|
155
|
-
$stomp.
|
156
|
-
#q.publish(encode_workitem(workitem), opts)
|
149
|
+
$stomp.send target_queue, encode_workitem(workitem), opts
|
157
150
|
end
|
158
151
|
|
159
152
|
reply_to_engine(workitem) if forget
|
@@ -162,7 +155,6 @@ module RuoteStomp
|
|
162
155
|
# (Stops the underlying queue subscription)
|
163
156
|
#
|
164
157
|
def stop
|
165
|
-
|
166
158
|
RuoteStomp.stop!
|
167
159
|
end
|
168
160
|
|
@@ -176,21 +168,18 @@ module RuoteStomp
|
|
176
168
|
# [NOT sure about this behavior with Stomp yet. Need to dive.]
|
177
169
|
|
178
170
|
def do_not_thread
|
179
|
-
|
180
171
|
true
|
181
172
|
end
|
182
173
|
|
183
174
|
private
|
184
175
|
|
185
176
|
def determine_forget(workitem)
|
186
|
-
|
187
177
|
return workitem.params['forget'] if workitem.params.has_key?('forget')
|
188
178
|
return @options['forget'] if @options.has_key?('forget')
|
189
179
|
false
|
190
180
|
end
|
191
181
|
|
192
182
|
def determine_queue(workitem)
|
193
|
-
|
194
183
|
workitem.params['queue'] || @options['queue']
|
195
184
|
end
|
196
185
|
|
@@ -199,9 +188,7 @@ module RuoteStomp
|
|
199
188
|
# this participant.
|
200
189
|
#
|
201
190
|
def encode_workitem(wi)
|
202
|
-
|
203
191
|
wi.params['participant_options'] = @options
|
204
|
-
|
205
192
|
Rufus::Json.encode(wi.to_h)
|
206
193
|
end
|
207
194
|
end
|
data/lib/ruote-stomp/receiver.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
1
|
require 'ruote-stomp'
|
3
2
|
|
4
|
-
|
5
3
|
module RuoteStomp
|
6
4
|
|
7
5
|
#
|
@@ -56,6 +54,9 @@ module RuoteStomp
|
|
56
54
|
# :queue for setting the queue on which to listen (defaults to
|
57
55
|
# 'ruote_workitems').
|
58
56
|
#
|
57
|
+
# :ignore_disconnect_on_process => true|false (defauts to false)
|
58
|
+
# processes the message even if the client has disconnected (use in testing only)
|
59
|
+
#
|
59
60
|
# The :launchitems option :
|
60
61
|
#
|
61
62
|
# :launchitems => true
|
@@ -70,6 +71,7 @@ module RuoteStomp
|
|
70
71
|
super(engine_or_storage)
|
71
72
|
|
72
73
|
@launchitems = opts[:launchitems]
|
74
|
+
ignore_disconnect = opts[:ignore_disconnect_on_process]
|
73
75
|
|
74
76
|
@queue =
|
75
77
|
opts[:queue] ||
|
@@ -78,40 +80,31 @@ module RuoteStomp
|
|
78
80
|
RuoteStomp.start!
|
79
81
|
|
80
82
|
if opts[:unsubscribe]
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
begin
|
84
|
+
$stomp.unsubscribe(@queue)
|
85
|
+
rescue OnStomp::UnsupportedCommandError => e
|
86
|
+
$stderr.puts("Connection does support unsubscribe")
|
87
|
+
end
|
84
88
|
end
|
85
|
-
|
86
|
-
$stomp.subscribe(@queue
|
89
|
+
|
90
|
+
$stomp.subscribe(@queue) do |message|
|
87
91
|
# Process your message here
|
88
92
|
# Your submitted data is in msg.body
|
89
|
-
if $stomp.
|
93
|
+
if $stomp.connected? && !ignore_disconnect
|
90
94
|
# do nothing, we're going down
|
91
95
|
else
|
92
96
|
handle(message)
|
93
97
|
end
|
94
98
|
end
|
95
|
-
#$stomp.join # Wait until listening thread dies
|
96
|
-
|
97
|
-
# MQ.queue(@queue, :durable => true).subscribe do |message|
|
98
|
-
# if AMQP.closing?
|
99
|
-
# # do nothing, we're going down
|
100
|
-
# else
|
101
|
-
# handle(message)
|
102
|
-
# end
|
103
|
-
# end
|
104
99
|
end
|
105
|
-
|
100
|
+
|
106
101
|
def stop
|
107
|
-
|
108
102
|
RuoteStomp.stop!
|
109
103
|
end
|
110
104
|
|
111
105
|
# (feel free to overwrite me)
|
112
106
|
#
|
113
107
|
def decode_workitem(msg)
|
114
|
-
|
115
108
|
(Rufus::Json.decode(msg) rescue nil)
|
116
109
|
end
|
117
110
|
|
@@ -120,9 +113,7 @@ module RuoteStomp
|
|
120
113
|
def handle(msg)
|
121
114
|
item = decode_workitem(msg.body)
|
122
115
|
return unless item.is_a?(Hash)
|
123
|
-
|
124
116
|
not_li = ! item.has_key?('definition')
|
125
|
-
|
126
117
|
return if @launchitems == :only && not_li
|
127
118
|
return unless @launchitems || not_li
|
128
119
|
|
@@ -152,5 +143,4 @@ module RuoteStomp
|
|
152
143
|
super(hash['definition'], hash['fields'] || {}, hash['variables'] || {})
|
153
144
|
end
|
154
145
|
end
|
155
|
-
end
|
156
|
-
|
146
|
+
end
|
data/lib/ruote-stomp/version.rb
CHANGED
data/lib/ruote-stomp.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'onstomp'
|
2
2
|
|
3
3
|
require 'ruote-stomp/version'
|
4
4
|
|
5
|
-
|
6
5
|
#
|
7
6
|
# Stomp participant and listener pair for ruote.
|
8
7
|
#
|
@@ -21,7 +20,6 @@ require 'ruote-stomp/version'
|
|
21
20
|
module RuoteStomp
|
22
21
|
|
23
22
|
autoload 'ParticipantProxy', 'ruote-stomp/participant'
|
24
|
-
|
25
23
|
autoload 'Receiver', 'ruote-stomp/receiver'
|
26
24
|
autoload 'WorkitemListener', 'ruote-stomp/workitem_listener'
|
27
25
|
autoload 'LaunchitemListener', 'ruote-stomp/launchitem_listener'
|
@@ -39,34 +37,26 @@ module RuoteStomp
|
|
39
37
|
# Ensure the Stomp connection is started
|
40
38
|
def start!
|
41
39
|
return if started?
|
42
|
-
|
43
40
|
mutex = Mutex.new
|
44
41
|
cv = ConditionVariable.new
|
45
|
-
|
46
42
|
Thread.main[:ruote_stomp_connection] = Thread.new do
|
47
43
|
Thread.abort_on_exception = true
|
48
|
-
|
44
|
+
|
49
45
|
begin
|
50
|
-
$stomp =
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
STOMP.settings[:reliable]
|
55
|
-
if $stomp
|
56
|
-
|
46
|
+
$stomp = OnStomp::Client.new create_connection_uri(STOMP.settings)
|
47
|
+
$stomp.connect
|
48
|
+
|
49
|
+
if $stomp && $stomp.connected?
|
57
50
|
started!
|
58
51
|
cv.signal
|
59
52
|
end
|
60
|
-
rescue
|
61
|
-
raise RuntimeError, "Failed to connect to Stomp server."
|
53
|
+
rescue Exception => e
|
54
|
+
raise RuntimeError, "Failed to connect to Stomp server. (#{e.message})"
|
62
55
|
end
|
63
56
|
end
|
64
57
|
|
65
58
|
mutex.synchronize { cv.wait(mutex) }
|
66
59
|
|
67
|
-
# Stomp equivalent?
|
68
|
-
#MQ.prefetch(1)
|
69
|
-
|
70
60
|
yield if block_given?
|
71
61
|
end
|
72
62
|
|
@@ -82,16 +72,35 @@ module RuoteStomp
|
|
82
72
|
# Close down the Stomp connections
|
83
73
|
def stop!
|
84
74
|
return unless started?
|
85
|
-
$stomp.
|
75
|
+
$stomp.disconnect
|
86
76
|
Thread.main[:ruote_stomp_connection].join
|
87
77
|
Thread.main[:ruote_stomp_started] = false
|
88
78
|
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def create_connection_uri(config={})
|
83
|
+
config = config.map { |n,v| {n,v.to_s} }.reduce(:merge)
|
84
|
+
user = config[:user]
|
85
|
+
passcode = config[:passcode]
|
86
|
+
host = config[:host]
|
87
|
+
port = config[:port]
|
88
|
+
ssl = config[:ssl] ? "+ssl" : ""
|
89
|
+
|
90
|
+
# construct the connection URI
|
91
|
+
user_and_password = [user,passcode].reject{|e| e.nil? || e.empty?}.join(":")
|
92
|
+
host_and_port = [host,port].reject{|e| e.nil? || e.empty?}.join(":")
|
93
|
+
uri = [host_and_port, user_and_password].reject{|e| e.nil? || e.empty?}.reverse.join("@")
|
94
|
+
protocol = ['stomp', ssl, '://'].reject{|e| e.nil? || e.empty?}.join
|
95
|
+
|
96
|
+
"#{protocol}#{uri}"
|
97
|
+
end
|
89
98
|
end
|
90
99
|
end
|
91
100
|
|
92
101
|
module STOMP
|
93
102
|
def self.settings
|
94
|
-
@settings ||= {:host => "localhost", :port => "61613"
|
103
|
+
@settings ||= {:host => "localhost", :port => "61613"}
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
data/ruote-stomp.gemspec
CHANGED
@@ -5,26 +5,23 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'ruote-stomp'
|
6
6
|
s.version = File.read('lib/ruote-stomp/version.rb').match(/VERSION = '([^']+)'/)[1]
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = [ 'Kit Plummer' ]
|
9
|
-
s.email = [ 'kplummer@maestrodev.com' ]
|
8
|
+
s.authors = [ 'Kit Plummer', 'Brian Sam-Bodden' ]
|
9
|
+
s.email = [ 'kplummer@maestrodev.com', 'bsbodden@integrallis.com' ]
|
10
10
|
s.homepage = 'http://ruote.rubyforge.org'
|
11
11
|
s.rubyforge_project = 'ruote'
|
12
12
|
s.summary = 'Stomp participant/listener pair for ruote 2.2'
|
13
|
-
s.description =
|
14
|
-
Stomp participant/listener pair for ruote 2.2 - ported from ruote-amqp.
|
15
|
-
}
|
13
|
+
s.description = 'Stomp participant/listener pair for ruote 2.2'
|
16
14
|
|
17
|
-
#s.files = `git ls-files`.split("\n")
|
18
15
|
s.files = Dir[
|
19
16
|
'Rakefile',
|
20
17
|
'lib/**/*.rb', 'spec/**/*.rb', 'test/**/*.rb',
|
21
18
|
'*.gemspec', '*.txt', '*.rdoc', '*.md'
|
22
19
|
]
|
23
20
|
|
24
|
-
|
25
|
-
s.add_runtime_dependency '
|
26
|
-
s.add_runtime_dependency 'ruote', ">= #{s.version}"
|
21
|
+
s.add_runtime_dependency 'onstomp', "~> 1.0.4"
|
22
|
+
s.add_runtime_dependency 'ruote', "~> 2.2.0"
|
27
23
|
s.add_runtime_dependency 'json'
|
24
|
+
s.add_runtime_dependency 'parslet'
|
28
25
|
s.add_development_dependency 'rake'
|
29
26
|
s.add_development_dependency 'rspec', ">= 2.6.0"
|
30
27
|
s.add_development_dependency 'stompserver', '~> 0.9.9'
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
2
|
|
4
3
|
describe RuoteStomp::LaunchitemListener do
|
@@ -20,48 +19,59 @@ describe RuoteStomp::LaunchitemListener do
|
|
20
19
|
'fields' => { 'foo' => 'bar' }
|
21
20
|
}.to_json
|
22
21
|
|
23
|
-
RuoteStomp::LaunchitemListener.new(@engine)
|
22
|
+
RuoteStomp::LaunchitemListener.new(@engine, :ignore_disconnect_on_process => true)
|
24
23
|
|
25
|
-
|
26
|
-
#MQ.queue('ruote_launchitems', :durable => true).publish(json)
|
24
|
+
finished_processing = false
|
27
25
|
|
28
|
-
|
26
|
+
$stomp.send('/queue/ruote_launchitems', json) do |r|
|
27
|
+
finished_processing = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
Timeout::timeout(10) do
|
32
|
+
while @tracer.to_s.empty?
|
33
|
+
print "*"
|
34
|
+
sleep 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue Timeout::Error
|
38
|
+
fail "Timeout waiting for message"
|
39
|
+
end
|
40
|
+
|
41
|
+
Thread.pass until finished_processing
|
29
42
|
|
30
43
|
@engine.should_not have_errors
|
31
44
|
@engine.should_not have_remaining_expressions
|
32
|
-
|
33
45
|
@tracer.to_s.should == 'bar'
|
34
46
|
end
|
35
47
|
|
36
48
|
it 'discards corrupt process definitions' do
|
37
|
-
|
49
|
+
|
38
50
|
json = {
|
39
51
|
'definition' => %{
|
40
52
|
I'm a broken process definition
|
41
53
|
},
|
42
54
|
'fields' => { 'foo' => 'bar' }
|
43
55
|
}.to_json
|
44
|
-
|
45
|
-
RuoteStomp::LaunchitemListener.new(@engine, :unsubscribe => true)
|
46
|
-
|
56
|
+
|
57
|
+
RuoteStomp::LaunchitemListener.new(@engine, {:unsubscribe => true, :ignore_disconnect_on_process => true})
|
58
|
+
|
47
59
|
serr = String.new
|
48
60
|
err = StringIO.new(serr, 'w+')
|
49
61
|
$stderr = err
|
50
|
-
|
51
|
-
$stomp.
|
52
|
-
|
53
|
-
#MQ.queue('ruote_launchitems', :durable => true).publish(json)
|
54
|
-
|
62
|
+
|
63
|
+
$stomp.send '/queue/ruote_launchitems', json
|
64
|
+
|
55
65
|
sleep 0.5
|
56
|
-
|
66
|
+
|
57
67
|
err.close
|
58
68
|
$stderr = STDERR
|
59
|
-
|
69
|
+
|
60
70
|
@engine.should_not have_errors
|
61
71
|
@engine.should_not have_remaining_expressions
|
62
|
-
|
72
|
+
|
63
73
|
@tracer.to_s.should == ''
|
64
|
-
|
74
|
+
|
65
75
|
serr.should match(/^===/)
|
66
76
|
end
|
67
77
|
end
|
data/spec/participant_spec.rb
CHANGED
@@ -26,9 +26,7 @@ describe RuoteStomp::ParticipantProxy, :type => :ruote do
|
|
26
26
|
begin
|
27
27
|
Timeout::timeout(10) do
|
28
28
|
@msg = nil
|
29
|
-
#MQ.queue('test1', :durable => true).subscribe { |msg| @msg = msg }
|
30
29
|
$stomp.subscribe("/queue/test1") do |message|
|
31
|
-
|
32
30
|
@msg = message.body
|
33
31
|
end
|
34
32
|
|
@@ -97,8 +95,7 @@ describe RuoteStomp::ParticipantProxy, :type => :ruote do
|
|
97
95
|
begin
|
98
96
|
Timeout::timeout(5) do
|
99
97
|
@msg = nil
|
100
|
-
|
101
|
-
$stomp.subscribe("/queue/test2", {}) do |message|
|
98
|
+
$stomp.subscribe("/queue/test2") do |message|
|
102
99
|
@msg = message.body
|
103
100
|
end
|
104
101
|
loop do
|
@@ -132,8 +129,7 @@ describe RuoteStomp::ParticipantProxy, :type => :ruote do
|
|
132
129
|
begin
|
133
130
|
Timeout::timeout(5) do
|
134
131
|
@msg = nil
|
135
|
-
|
136
|
-
$stomp.subscribe("/queue/test5", {}) do |message|
|
132
|
+
$stomp.subscribe("/queue/test5") do |message|
|
137
133
|
@msg = message.body
|
138
134
|
end
|
139
135
|
loop do
|
@@ -162,7 +158,7 @@ describe RuoteStomp::ParticipantProxy, :type => :ruote do
|
|
162
158
|
Timeout::timeout(10) do
|
163
159
|
|
164
160
|
#MQ.queue('test6', :durable => true).subscribe { |m| msg = m }
|
165
|
-
$stomp.subscribe("/queue/stomp"
|
161
|
+
$stomp.subscribe("/queue/stomp") do |message|
|
166
162
|
msg = message.body
|
167
163
|
end
|
168
164
|
loop do
|
data/spec/receiver_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
2
|
|
4
3
|
require 'ruote/participant'
|
5
4
|
|
6
|
-
|
7
5
|
describe RuoteStomp::Receiver do
|
8
6
|
|
9
7
|
after(:each) do
|
@@ -11,7 +9,6 @@ describe RuoteStomp::Receiver do
|
|
11
9
|
end
|
12
10
|
|
13
11
|
it "handles replies" do
|
14
|
-
|
15
12
|
pdef = Ruote.process_definition :name => 'test' do
|
16
13
|
set :field => 'foo', :value => 'foo'
|
17
14
|
sequence do
|
@@ -20,28 +17,23 @@ describe RuoteStomp::Receiver do
|
|
20
17
|
echo '${f:foo}'
|
21
18
|
end
|
22
19
|
end
|
23
|
-
|
20
|
+
|
24
21
|
@engine.register_participant(:stomp, RuoteStomp::ParticipantProxy)
|
25
|
-
|
26
|
-
RuoteStomp::Receiver.new(@engine)
|
27
|
-
|
22
|
+
|
23
|
+
receiver = RuoteStomp::Receiver.new(@engine, :ignore_disconnect_on_process => true)
|
24
|
+
|
28
25
|
wfid = @engine.launch(pdef)
|
29
|
-
|
26
|
+
|
30
27
|
workitem = nil
|
31
|
-
|
28
|
+
|
32
29
|
begin
|
33
30
|
Timeout::timeout(5) do
|
34
|
-
|
35
|
-
|
36
|
-
# wi = Ruote::Workitem.new(Rufus::Json.decode(msg))
|
37
|
-
# workitem = wi if wi.wfid == wfid
|
38
|
-
# }
|
39
|
-
|
40
|
-
$stomp.subscribe("/queue/test3", {}) do |message|
|
31
|
+
|
32
|
+
$stomp.subscribe("/queue/test3") do |message|
|
41
33
|
wi = Ruote::Workitem.new(Rufus::Json.decode(message.body))
|
42
34
|
workitem = wi if wi.wfid == wfid
|
43
35
|
end
|
44
|
-
|
36
|
+
|
45
37
|
loop do
|
46
38
|
break unless workitem.nil?
|
47
39
|
sleep 0.1
|
@@ -50,19 +42,18 @@ describe RuoteStomp::Receiver do
|
|
50
42
|
rescue Timeout::Error
|
51
43
|
fail "Timeout waiting for message"
|
52
44
|
end
|
53
|
-
|
45
|
+
|
54
46
|
workitem.fields['foo'] = "bar"
|
47
|
+
|
48
|
+
$stomp.send '/queue/ruote_workitems', Rufus::Json.encode(workitem.to_h)
|
55
49
|
|
56
|
-
#MQ.queue('ruote_workitems', :durable => true).publish(Rufus::Json.encode(workitem.to_h), :persistent => true)
|
57
|
-
$stomp.publish '/queue/ruote_workitems',
|
58
|
-
Rufus::Json.encode(workitem.to_h),
|
59
|
-
{ :persistent => true }
|
60
50
|
@engine.wait_for(wfid)
|
61
|
-
|
51
|
+
|
62
52
|
@engine.should_not have_errors
|
63
53
|
@engine.should_not have_remaining_expressions
|
64
|
-
|
54
|
+
|
65
55
|
@tracer.to_s.should == "foo\nbar"
|
56
|
+
receiver.stop
|
66
57
|
end
|
67
58
|
|
68
59
|
it "launches processes" do
|
@@ -77,64 +68,57 @@ describe RuoteStomp::Receiver do
|
|
77
68
|
},
|
78
69
|
'fields' => { 'foo' => 'bar' }
|
79
70
|
}.to_json
|
71
|
+
|
72
|
+
receiver = RuoteStomp::Receiver.new(@engine, {:launchitems => true, :unsubscribe => true, :ignore_disconnect_on_process => true})
|
80
73
|
|
81
|
-
|
74
|
+
finished_processing = false
|
82
75
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
# json, :persistent => true
|
87
|
-
# )
|
76
|
+
$stomp.send('/queue/ruote_workitems', json) do |r|
|
77
|
+
finished_processing = true
|
78
|
+
end
|
88
79
|
|
89
|
-
|
80
|
+
begin
|
81
|
+
Timeout::timeout(20) do
|
82
|
+
while @tracer.to_s.empty?
|
83
|
+
print "*"
|
84
|
+
sleep 1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
rescue Timeout::Error
|
88
|
+
fail "Timeout waiting for message"
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
sleep 0.5
|
91
|
+
Thread.pass until finished_processing
|
93
92
|
|
94
93
|
@engine.should_not have_errors
|
95
94
|
@engine.should_not have_remaining_expressions
|
96
95
|
|
97
96
|
@tracer.to_s.should == 'bar'
|
97
|
+
receiver.stop
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'accepts a custom :queue' do
|
101
|
-
|
101
|
+
|
102
102
|
RuoteStomp::Receiver.new(
|
103
|
-
@engine, :queue => '/queue/mario', :launchitems => true, :unsubscribe => true)
|
104
|
-
|
103
|
+
@engine, :queue => '/queue/mario', :launchitems => true, :unsubscribe => true, :ignore_disconnect_on_process => true)
|
104
|
+
|
105
105
|
@engine.register_participant 'alpha', Ruote::StorageParticipant
|
106
|
-
|
106
|
+
|
107
107
|
json = Rufus::Json.encode({
|
108
108
|
'definition' => "Ruote.define { alpha }"
|
109
109
|
})
|
110
|
-
|
111
|
-
# MQ.queue(
|
112
|
-
# 'ruote_workitems', :durable => true
|
113
|
-
# ).publish(
|
114
|
-
# json, :persistent => true
|
115
|
-
# )
|
116
110
|
|
117
|
-
$stomp.
|
118
|
-
|
119
|
-
{ :persistent => true }
|
120
|
-
|
111
|
+
$stomp.send '/queue/ruote_workitems', json
|
112
|
+
|
121
113
|
sleep 1
|
122
|
-
|
114
|
+
|
123
115
|
@engine.processes.size.should == 0
|
124
116
|
# nothing happened
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# ).publish(
|
129
|
-
# json, :persistent => true
|
130
|
-
# )
|
131
|
-
|
132
|
-
$stomp.publish '/queue/mario',
|
133
|
-
json,
|
134
|
-
{ :persistent => true }
|
135
|
-
|
117
|
+
|
118
|
+
$stomp.send '/queue/mario', json
|
119
|
+
|
136
120
|
sleep 1
|
137
|
-
|
121
|
+
|
138
122
|
@engine.processes.size.should == 1
|
139
123
|
# launch happened
|
140
124
|
end
|