cwyckoff-rosetta_queue 0.2.0 → 0.2.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/lib/rosetta_queue/adapter.rb +0 -1
- data/lib/rosetta_queue/adapters/amqp.rb +80 -68
- data/lib/rosetta_queue/adapters/base.rb +1 -1
- data/lib/rosetta_queue/consumer_managers/base.rb +1 -1
- data/lib/rosetta_queue/producer.rb +1 -9
- data/lib/rosetta_queue/spec_helpers/helpers.rb +1 -1
- metadata +1 -3
- data/lib/rosetta_queue/adapters/amqp_base.rb +0 -36
- data/lib/rosetta_queue/adapters/amqp_carrot.rb +0 -100
|
@@ -15,7 +15,6 @@ module RosettaQueue
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def type=(adapter_prefix)
|
|
18
|
-
require "rosetta_queue/adapters/amqp_base" if adapter_prefix =~ /amqp/
|
|
19
18
|
require "rosetta_queue/adapters/#{adapter_prefix}"
|
|
20
19
|
@adapter_class = RosettaQueue::Gateway.const_get("#{adapter_prefix.to_s.classify}Adapter")
|
|
21
20
|
|
|
@@ -1,20 +1,56 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'carrot'
|
|
2
2
|
|
|
3
3
|
module RosettaQueue
|
|
4
4
|
module Gateway
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# This AMQP adapter utilizes a forked version of the synchronous AMPQ client 'Carrot'
|
|
7
|
+
# by famoseagle (http://github.com/famoseagle)
|
|
8
|
+
class AmqpAdapter < BaseAdapter
|
|
9
|
+
|
|
10
|
+
def initialize(adapter_settings = {})
|
|
11
|
+
raise AdapterException, "Missing adapter settings" if adapter_settings.empty?
|
|
12
|
+
@adapter_settings = adapter_settings
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def delete(destination, opts={})
|
|
16
|
+
exchange_strategy_for(destination, opts).delete(destination)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def disconnect(message_handler); end
|
|
20
|
+
|
|
21
|
+
def receive_once(destination, opts={})
|
|
22
|
+
exchange_strategy_for(destination, opts).receive_once(destination) do |msg|
|
|
23
|
+
return msg
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def receive_with(message_handler)
|
|
28
|
+
options = options_for(message_handler)
|
|
29
|
+
destination = destination_for(message_handler)
|
|
30
|
+
exchange_strategy_for(destination, options).receive(destination, message_handler)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def send_message(destination, message, options=nil)
|
|
34
|
+
exchange_strategy_for(destination, options).publish(destination, message)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def unsubscribe; end
|
|
38
|
+
|
|
39
|
+
private
|
|
7
40
|
|
|
8
41
|
def exchange_strategy_for(destination, options)
|
|
9
42
|
case destination
|
|
10
43
|
when /fanout/
|
|
11
44
|
@exchange ||= AmqpExchangeStrategies::FanoutExchange.new(@adapter_settings, options)
|
|
45
|
+
when /topic/
|
|
46
|
+
raise "Sorry. RosettaQueue can not process AMQP topics yet"
|
|
12
47
|
when /queue/
|
|
13
48
|
@exchange ||= AmqpExchangeStrategies::DirectExchange.new(@adapter_settings, options)
|
|
14
49
|
else
|
|
15
50
|
@exchange ||= AmqpExchangeStrategies::DirectExchange.new(@adapter_settings, options)
|
|
16
51
|
end
|
|
17
52
|
end
|
|
53
|
+
|
|
18
54
|
end
|
|
19
55
|
|
|
20
56
|
module AmqpExchangeStrategies
|
|
@@ -25,99 +61,75 @@ module RosettaQueue
|
|
|
25
61
|
@adapter_settings, @options = adapter_settings, options
|
|
26
62
|
end
|
|
27
63
|
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
publish_message(destination, message)
|
|
32
|
-
EM.add_timer(1) { EM.stop_event_loop }
|
|
33
|
-
end
|
|
34
|
-
else
|
|
35
|
-
publish_message(destination, message)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
64
|
+
def delete(destination)
|
|
65
|
+
conn.queue(destination).delete(@options)
|
|
66
|
+
end
|
|
38
67
|
|
|
39
68
|
protected
|
|
40
|
-
|
|
41
|
-
def channel
|
|
42
|
-
@channel ||= MQ.new(conn)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
69
|
def conn
|
|
46
70
|
vhost = @adapter_settings[:opts][:vhost] || "/"
|
|
47
|
-
@conn ||=
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def publish_message(dest, msg)
|
|
54
|
-
RosettaQueue.logger.info("Publishing to #{dest} :: #{msg}")
|
|
55
|
-
channel.queue(dest).publish(msg, @options)
|
|
56
|
-
channel.queue(dest).unsubscribe
|
|
71
|
+
@conn ||= Carrot.new(:user => @adapter_settings[:user],
|
|
72
|
+
:pass => @adapter_settings[:password],
|
|
73
|
+
:host => @adapter_settings[:host],
|
|
74
|
+
:vhost => vhost)
|
|
57
75
|
end
|
|
58
76
|
end
|
|
59
77
|
|
|
60
|
-
|
|
61
78
|
class DirectExchange < BaseExchange
|
|
62
79
|
|
|
80
|
+
def publish(destination, message, options={})
|
|
81
|
+
RosettaQueue.logger.info("Publishing to #{destination} :: #{message}")
|
|
82
|
+
conn.queue(destination, options).publish(message, options)
|
|
83
|
+
end
|
|
84
|
+
|
|
63
85
|
def receive(destination, message_handler)
|
|
64
|
-
|
|
86
|
+
conn.queue(destination, @options).subscribe(@options) do |msg|
|
|
65
87
|
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
66
88
|
message_handler.on_message(Filters.process_receiving(msg))
|
|
67
|
-
end
|
|
89
|
+
end
|
|
68
90
|
end
|
|
69
91
|
|
|
70
|
-
def receive_once(destination)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
yield Filters.process_receiving(msg)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
92
|
+
def receive_once(destination, options={})
|
|
93
|
+
msg = conn.queue(destination, options).pop(options)
|
|
94
|
+
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
95
|
+
yield Filters.process_receiving(msg)
|
|
77
96
|
end
|
|
78
97
|
end
|
|
79
98
|
|
|
80
|
-
|
|
81
99
|
class FanoutExchange < BaseExchange
|
|
82
|
-
|
|
83
|
-
def
|
|
84
|
-
|
|
85
|
-
exchange
|
|
86
|
-
|
|
87
|
-
queue.bind(exchange).subscribe(@options) do |msg|
|
|
88
|
-
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
89
|
-
message_handler.on_message(Filters.process_receiving(msg))
|
|
90
|
-
end
|
|
100
|
+
|
|
101
|
+
def fanout_name_for(destination)
|
|
102
|
+
fanout_name = destination.gsub(/fanout\/(.*)/, '\1')
|
|
103
|
+
raise "Unable to discover fanout exchange. Cannot bind queue to exchange!" unless fanout_name
|
|
104
|
+
fanout_name
|
|
91
105
|
end
|
|
92
106
|
|
|
93
|
-
def receive_once(destination)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
exchange = channel.fanout(fanout_name_for(destination))
|
|
107
|
+
def receive_once(destination, options={})
|
|
108
|
+
queue = conn.queue("queue_#{self.object_id}", options)
|
|
109
|
+
exchange = conn.fanout(fanout_name_for(destination), options)
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
end
|
|
102
|
-
end
|
|
111
|
+
msg = queue.bind(exchange).pop(@options)
|
|
112
|
+
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
113
|
+
yield Filters.process_receiving(msg)
|
|
103
114
|
end
|
|
104
115
|
|
|
105
|
-
|
|
116
|
+
def publish(destination, message, options={})
|
|
117
|
+
exchange = conn.fanout(fanout_name_for(destination), options)
|
|
118
|
+
exchange.publish(message, options)
|
|
119
|
+
RosettaQueue.logger.info("Publishing to fanout #{destination} :: #{message}")
|
|
120
|
+
end
|
|
106
121
|
|
|
107
|
-
def
|
|
108
|
-
|
|
109
|
-
exchange.
|
|
110
|
-
RosettaQueue.logger.info("Publishing to fanout #{dest} :: #{msg}")
|
|
111
|
-
end
|
|
122
|
+
def receive(destination, message_handler)
|
|
123
|
+
queue = conn.queue("queue_#{self.object_id}", @options)
|
|
124
|
+
exchange = conn.fanout(fanout_name_for(destination), @options)
|
|
112
125
|
|
|
113
|
-
|
|
126
|
+
msg = queue.bind(exchange).subscribe(@options) do |msg|
|
|
114
127
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
fanout_name
|
|
128
|
+
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
129
|
+
message_handler.on_message(Filters.process_receiving(msg))
|
|
130
|
+
end
|
|
119
131
|
end
|
|
120
|
-
end
|
|
132
|
+
end
|
|
121
133
|
end
|
|
122
134
|
end
|
|
123
135
|
end
|
|
@@ -10,13 +10,5 @@ module RosettaQueue
|
|
|
10
10
|
RosettaQueue.logger.error("Caught exception in Consumer#receive: #{$!}\n" + e.backtrace.join("\n\t"))
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
# def publish(message)
|
|
14
|
-
# begin
|
|
15
|
-
# connection.send_message(publish_destination, message, options)
|
|
16
|
-
# rescue Exception=>e
|
|
17
|
-
# RosettaQueue.logger.error("Caught exception in Producer#publish: #{$!}\n" + e.backtrace.join("\n\t"))
|
|
18
|
-
# end
|
|
19
|
-
# end
|
|
20
|
-
|
|
21
13
|
end
|
|
22
|
-
end
|
|
14
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module RosettaQueue
|
|
2
2
|
# Adds helpful methods when doing application level testing.
|
|
3
|
-
# If you are using cucumber just include it in your
|
|
3
|
+
# If you are using cucumber just include it in your World in the env.rb file:
|
|
4
4
|
# World {|world| world.extend RosettaQueue::SpecHelpers }
|
|
5
5
|
module SpecHelpers
|
|
6
6
|
require 'open-uri'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cwyckoff-rosetta_queue
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Mabey
|
|
@@ -31,9 +31,7 @@ files:
|
|
|
31
31
|
- lib/rosetta_queue
|
|
32
32
|
- lib/rosetta_queue/adapter.rb
|
|
33
33
|
- lib/rosetta_queue/adapters
|
|
34
|
-
- lib/rosetta_queue/adapters/amqp_base.rb
|
|
35
34
|
- lib/rosetta_queue/adapters/amqp.rb
|
|
36
|
-
- lib/rosetta_queue/adapters/amqp_carrot.rb
|
|
37
35
|
- lib/rosetta_queue/adapters/base.rb
|
|
38
36
|
- lib/rosetta_queue/adapters/fake.rb
|
|
39
37
|
- lib/rosetta_queue/adapters/null.rb
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module RosettaQueue
|
|
2
|
-
module Gateway
|
|
3
|
-
|
|
4
|
-
class AmqpBaseAdapter < BaseAdapter
|
|
5
|
-
|
|
6
|
-
def initialize(adapter_settings = {})
|
|
7
|
-
raise AdapterException, "Missing adapter settings" if adapter_settings.empty?
|
|
8
|
-
@adapter_settings = adapter_settings
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def delete(destination, opts={})
|
|
12
|
-
exchange_strategy_for(destination, opts).delete(destination)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def disconnect(message_handler); end
|
|
16
|
-
|
|
17
|
-
def receive_once(destination, opts={})
|
|
18
|
-
exchange_strategy_for(destination, opts).receive_once(destination) do |msg|
|
|
19
|
-
return msg
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def receive_with(message_handler)
|
|
24
|
-
options = options_for(message_handler)
|
|
25
|
-
destination = destination_for(message_handler)
|
|
26
|
-
exchange_strategy_for(destination, options).receive(destination, message_handler)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def send_message(destination, message, options=nil)
|
|
30
|
-
exchange_strategy_for(destination, options).publish(destination, message)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def unsubscribe; end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
require 'carrot'
|
|
2
|
-
|
|
3
|
-
module RosettaQueue
|
|
4
|
-
module Gateway
|
|
5
|
-
|
|
6
|
-
class AmqpCarrotAdapter < AmqpBaseAdapter
|
|
7
|
-
|
|
8
|
-
def exchange_strategy_for(destination, options)
|
|
9
|
-
case destination
|
|
10
|
-
when /fanout/
|
|
11
|
-
@exchange ||= CarrotExchangeStrategies::FanoutExchange.new(@adapter_settings, options)
|
|
12
|
-
when /queue/
|
|
13
|
-
@exchange ||= CarrotExchangeStrategies::DirectExchange.new(@adapter_settings, options)
|
|
14
|
-
else
|
|
15
|
-
@exchange ||= CarrotExchangeStrategies::DirectExchange.new(@adapter_settings, options)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
module CarrotExchangeStrategies
|
|
22
|
-
|
|
23
|
-
class BaseExchange
|
|
24
|
-
|
|
25
|
-
def initialize(adapter_settings, options={})
|
|
26
|
-
@adapter_settings, @options = adapter_settings, options
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def delete(destination)
|
|
30
|
-
conn.queue(destination).delete(@options)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
protected
|
|
34
|
-
def conn
|
|
35
|
-
vhost = @adapter_settings[:opts][:vhost] || "/"
|
|
36
|
-
@conn ||= Carrot.new(:user => @adapter_settings[:user],
|
|
37
|
-
:pass => @adapter_settings[:password],
|
|
38
|
-
:host => @adapter_settings[:host],
|
|
39
|
-
:vhost => vhost)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
class DirectExchange < BaseExchange
|
|
44
|
-
|
|
45
|
-
def publish(destination, message, options={})
|
|
46
|
-
RosettaQueue.logger.info("Publishing to #{destination} :: #{message}")
|
|
47
|
-
conn.queue(destination).publish(message, options)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def receive(destination, message_handler)
|
|
51
|
-
conn.queue(destination).subscribe(@options) do |msg|
|
|
52
|
-
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
53
|
-
message_handler.on_message(Filters.process_receiving(msg))
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def receive_once(destination)
|
|
58
|
-
msg = conn.queue(destination).pop(@options)
|
|
59
|
-
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
60
|
-
yield Filters.process_receiving(msg)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
class FanoutExchange < BaseExchange
|
|
65
|
-
|
|
66
|
-
def fanout_name_for(destination)
|
|
67
|
-
fanout_name = destination.gsub(/fanout\/(.*)/, '\1')
|
|
68
|
-
raise "Unable to discover fanout exchange. Cannot bind queue to exchange!" unless fanout_name
|
|
69
|
-
fanout_name
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def receive_once(destination)
|
|
73
|
-
queue = conn.queue("queue_#{self.object_id}")
|
|
74
|
-
exchange = conn.fanout(fanout_name_for(destination))
|
|
75
|
-
|
|
76
|
-
msg = queue.bind(exchange).pop(@options)
|
|
77
|
-
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
78
|
-
yield Filters.process_receiving(msg)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def publish(destination, message, options={})
|
|
82
|
-
exchange = conn.fanout(fanout_name_for(destination))
|
|
83
|
-
exchange.publish(message, @options)
|
|
84
|
-
RosettaQueue.logger.info("Publishing to fanout #{destination} :: #{message}")
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def receive(destination, message_handler)
|
|
88
|
-
queue = conn.queue("queue_#{self.object_id}")
|
|
89
|
-
exchange = conn.fanout(fanout_name_for(destination))
|
|
90
|
-
|
|
91
|
-
msg = queue.bind(exchange).subscribe(@options) do |msg|
|
|
92
|
-
|
|
93
|
-
RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
|
|
94
|
-
message_handler.on_message(Filters.process_receiving(msg))
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|