activemessaging 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +54 -13
- data/README.md +6 -0
- data/VERSION +1 -1
- data/activemessaging.gemspec +8 -4
- data/gemfiles/activesupport23.gemfile.lock +2 -2
- data/gemfiles/activesupport30.gemfile.lock +2 -2
- data/gemfiles/activesupport31.gemfile.lock +2 -2
- data/gemfiles/activesupport32.gemfile.lock +2 -2
- data/lib/activemessaging.rb +12 -7
- data/lib/activemessaging/adapters/amqp.rb +1 -1
- data/lib/activemessaging/adapters/stomp.rb +12 -3
- data/lib/activemessaging/gateway.rb +31 -27
- data/lib/activemessaging/railtie.rb +4 -0
- data/lib/activemessaging/threaded_poller.rb +31 -6
- data/lib/generators/active_messaging/install/install_generator.rb +6 -6
- data/lib/generators/active_messaging/install/templates/threaded_poller +1 -0
- data/lib/generators/active_messaging/processor/processor_generator.rb +2 -2
- metadata +31 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f05d43c09bd5e33636c4b916952a0036c299b904
|
4
|
+
data.tar.gz: 2a073f54521759315dda76d0434872f1f96d8732
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 598a0605d67d4a904a855341ac2c49f15fc0fc3ca36eb287eab8b94aacf57da122aba9f01516e78efeaa0ee6f55ccebd713bcfdab05ee637acff6e67850c5112
|
7
|
+
data.tar.gz: 6b8ae9feed2d6c89929951e665e4eecfb937cc722377249b5a67e483900424fbd07514a2f4f94dff894d2a26d6f89211516cbf0e55db46743f2b36ae46bdb1e8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activemessaging (0.12.
|
4
|
+
activemessaging (0.12.2)
|
5
5
|
activemessaging
|
6
6
|
activesupport (>= 2.3.11)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
12
|
-
i18n (~> 0.6)
|
13
|
-
|
11
|
+
activesupport (4.0.5)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
minitest (~> 4.2)
|
14
|
+
multi_json (~> 1.3)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 0.3.37)
|
17
|
+
addressable (2.3.6)
|
14
18
|
appraisal (0.4.1)
|
15
19
|
bundler
|
16
20
|
rake
|
21
|
+
builder (3.2.2)
|
17
22
|
celluloid (0.12.0)
|
18
23
|
timers (>= 1.0.0)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
descendants_tracker (0.0.4)
|
25
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
26
|
+
faraday (0.9.0)
|
27
|
+
multipart-post (>= 1.2, < 3)
|
28
|
+
git (1.2.6)
|
29
|
+
github_api (0.11.3)
|
30
|
+
addressable (~> 2.3)
|
31
|
+
descendants_tracker (~> 0.0.1)
|
32
|
+
faraday (~> 0.8, < 0.10)
|
33
|
+
hashie (>= 1.2)
|
34
|
+
multi_json (>= 1.7.5, < 2.0)
|
35
|
+
nokogiri (~> 1.6.0)
|
36
|
+
oauth2
|
37
|
+
hashie (3.0.0)
|
38
|
+
highline (1.6.21)
|
39
|
+
i18n (0.6.9)
|
40
|
+
jeweler (2.0.1)
|
41
|
+
builder
|
42
|
+
bundler (>= 1.0)
|
23
43
|
git (>= 1.2.5)
|
44
|
+
github_api
|
45
|
+
highline (>= 1.6.15)
|
46
|
+
nokogiri (>= 1.5.10)
|
24
47
|
rake
|
25
48
|
rdoc
|
26
49
|
jruby-activemq (5.5.1-java)
|
27
|
-
json (1.
|
28
|
-
json (1.
|
29
|
-
|
30
|
-
|
31
|
-
|
50
|
+
json (1.8.1)
|
51
|
+
json (1.8.1-java)
|
52
|
+
jwt (1.0.0)
|
53
|
+
mini_portile (0.6.0)
|
54
|
+
minitest (4.7.5)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
multi_xml (0.5.5)
|
57
|
+
multipart-post (2.0.0)
|
58
|
+
nokogiri (1.6.2.1)
|
59
|
+
mini_portile (= 0.6.0)
|
60
|
+
nokogiri (1.6.2.1-java)
|
61
|
+
oauth2 (0.9.4)
|
62
|
+
faraday (>= 0.8, < 0.10)
|
63
|
+
jwt (~> 1.0)
|
64
|
+
multi_json (~> 1.3)
|
65
|
+
multi_xml (~> 0.5)
|
66
|
+
rack (~> 1.2)
|
67
|
+
rack (1.5.2)
|
68
|
+
rake (10.3.2)
|
69
|
+
rdoc (4.1.1)
|
32
70
|
json (~> 1.4)
|
33
71
|
stomp (1.2.4)
|
72
|
+
thread_safe (0.3.4)
|
73
|
+
thread_safe (0.3.4-java)
|
34
74
|
timers (1.0.1)
|
75
|
+
tzinfo (0.3.39)
|
35
76
|
|
36
77
|
PLATFORMS
|
37
78
|
java
|
data/README.md
CHANGED
@@ -13,6 +13,12 @@ Here's a sample of a processor class that handles incoming messages:
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# Generating with Rails 3
|
17
|
+
|
18
|
+
After adding ActiveMessaging to your Gemfile and executing bundle install, run the following commands:
|
19
|
+
|
20
|
+
rails g active_messaging:install
|
21
|
+
rails g active_messaging:processor <NameOfYourProcessor>
|
16
22
|
|
17
23
|
# Support
|
18
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.12.
|
1
|
+
0.12.2
|
data/activemessaging.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: activemessaging 0.12.2 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "activemessaging"
|
8
|
-
s.version = "0.12.
|
9
|
+
s.version = "0.12.2"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch", "Lance Cooper", "Matt Campbell"]
|
12
|
-
s.date = "
|
13
|
+
s.date = "2014-06-05"
|
13
14
|
s.description = "ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc. Now supporting Rails 3 as of version 0.8.0."
|
14
15
|
s.email = "activemessaging-discuss@googlegroups.com"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -109,20 +110,22 @@ Gem::Specification.new do |s|
|
|
109
110
|
]
|
110
111
|
s.homepage = "http://github.com/kookster/activemessaging"
|
111
112
|
s.require_paths = ["lib"]
|
112
|
-
s.rubygems_version = "1.
|
113
|
+
s.rubygems_version = "2.1.11"
|
113
114
|
s.summary = "Official activemessaging gem, now hosted on github.com/kookster. (kookster prefix temporary)"
|
114
115
|
|
115
116
|
if s.respond_to? :specification_version then
|
116
|
-
s.specification_version =
|
117
|
+
s.specification_version = 4
|
117
118
|
|
118
119
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
119
120
|
s.add_runtime_dependency(%q<activemessaging>, [">= 0"])
|
121
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
120
122
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.11"])
|
121
123
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
122
124
|
s.add_development_dependency(%q<stomp>, [">= 0"])
|
123
125
|
s.add_development_dependency(%q<appraisal>, [">= 0"])
|
124
126
|
else
|
125
127
|
s.add_dependency(%q<activemessaging>, [">= 0"])
|
128
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
126
129
|
s.add_dependency(%q<activesupport>, [">= 2.3.11"])
|
127
130
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
128
131
|
s.add_dependency(%q<stomp>, [">= 0"])
|
@@ -130,6 +133,7 @@ Gem::Specification.new do |s|
|
|
130
133
|
end
|
131
134
|
else
|
132
135
|
s.add_dependency(%q<activemessaging>, [">= 0"])
|
136
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
133
137
|
s.add_dependency(%q<activesupport>, [">= 2.3.11"])
|
134
138
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
135
139
|
s.add_dependency(%q<stomp>, [">= 0"])
|
data/lib/activemessaging.rb
CHANGED
@@ -14,12 +14,12 @@ module ActiveMessaging
|
|
14
14
|
class StopProcessingException < Interrupt #:nodoc:
|
15
15
|
end
|
16
16
|
|
17
|
-
# Used to indicate that the processing on a message should cease,
|
17
|
+
# Used to indicate that the processing on a message should cease,
|
18
18
|
# and the message should be returned back to the broker as best it can be
|
19
19
|
class AbortMessageException < Exception #:nodoc:
|
20
20
|
end
|
21
21
|
|
22
|
-
# Used to indicate that the processing on a message should cease,
|
22
|
+
# Used to indicate that the processing on a message should cease,
|
23
23
|
# but no further action is required
|
24
24
|
class StopFilterException < Exception #:nodoc:
|
25
25
|
end
|
@@ -46,15 +46,14 @@ module ActiveMessaging
|
|
46
46
|
def self.load_extensions
|
47
47
|
require 'logger'
|
48
48
|
require 'activemessaging/gateway'
|
49
|
-
require 'activemessaging/threaded_poller'
|
50
49
|
require 'activemessaging/adapter'
|
51
50
|
require 'activemessaging/message_sender'
|
52
51
|
require 'activemessaging/processor'
|
53
52
|
require 'activemessaging/filter'
|
54
53
|
require 'activemessaging/trace_filter'
|
55
54
|
|
56
|
-
# load all under the adapters dir
|
57
|
-
Dir[File.join(ROOT, 'lib', 'activemessaging', 'adapters', '*.rb')].each do |a|
|
55
|
+
# load all under the adapters dir
|
56
|
+
Dir[File.join(ROOT, 'lib', 'activemessaging', 'adapters', '*.rb')].each do |a|
|
58
57
|
begin
|
59
58
|
adapter_name = File.basename(a, ".rb")
|
60
59
|
require 'activemessaging/adapters/' + adapter_name
|
@@ -65,9 +64,15 @@ module ActiveMessaging
|
|
65
64
|
end
|
66
65
|
|
67
66
|
def self.load_config
|
67
|
+
# Skip loading config if there are no custom processors as the generator
|
68
|
+
# is likely running since application_processor.rb and another processor
|
69
|
+
# should exist when running rails.
|
70
|
+
if Dir["#{app_root}/app/processors/*.rb"].size() <= 1
|
71
|
+
return
|
72
|
+
end
|
68
73
|
path = File.expand_path("#{app_root}/config/messaging.rb")
|
69
74
|
begin
|
70
|
-
load path
|
75
|
+
load path
|
71
76
|
rescue
|
72
77
|
raise $!, " ActiveMessaging: problems trying to load '#{path}': \n\t#{$!.message}"
|
73
78
|
end
|
@@ -106,7 +111,7 @@ module ActiveMessaging
|
|
106
111
|
err_msg = <<-EOM
|
107
112
|
|
108
113
|
ActiveMessaging Error: No subscriptions.
|
109
|
-
|
114
|
+
|
110
115
|
If you have no processor classes in app/processors, add them using the command:
|
111
116
|
script/generate processor DoSomething"
|
112
117
|
|
@@ -61,7 +61,7 @@ module ActiveMessaging
|
|
61
61
|
|
62
62
|
@queue_config = DEFAULT_QUEUE_CONFIG
|
63
63
|
unless @auto_generated_queue
|
64
|
-
@queue_config.merge({
|
64
|
+
@queue_config.merge!({
|
65
65
|
:durable => !!config[:queue_durable],
|
66
66
|
:auto_delete => !!config[:queue_auto_delete],
|
67
67
|
:exclusive => !!config[:queue_exclusive]
|
@@ -80,10 +80,19 @@ module ActiveMessaging
|
|
80
80
|
|
81
81
|
def received message, headers={}
|
82
82
|
#check to see if the ack mode for this subscription is auto or client
|
83
|
-
# if the ack mode is client, send an ack
|
84
|
-
if (headers[:ack] === 'client')
|
83
|
+
# if the ack mode is client or client-individual, send an ack
|
84
|
+
if (headers[:ack] === 'client' || headers[:ack] === 'client-individual')
|
85
85
|
ack_headers = message.headers.has_key?(:transaction) ? { :transaction=>message.headers[:transaction]} : {}
|
86
|
-
|
86
|
+
# All 3 protocol levels have unique ACK requirements.
|
87
|
+
case @stomp_connection.protocol
|
88
|
+
when ::Stomp::SPL_10
|
89
|
+
@stomp_connection.ack(message.headers['message-id'], ack_headers)
|
90
|
+
when ::Stomp::SPL_11
|
91
|
+
ack_headers['subscription'] = message.headers['subscription']
|
92
|
+
@stomp_connection.ack(message.headers['message-id'], ack_headers)
|
93
|
+
else # avoid ::Stomp::SPL_12 constant when using older Stomp gems
|
94
|
+
@stomp_connection.ack(message.headers['ack'], ack_headers)
|
95
|
+
end
|
87
96
|
end
|
88
97
|
end
|
89
98
|
|
@@ -6,7 +6,7 @@ require 'thread'
|
|
6
6
|
module ActiveMessaging
|
7
7
|
|
8
8
|
class Gateway
|
9
|
-
|
9
|
+
|
10
10
|
@adapters = {}
|
11
11
|
@subscriptions = {}
|
12
12
|
@named_destinations = {}
|
@@ -61,7 +61,7 @@ module ActiveMessaging
|
|
61
61
|
ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: receive loop terminated"
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
while @running
|
66
66
|
trap("TERM", "EXIT")
|
67
67
|
living = false
|
@@ -71,7 +71,7 @@ module ActiveMessaging
|
|
71
71
|
end
|
72
72
|
ActiveMessaging.logger.error "All connection threads have died..."
|
73
73
|
rescue Interrupt
|
74
|
-
ActiveMessaging.logger.error "\n<<Interrupt received>>\n"
|
74
|
+
ActiveMessaging.logger.error "\n<<Interrupt received>>\n"
|
75
75
|
rescue Object=>exception
|
76
76
|
ActiveMessaging.logger.error "#{exception.class.name}: #{exception.message}\n\t#{exception.backtrace.join("\n\t")}"
|
77
77
|
raise exception
|
@@ -80,11 +80,11 @@ module ActiveMessaging
|
|
80
80
|
stop
|
81
81
|
ActiveMessaging.logger.error "=> END"
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def stop
|
85
85
|
# first tell the threads to stop their looping, so they'll stop when next complete a receive/dispatch cycle
|
86
86
|
@running = false
|
87
|
-
|
87
|
+
|
88
88
|
# if they are dispatching (i.e. !thread[:message].nil?), wait for them to finish
|
89
89
|
# if they are receiving (i.e. thread[:message].nil?), stop them by raising exception
|
90
90
|
dispatching = true
|
@@ -118,7 +118,7 @@ module ActiveMessaging
|
|
118
118
|
unsubscribe
|
119
119
|
disconnect
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def connection broker_name='default'
|
123
123
|
return @connections[broker_name] if @connections.has_key?(broker_name)
|
124
124
|
config = load_connection_configuration(broker_name)
|
@@ -130,12 +130,12 @@ module ActiveMessaging
|
|
130
130
|
def register_adapter adapter_name, adapter_class
|
131
131
|
Gateway.adapters[adapter_name] = adapter_class
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
def filter filter, options = {}
|
135
135
|
options[:direction] = :bidirectional if options[:direction].nil?
|
136
136
|
filters << [filter, options]
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def subscribe
|
140
140
|
subscriptions.each { |key, subscription| subscription.subscribe }
|
141
141
|
end
|
@@ -163,7 +163,7 @@ module ActiveMessaging
|
|
163
163
|
end
|
164
164
|
yield(message)
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def apply_filter?(direction, details, options)
|
168
168
|
# check that it is the correct direction
|
169
169
|
result = if direction.to_sym == options[:direction] || options[:direction] == :bidirectional
|
@@ -201,14 +201,18 @@ module ActiveMessaging
|
|
201
201
|
end
|
202
202
|
|
203
203
|
def prepare_application
|
204
|
-
|
204
|
+
return unless defined?(ActiveRecord)
|
205
|
+
|
206
|
+
if ActiveRecord::VERSION::MAJOR >= 4
|
207
|
+
ActiveRecord::Base.connection_pool.connections.map(&:verify!)
|
208
|
+
else
|
205
209
|
ActiveRecord::Base.verify_active_connections!
|
206
210
|
end
|
207
211
|
end
|
208
212
|
|
209
213
|
def reset_application
|
210
214
|
end
|
211
|
-
|
215
|
+
|
212
216
|
def dispatch(message)
|
213
217
|
prepare_application
|
214
218
|
_dispatch(message)
|
@@ -225,11 +229,11 @@ module ActiveMessaging
|
|
225
229
|
abort = false
|
226
230
|
processed = false
|
227
231
|
|
228
|
-
subscriptions.each do |key, subscription|
|
232
|
+
subscriptions.each do |key, subscription|
|
229
233
|
if message.matches_subscription?(subscription) then
|
230
234
|
processed = true
|
231
235
|
routing = {
|
232
|
-
:receiver => subscription.processor_class,
|
236
|
+
:receiver => subscription.processor_class,
|
233
237
|
:destination => subscription.destination,
|
234
238
|
:direction => :incoming
|
235
239
|
}
|
@@ -271,9 +275,9 @@ module ActiveMessaging
|
|
271
275
|
raise "You already defined #{destination_name} to #{named_destinations[destination_name].value}" if named_destinations.has_key?(destination_name)
|
272
276
|
named_destinations[destination_name] = Destination.new(destination_name, destination, publish_headers, broker)
|
273
277
|
end
|
274
|
-
|
278
|
+
|
275
279
|
alias queue destination
|
276
|
-
|
280
|
+
|
277
281
|
def find_destination destination_name
|
278
282
|
real_destination = named_destinations[destination_name]
|
279
283
|
raise "You have not yet defined a destination named #{destination_name}. Destinations currently defined are [#{named_destinations.keys.join(',')}]" if real_destination.nil?
|
@@ -293,10 +297,10 @@ module ActiveMessaging
|
|
293
297
|
def publish destination_name, body, publisher=nil, headers={}, timeout=10
|
294
298
|
raise "You cannot have a nil or empty destination name." if destination_name.nil?
|
295
299
|
raise "You cannot have a nil or empty message body." if (body.nil? || body.empty?)
|
296
|
-
|
300
|
+
|
297
301
|
real_destination = find_destination(destination_name)
|
298
302
|
details = {
|
299
|
-
:publisher => publisher,
|
303
|
+
:publisher => publisher,
|
300
304
|
:destination => real_destination,
|
301
305
|
:direction => :outgoing
|
302
306
|
}
|
@@ -312,13 +316,13 @@ module ActiveMessaging
|
|
312
316
|
raise toe
|
313
317
|
end
|
314
318
|
end
|
315
|
-
|
319
|
+
|
316
320
|
def receive destination_name, receiver=nil, subscribe_headers={}, timeout=10
|
317
321
|
raise "You cannot have a nil or empty destination name." if destination_name.nil?
|
318
322
|
conn = nil
|
319
323
|
dest = find_destination destination_name
|
320
324
|
config = load_connection_configuration(dest.broker_name)
|
321
|
-
subscribe_headers['id'] = receiver.name.underscore unless (receiver.nil? or subscribe_headers.key? 'id')
|
325
|
+
subscribe_headers['id'] = receiver.name.underscore unless (receiver.nil? or subscribe_headers.key? 'id')
|
322
326
|
Timeout.timeout timeout do
|
323
327
|
conn = Gateway.adapters[config[:adapter]].new(config)
|
324
328
|
conn.subscribe(dest.value, subscribe_headers)
|
@@ -332,7 +336,7 @@ module ActiveMessaging
|
|
332
336
|
ensure
|
333
337
|
conn.disconnect unless conn.nil?
|
334
338
|
end
|
335
|
-
|
339
|
+
|
336
340
|
def processor_group group_name, *processors
|
337
341
|
if processor_groups.has_key? group_name
|
338
342
|
processor_groups[group_name] = processor_groups[group_name] + processors
|
@@ -362,7 +366,7 @@ module ActiveMessaging
|
|
362
366
|
end
|
363
367
|
@current_processor_group
|
364
368
|
end
|
365
|
-
|
369
|
+
|
366
370
|
def load_connection_configuration(label='default')
|
367
371
|
@broker_yml = YAML::load(ERB.new(IO.read(File.join(ActiveMessaging.app_root, 'config', 'broker.yml'))).result) if @broker_yml.nil?
|
368
372
|
if label == 'default'
|
@@ -374,14 +378,14 @@ module ActiveMessaging
|
|
374
378
|
config[:adapter] ||= :stomp
|
375
379
|
return config
|
376
380
|
end
|
377
|
-
|
381
|
+
|
378
382
|
end
|
379
383
|
|
380
384
|
end
|
381
385
|
|
382
386
|
class Subscription
|
383
387
|
attr_accessor :destination, :processor_class, :subscribe_headers
|
384
|
-
|
388
|
+
|
385
389
|
def initialize(destination, processor_class, subscribe_headers = {})
|
386
390
|
@destination, @processor_class, @subscribe_headers = destination, processor_class, subscribe_headers
|
387
391
|
subscribe_headers['id'] = processor_class.name.underscore unless subscribe_headers.key? 'id'
|
@@ -389,7 +393,7 @@ module ActiveMessaging
|
|
389
393
|
|
390
394
|
def subscribe
|
391
395
|
ActiveMessaging.logger.error "=> Subscribing to #{destination.value} (processed by #{processor_class})"
|
392
|
-
Gateway.connection(@destination.broker_name).subscribe(@destination.value, subscribe_headers)
|
396
|
+
Gateway.connection(@destination.broker_name).subscribe(@destination.value, subscribe_headers)
|
393
397
|
end
|
394
398
|
|
395
399
|
def unsubscribe
|
@@ -408,13 +412,13 @@ module ActiveMessaging
|
|
408
412
|
@publish_headers.reverse_merge! DEFAULT_PUBLISH_HEADERS
|
409
413
|
@wildcard = wildcard_match_exp_for(value) if (value =~ /\*/)
|
410
414
|
end
|
411
|
-
|
415
|
+
|
412
416
|
def to_s
|
413
417
|
"<destination: #{broker_name} :#{name}=>'#{value}'>"
|
414
418
|
end
|
415
|
-
|
419
|
+
|
416
420
|
private
|
417
|
-
|
421
|
+
|
418
422
|
def wildcard_match_exp_for(destination)
|
419
423
|
exp = destination.to_s.gsub(/[.]/, '\.').gsub(/[*]/, '[^.*]+').gsub(/([>].*$)/, '.*') + '$'
|
420
424
|
Regexp.new(exp)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# still working on prioritized worker requests
|
2
|
-
|
3
|
-
|
4
1
|
# This owes no small debt to sidekiq for showing how to use celluloid for polling for messages.
|
5
2
|
# https://github.com/mperham/sidekiq/blob/poller/lib/sidekiq/manager.rb
|
6
3
|
if RUBY_VERSION.to_f >= 1.9 # Celluloid requires fibers support, which is not available on 1.8
|
@@ -15,7 +12,7 @@ module ActiveMessaging
|
|
15
12
|
# traps when any worker dies
|
16
13
|
trap_exit :died
|
17
14
|
|
18
|
-
attr_accessor :configuration, :receiver, :connection, :workers, :busy, :running
|
15
|
+
attr_accessor :configuration, :receiver, :connection, :workers, :busy, :running, :pause
|
19
16
|
|
20
17
|
#
|
21
18
|
# connection is a string, name of the connection from broker.yml to use for this threaded poller instance
|
@@ -34,6 +31,7 @@ module ActiveMessaging
|
|
34
31
|
# default config is a pool size of 3 worker threads
|
35
32
|
self.configuration = configuration || [{:pool_size => 3}]
|
36
33
|
self.connection = connection
|
34
|
+
self.pause = 1
|
37
35
|
end
|
38
36
|
|
39
37
|
def start
|
@@ -54,7 +52,7 @@ module ActiveMessaging
|
|
54
52
|
|
55
53
|
# create a message receiver actor, ony need one, using connection
|
56
54
|
receiver_connection = ActiveMessaging::Gateway.connection(connection)
|
57
|
-
self.receiver = MessageReceiver.new(current_actor, receiver_connection)
|
55
|
+
self.receiver = MessageReceiver.new(current_actor, receiver_connection, pause)
|
58
56
|
|
59
57
|
# start the workers based on the config
|
60
58
|
configuration.each do |c|
|
@@ -138,6 +136,14 @@ module ActiveMessaging
|
|
138
136
|
(!running && busy.empty?)
|
139
137
|
end
|
140
138
|
|
139
|
+
def inspect
|
140
|
+
"#<ThreadedPoller #{to_s}>"
|
141
|
+
end
|
142
|
+
|
143
|
+
def to_s
|
144
|
+
@str ||= "#{Process.pid}-#{Thread.current.object_id}:#{self.object_id}"
|
145
|
+
end
|
146
|
+
|
141
147
|
def logger; ActiveMessaging.logger; end
|
142
148
|
|
143
149
|
end
|
@@ -172,12 +178,20 @@ module ActiveMessaging
|
|
172
178
|
logger.debug("ActiveMessaging::MessageReceiver.receive: terminate")
|
173
179
|
self.terminate
|
174
180
|
end
|
175
|
-
logger.debug("ActiveMessaging::MessageReceiver.receive: no message, retry in #{pause} sec")
|
181
|
+
logger.debug("ActiveMessaging::MessageReceiver.receive: no message for worker #{worker.object_id}, retry in #{pause} sec")
|
176
182
|
after(pause) { receive(worker) }
|
177
183
|
end
|
178
184
|
|
179
185
|
end
|
180
186
|
|
187
|
+
def inspect
|
188
|
+
"#<MessageReceiver #{to_s}>"
|
189
|
+
end
|
190
|
+
|
191
|
+
def to_s
|
192
|
+
@str ||= "#{Process.pid}-#{Thread.current.object_id}:#{self.object_id}"
|
193
|
+
end
|
194
|
+
|
181
195
|
def logger; ::ActiveMessaging.logger; end
|
182
196
|
end
|
183
197
|
|
@@ -194,6 +208,9 @@ module ActiveMessaging
|
|
194
208
|
def execute(message)
|
195
209
|
begin
|
196
210
|
::ActiveMessaging::Gateway.dispatch(message)
|
211
|
+
rescue Object => err
|
212
|
+
logger.error("ActiveMessaging::Worker.execute error - #{err.inspect}")
|
213
|
+
abort(err)
|
197
214
|
ensure
|
198
215
|
::ActiveRecord::Base.clear_active_connections! if defined?(::ActiveRecord)
|
199
216
|
end
|
@@ -201,6 +218,14 @@ module ActiveMessaging
|
|
201
218
|
poller.executed!(current_actor)
|
202
219
|
end
|
203
220
|
|
221
|
+
def inspect
|
222
|
+
"#<Worker #{to_s}>"
|
223
|
+
end
|
224
|
+
|
225
|
+
def to_s
|
226
|
+
@str ||= "#{Process.pid}-#{Thread.current.object_id}:#{self.object_id}"
|
227
|
+
end
|
228
|
+
|
204
229
|
def logger; ::ActiveMessaging.logger; end
|
205
230
|
|
206
231
|
end
|
@@ -3,11 +3,11 @@ module ActiveMessaging
|
|
3
3
|
source_root File.expand_path("../templates", __FILE__)
|
4
4
|
|
5
5
|
argument :poller_name, :type => :string, :default => 'poller', :banner => 'poller_name'
|
6
|
-
|
6
|
+
|
7
7
|
def copy_application
|
8
8
|
copy_file "application_processor.rb", "app/processors/application_processor.rb"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def copy_poller
|
12
12
|
template "poller", "script/#{poller_name}"
|
13
13
|
chmod("script/#{poller_name}", 0755)
|
@@ -25,15 +25,15 @@ module ActiveMessaging
|
|
25
25
|
def copy_broker_rb
|
26
26
|
copy_file "broker.yml", "config/broker.yml"
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def add_gems
|
30
30
|
gem("daemons")
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
|
34
34
|
def change_application
|
35
35
|
application ' config.autoload_paths += %W(#{config.root}/app/processors)'
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
@@ -26,6 +26,7 @@ Dir["#{lib_path}/**/*.rb"].each {|file| require file unless file.match(/poller\.
|
|
26
26
|
# require and load activemessaging
|
27
27
|
require 'activemessaging'
|
28
28
|
ActiveMessaging.load_activemessaging
|
29
|
+
require 'activemessaging/threaded_poller'
|
29
30
|
|
30
31
|
# configure the connection (there can be multiple defined in broker.yml) and number of threads
|
31
32
|
connection_name = 'default'
|
@@ -4,7 +4,7 @@ module ActiveMessaging
|
|
4
4
|
source_root File.expand_path("../templates", __FILE__)
|
5
5
|
|
6
6
|
# check_class_collision :suffix=>"Processor"
|
7
|
-
|
7
|
+
|
8
8
|
def copy_processor
|
9
9
|
template "processor.rb", "app/processors/#{file_name}_processor.rb"
|
10
10
|
end
|
@@ -36,4 +36,4 @@ module Rspec
|
|
36
36
|
template "processor_spec.rb", "spec/functional/#{file_name}_processor_spec.rb"
|
37
37
|
end
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemessaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
5
|
-
prerelease:
|
4
|
+
version: 0.12.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Tirsen
|
@@ -16,86 +15,90 @@ authors:
|
|
16
15
|
autorequire:
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
|
-
date:
|
18
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: activemessaging
|
23
22
|
requirement: !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - '>='
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: '0'
|
29
27
|
type: :runtime
|
30
28
|
prerelease: false
|
31
29
|
version_requirements: !ruby/object:Gem::Requirement
|
32
|
-
none: false
|
33
30
|
requirements:
|
34
|
-
- -
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: jeweler
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
35
46
|
- !ruby/object:Gem::Version
|
36
47
|
version: '0'
|
37
48
|
- !ruby/object:Gem::Dependency
|
38
49
|
name: activesupport
|
39
50
|
requirement: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
51
|
requirements:
|
42
|
-
- -
|
52
|
+
- - '>='
|
43
53
|
- !ruby/object:Gem::Version
|
44
54
|
version: 2.3.11
|
45
55
|
type: :runtime
|
46
56
|
prerelease: false
|
47
57
|
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
58
|
requirements:
|
50
|
-
- -
|
59
|
+
- - '>='
|
51
60
|
- !ruby/object:Gem::Version
|
52
61
|
version: 2.3.11
|
53
62
|
- !ruby/object:Gem::Dependency
|
54
63
|
name: jeweler
|
55
64
|
requirement: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
65
|
requirements:
|
58
|
-
- -
|
66
|
+
- - '>='
|
59
67
|
- !ruby/object:Gem::Version
|
60
68
|
version: '0'
|
61
69
|
type: :development
|
62
70
|
prerelease: false
|
63
71
|
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
72
|
requirements:
|
66
|
-
- -
|
73
|
+
- - '>='
|
67
74
|
- !ruby/object:Gem::Version
|
68
75
|
version: '0'
|
69
76
|
- !ruby/object:Gem::Dependency
|
70
77
|
name: stomp
|
71
78
|
requirement: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
79
|
requirements:
|
74
|
-
- -
|
80
|
+
- - '>='
|
75
81
|
- !ruby/object:Gem::Version
|
76
82
|
version: '0'
|
77
83
|
type: :development
|
78
84
|
prerelease: false
|
79
85
|
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
86
|
requirements:
|
82
|
-
- -
|
87
|
+
- - '>='
|
83
88
|
- !ruby/object:Gem::Version
|
84
89
|
version: '0'
|
85
90
|
- !ruby/object:Gem::Dependency
|
86
91
|
name: appraisal
|
87
92
|
requirement: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
93
|
requirements:
|
90
|
-
- -
|
94
|
+
- - '>='
|
91
95
|
- !ruby/object:Gem::Version
|
92
96
|
version: '0'
|
93
97
|
type: :development
|
94
98
|
prerelease: false
|
95
99
|
version_requirements: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
100
|
requirements:
|
98
|
-
- -
|
101
|
+
- - '>='
|
99
102
|
- !ruby/object:Gem::Version
|
100
103
|
version: '0'
|
101
104
|
description: ActiveMessaging is an attempt to bring the simplicity and elegance of
|
@@ -201,30 +204,26 @@ files:
|
|
201
204
|
- test/tracer_test.rb
|
202
205
|
homepage: http://github.com/kookster/activemessaging
|
203
206
|
licenses: []
|
207
|
+
metadata: {}
|
204
208
|
post_install_message:
|
205
209
|
rdoc_options: []
|
206
210
|
require_paths:
|
207
211
|
- lib
|
208
212
|
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
-
none: false
|
210
213
|
requirements:
|
211
|
-
- -
|
214
|
+
- - '>='
|
212
215
|
- !ruby/object:Gem::Version
|
213
216
|
version: '0'
|
214
|
-
segments:
|
215
|
-
- 0
|
216
|
-
hash: 2900052431742468498
|
217
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
-
none: false
|
219
218
|
requirements:
|
220
|
-
- -
|
219
|
+
- - '>='
|
221
220
|
- !ruby/object:Gem::Version
|
222
221
|
version: '0'
|
223
222
|
requirements: []
|
224
223
|
rubyforge_project:
|
225
|
-
rubygems_version: 1.
|
224
|
+
rubygems_version: 2.1.11
|
226
225
|
signing_key:
|
227
|
-
specification_version:
|
226
|
+
specification_version: 4
|
228
227
|
summary: Official activemessaging gem, now hosted on github.com/kookster. (kookster
|
229
228
|
prefix temporary)
|
230
229
|
test_files: []
|