ruote-amqp 0.9.21.1 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/History.txt +7 -0
- data/Manifest.txt +4 -2
- data/README.rdoc +28 -22
- data/Rakefile +45 -21
- data/lib/ruote-amqp.rb +46 -20
- data/lib/ruote-amqp/launchitem_listener.rb +88 -0
- data/lib/ruote-amqp/participant.rb +14 -24
- data/lib/ruote-amqp/workitem_listener.rb +84 -0
- data/lib/spec/ruote.rb +1 -1
- data/lib/spec/ruote_example_group.rb +1 -1
- data/lib/spec/ruote_helpers.rb +12 -9
- data/lib/spec/ruote_matchers.rb +15 -25
- data/ruote-amqp.gemspec +83 -0
- data/spec/launchitem_listener_spec.rb +32 -0
- data/spec/participant_spec.rb +9 -21
- data/spec/spec_helper.rb +33 -41
- data/spec/{listener_spec.rb → workitem_listener_spec.rb} +12 -13
- metadata +40 -29
- data/lib/ruote-amqp/listener.rb +0 -92
- data/tasks/rspec.rake +0 -21
@@ -1,29 +1,27 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe RuoteAMQP::
|
3
|
+
describe RuoteAMQP::WorkitemListener do
|
4
|
+
|
4
5
|
it "should handle replies" do
|
5
|
-
pdef = <<-EOF
|
6
|
-
class AmqpParticipant2 < OpenWFE::ProcessDefinition
|
7
6
|
|
7
|
+
pdef = Ruote.process_definition :name => 'test' do
|
8
8
|
set :field => 'foo', :value => 'foo'
|
9
|
-
|
10
9
|
sequence do
|
11
10
|
echo '${f:foo}'
|
12
11
|
amqp :queue => 'test3'
|
13
12
|
echo '${f:foo}'
|
14
13
|
end
|
15
14
|
end
|
16
|
-
EOF
|
17
15
|
|
18
16
|
@engine.register_participant( :amqp, RuoteAMQP::Participant )
|
19
17
|
|
20
|
-
|
18
|
+
RuoteAMQP::WorkitemListener.new( @engine )
|
21
19
|
|
22
20
|
fei = @engine.launch pdef
|
23
21
|
|
24
22
|
begin
|
25
|
-
Timeout::timeout(
|
26
|
-
msg = nil
|
23
|
+
Timeout::timeout(5) do
|
24
|
+
@msg = nil
|
27
25
|
MQ.queue('test3').subscribe { |msg| @msg = msg }
|
28
26
|
|
29
27
|
loop do
|
@@ -35,14 +33,14 @@ describe RuoteAMQP::Listener do
|
|
35
33
|
violated "Timeout waiting for message"
|
36
34
|
end
|
37
35
|
|
38
|
-
wi =
|
39
|
-
wi.
|
36
|
+
wi = Ruote::Workitem.new( Rufus::Json.decode( @msg ) )
|
37
|
+
wi.fields['foo'] = "bar"
|
40
38
|
|
41
|
-
MQ.queue( wi.
|
39
|
+
MQ.queue( wi.fields['params']['reply_queue'] ).publish( Rufus::Json.encode( wi.to_h ) )
|
42
40
|
|
43
|
-
|
41
|
+
@engine.context.logger.wait_for( fei )
|
44
42
|
|
45
|
-
@engine.should_not have_errors
|
43
|
+
@engine.should_not have_errors
|
46
44
|
@engine.should_not have_remaining_expressions
|
47
45
|
|
48
46
|
@tracer.to_s.should == "foo\nbar"
|
@@ -50,3 +48,4 @@ describe RuoteAMQP::Listener do
|
|
50
48
|
purge_engine
|
51
49
|
end
|
52
50
|
end
|
51
|
+
|
metadata
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruote-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- kenneth.kalmer@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-04 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: rufus-json
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.1.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: amqp
|
@@ -28,28 +28,32 @@ dependencies:
|
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.6
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruote
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
43
|
+
version: 2.1.5
|
34
44
|
version:
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
46
|
+
name: rspec
|
37
47
|
type: :development
|
38
48
|
version_requirement:
|
39
49
|
version_requirements: !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
53
|
+
version: "0"
|
44
54
|
version:
|
45
|
-
description:
|
46
|
-
|
47
|
-
distribute workitems out to AMQP consumers for processing.
|
48
|
-
|
49
|
-
To learn more about remote participants in ruote please see
|
50
|
-
http://openwfe.rubyforge.org/part.html
|
51
|
-
email:
|
52
|
-
- kenneth.kalmer@gmail.com
|
55
|
+
description:
|
56
|
+
email: kenneth.kalmer@gmail.com
|
53
57
|
executables: []
|
54
58
|
|
55
59
|
extensions: []
|
@@ -58,8 +62,10 @@ extra_rdoc_files:
|
|
58
62
|
- History.txt
|
59
63
|
- Manifest.txt
|
60
64
|
- PostInstall.txt
|
65
|
+
- README.rdoc
|
61
66
|
- TODO.txt
|
62
67
|
files:
|
68
|
+
- .gitignore
|
63
69
|
- History.txt
|
64
70
|
- Manifest.txt
|
65
71
|
- PostInstall.txt
|
@@ -67,29 +73,30 @@ files:
|
|
67
73
|
- Rakefile
|
68
74
|
- TODO.txt
|
69
75
|
- lib/ruote-amqp.rb
|
70
|
-
- lib/ruote-amqp/
|
76
|
+
- lib/ruote-amqp/launchitem_listener.rb
|
71
77
|
- lib/ruote-amqp/participant.rb
|
78
|
+
- lib/ruote-amqp/workitem_listener.rb
|
72
79
|
- lib/spec/ruote.rb
|
73
80
|
- lib/spec/ruote_example_group.rb
|
74
81
|
- lib/spec/ruote_helpers.rb
|
75
82
|
- lib/spec/ruote_matchers.rb
|
83
|
+
- ruote-amqp.gemspec
|
76
84
|
- script/console
|
77
85
|
- script/destroy
|
78
86
|
- script/generate
|
79
|
-
- spec/
|
87
|
+
- spec/launchitem_listener_spec.rb
|
80
88
|
- spec/participant_spec.rb
|
81
89
|
- spec/ruote_amqp_spec.rb
|
82
90
|
- spec/spec.opts
|
83
91
|
- spec/spec_helper.rb
|
84
|
-
-
|
92
|
+
- spec/workitem_listener_spec.rb
|
85
93
|
has_rdoc: true
|
86
94
|
homepage: http://github.com/kennethkalmer/ruote-amqp
|
87
95
|
licenses: []
|
88
96
|
|
89
|
-
post_install_message:
|
97
|
+
post_install_message:
|
90
98
|
rdoc_options:
|
91
|
-
- --
|
92
|
-
- README.rdoc
|
99
|
+
- --charset=UTF-8
|
93
100
|
require_paths:
|
94
101
|
- lib
|
95
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -106,10 +113,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
113
|
version:
|
107
114
|
requirements: []
|
108
115
|
|
109
|
-
rubyforge_project:
|
110
|
-
rubygems_version: 1.3.
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.5
|
111
118
|
signing_key:
|
112
119
|
specification_version: 3
|
113
|
-
summary:
|
114
|
-
test_files:
|
115
|
-
|
120
|
+
summary: AMQP participant/listener pair for ruote 2.1
|
121
|
+
test_files:
|
122
|
+
- spec/launchitem_listener_spec.rb
|
123
|
+
- spec/participant_spec.rb
|
124
|
+
- spec/ruote_amqp_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spec/workitem_listener_spec.rb
|
data/lib/ruote-amqp/listener.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'openwfe/service'
|
2
|
-
require 'openwfe/listeners/listener'
|
3
|
-
|
4
|
-
module RuoteAMQP
|
5
|
-
|
6
|
-
#
|
7
|
-
# = AMQP Listeners
|
8
|
-
#
|
9
|
-
# Used in conjunction with the RuoteAMQP::Participant, the Listener
|
10
|
-
# subscribes to a specific direct exchange and monitors for
|
11
|
-
# incoming workitems. It expects workitems to arrive serialized as
|
12
|
-
# JSON.
|
13
|
-
#
|
14
|
-
# == Configuration
|
15
|
-
#
|
16
|
-
# AMQP configuration is handled by directly manipulating the values of
|
17
|
-
# the +AMQP.settings+ hash, as provided by the AMQP gem. No
|
18
|
-
# defaults are set by the participant. The only +option+ parsed by
|
19
|
-
# the initializer of the listener is the +queue+ key (Hash
|
20
|
-
# expected). If no +queue+ key is set, the listener will subscribe
|
21
|
-
# to the +ruote+ direct exchange for workitems, otherwise it will
|
22
|
-
# subscribe to the direct exchange provided.
|
23
|
-
#
|
24
|
-
# The participant requires version 0.6.1 or later of the amqp gem.
|
25
|
-
#
|
26
|
-
# == Usage
|
27
|
-
#
|
28
|
-
# Register the listener with the engine:
|
29
|
-
#
|
30
|
-
# engine.register_listener( RuoteAMQP::Listener )
|
31
|
-
#
|
32
|
-
# The listener leverages the asynchronous nature of the amqp gem,
|
33
|
-
# so no timers are setup when initialized.
|
34
|
-
#
|
35
|
-
# See the RuoteAMQP::Participant docs for information on sending
|
36
|
-
# workitems out to remote participants, and have them send replies
|
37
|
-
# to the correct direct exchange specified in the workitem
|
38
|
-
# attributes.
|
39
|
-
#
|
40
|
-
class Listener < OpenWFE::Service
|
41
|
-
include OpenWFE::WorkItemListener
|
42
|
-
|
43
|
-
class << self
|
44
|
-
|
45
|
-
# Listening queue
|
46
|
-
attr_writer :queue
|
47
|
-
|
48
|
-
def queue
|
49
|
-
@queue ||= 'ruote'
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# Only one option is used (:queue) to determine where to listen
|
55
|
-
# for work
|
56
|
-
def initialize( service_name, options )
|
57
|
-
|
58
|
-
if q = options.delete(:queue)
|
59
|
-
self.class.queue = q
|
60
|
-
end
|
61
|
-
|
62
|
-
super( service_name, options )
|
63
|
-
|
64
|
-
#if AMQP.connection.nil?
|
65
|
-
@em_thread = Thread.new { EM.run } unless EM.reactor_running?
|
66
|
-
#end
|
67
|
-
|
68
|
-
MQ.queue( self.class.queue, :durable => true ).subscribe do |message|
|
69
|
-
workitem = decode_workitem( message )
|
70
|
-
ldebug { "workitem from '#{self.class.queue}': #{workitem.inspect}" }
|
71
|
-
handle_item( workitem )
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def stop
|
76
|
-
linfo { "Stopping..." }
|
77
|
-
|
78
|
-
AMQP.stop { EM.stop } #if EM.reactor_running? }
|
79
|
-
@em_thread.join if @em_thread
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
# Complicated guesswork that needs to happen here to detect the format
|
85
|
-
def decode_workitem( msg )
|
86
|
-
ldebug { "decoding workitem from: #{msg}" }
|
87
|
-
|
88
|
-
hash = OpenWFE::Json.decode(msg)
|
89
|
-
OpenWFE.workitem_from_h( hash )
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/tasks/rspec.rake
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
-
require 'spec'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
rescue LoadError
|
10
|
-
puts <<-EOS
|
11
|
-
To use rspec for testing you must install rspec gem:
|
12
|
-
gem install rspec
|
13
|
-
EOS
|
14
|
-
exit(0)
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|