rosetta_queue 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -24,6 +24,7 @@ begin
24
24
  s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
25
25
  s.files = FileList["[A-Z]*.*", "{bin,generators,lib,features,spec}/**/*", "Rakefile", "cucumber.yml"]
26
26
  s.authors = ["Ben Mabey", "Chris Wyckoff"]
27
+ s.add_dependency("bunny")
27
28
  end
28
29
  rescue LoadError
29
30
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -36,4 +37,3 @@ desc 'Removes trailing whitespace'
36
37
  task :whitespace do
37
38
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
38
39
  end
39
-
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :build:
5
- :patch: 0
4
+ :patch: 2
5
+ :build:
@@ -14,9 +14,4 @@ require 'rosetta_queue/exception_handler'
14
14
  require 'rosetta_queue/producer'
15
15
  require 'rosetta_queue/consumer_managers/base'
16
16
  require 'rosetta_queue/consumer_managers/threaded'
17
-
18
- if defined?(Rails)
19
- RosettaQueue.logger = RosettaQueue::Logger.new(File.join(Rails.root, 'log', 'rosetta_queue.log'))
20
- require('rosetta_queue/spec_helpers') if Rails.env == "test"
21
- end
22
-
17
+ require 'rosetta_queue/railtie' if defined?(Rails)
@@ -17,7 +17,6 @@ module RosettaQueue
17
17
  end
18
18
 
19
19
  def unsubscribe
20
- @queue.unsubscribe
21
20
  conn.stop
22
21
  end
23
22
 
@@ -40,23 +39,22 @@ module RosettaQueue
40
39
  def publish(destination, message, options={})
41
40
  RosettaQueue.logger.info("Publishing to #{destination} :: #{message}")
42
41
  @queue = conn.queue(destination, options)
43
- @queue.publish(message, options)
42
+ exchange = conn.exchange("")
43
+ exchange.publish(message, {:key => destination}.merge(options))
44
44
  end
45
45
 
46
46
  def receive(destination, message_handler)
47
- ack = @options[:ack]
48
47
  @queue = conn.queue(destination, @options)
49
48
  @queue.subscribe(@options) do |msg|
50
- RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
51
- message_handler.handle_message(msg)
52
- @queue.ack if ack
49
+ RosettaQueue.logger.info("Receiving from #{destination} :: #{msg[:payload]}")
50
+ message_handler.handle_message(msg[:payload])
53
51
  end
54
52
  end
55
53
 
56
54
  def receive_once(destination, options = {})
57
55
  ack = options[:ack]
58
56
  @queue = conn.queue(destination, options)
59
- msg = @queue.pop(options)
57
+ msg = @queue.pop[:payload]
60
58
  RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
61
59
  @queue.ack if ack
62
60
  yield Filters.process_receiving(msg)
@@ -74,14 +72,12 @@ module RosettaQueue
74
72
  end
75
73
 
76
74
  def receive(destination, message_handler)
77
- ack = @options[:ack]
78
75
  @queue = conn.queue("queue_#{self.object_id}", @options)
79
76
  exchange = conn.exchange(fanout_name_for(destination), @options.merge({:type => :fanout}))
80
77
  @queue.bind(exchange)
81
78
  @queue.subscribe(@options) do |msg|
82
- RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
83
- message_handler.handle_message(msg)
84
- @queue.ack if ack
79
+ RosettaQueue.logger.info("Receiving from #{destination} :: #{msg[:payload]}")
80
+ message_handler.handle_message(msg[:payload])
85
81
  end
86
82
  end
87
83
 
@@ -90,7 +86,7 @@ module RosettaQueue
90
86
  @queue = conn.queue("queue_#{self.object_id}", options)
91
87
  exchange = conn.exchange(fanout_name_for(destination), options.merge({:type => :fanout}))
92
88
  @queue.bind(exchange)
93
- msg = @queue.pop(options)
89
+ msg = @queue.pop[:payload]
94
90
  RosettaQueue.logger.info("Receiving from #{destination} :: #{msg}")
95
91
  @queue.ack if ack
96
92
  yield Filters.process_receiving(msg)
@@ -0,0 +1,6 @@
1
+ class RosettaQueueRailtie < Rails::Railtie
2
+ initializer "rosetta_queue" do
3
+ RosettaQueue.logger = RosettaQueue::Logger.new(File.join(Rails.root, 'log', 'rosetta_queue.log'))
4
+ require('rosetta_queue/spec_helpers') if Rails.env == "test"
5
+ end
6
+ end
@@ -32,7 +32,7 @@ module RosettaQueue::Gateway
32
32
 
33
33
  before(:each) do
34
34
  RosettaQueue.logger.stub!(:info)
35
- @msg = "Hello World!"
35
+ @msg = {:payload => "Hello World!"}
36
36
  @adapter = AmqpSynchAdapter.new({:user => "foo", :password => "bar", :host => "localhost"})
37
37
  @handler = mock("handler", :handle_message => true, :destination => :foo, :options_hash => {:durable => true})
38
38
  end
@@ -93,7 +93,7 @@ module RosettaQueue::Gateway
93
93
  it "delegates to cached exchange strategy" do
94
94
  # given
95
95
  @adapter.receive_with(@handler)
96
-
96
+
97
97
  # expect
98
98
  @exchange_strategy.should_receive(:unsubscribe)
99
99
 
@@ -115,12 +115,13 @@ module RosettaQueue::Gateway
115
115
 
116
116
  end
117
117
  end
118
-
118
+
119
119
  describe SynchExchange::DirectExchange do
120
120
 
121
121
  before(:each) do
122
+ mock_exchange = mock("SynchExchange::DirectExchange", :publish => true)
122
123
  @queue = mock("Bunny::Queue", :pop => @msg, :publish => true, :unsubscribe => true)
123
- Bunny.stub!(:new).and_return(@conn = mock("Bunny::Client", :queue => @queue, :exchange => @exchange, :status => :connected, :stop => nil))
124
+ Bunny.stub!(:new).and_return(@conn = mock("Bunny::Client", :queue => @queue, :exchange => mock_exchange, :status => :connected, :stop => nil))
124
125
  @queue.stub!(:subscribe).and_yield(@msg)
125
126
  @handler = mock("handler", :handle_message => true, :destination => :foo)
126
127
  @exchange = SynchExchange::DirectExchange.new({:user => 'user', :password => 'pass', :host => 'host', :opts => {:vhost => "foo"}})
@@ -142,7 +143,7 @@ module RosettaQueue::Gateway
142
143
 
143
144
  it "should return the message from the connection" do
144
145
  @exchange.receive_once("queue.foo") do |msg|
145
- msg.should == @msg
146
+ msg.should == @msg[:payload]
146
147
  end
147
148
  end
148
149
 
@@ -177,9 +178,9 @@ module RosettaQueue::Gateway
177
178
  }
178
179
  end
179
180
 
180
- it "should publish message to queue" do
181
+ it "should publish message to exchange" do
181
182
  when_publishing {
182
- @conn.queue.should_receive(:publish).with("message", {})
183
+ @conn.exchange.should_receive(:publish).with("message", {:key => "queue.foo"})
183
184
  }
184
185
  end
185
186
 
@@ -214,7 +215,7 @@ module RosettaQueue::Gateway
214
215
 
215
216
  it "should return the message from the connection" do
216
217
  @exchange.receive_once("topic.foo") do |msg|
217
- msg.should == @msg
218
+ msg.should == @msg[:payload]
218
219
  end
219
220
  end
220
221
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rosetta_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 2
10
+ version: 0.5.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Ben Mabey
@@ -10,10 +16,22 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2009-12-21 00:00:00 -07:00
14
- default_executable:
15
- dependencies: []
16
-
19
+ date: 2012-11-05 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bunny
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
17
35
  description: Messaging gateway API with adapters for many messaging systems available in Ruby. Messaging systems can be easily switched out with a small configuration change. Code for testing on the object and application level is also provided.
18
36
  email: cbwyckoff@gmail.com
19
37
  executables: []
@@ -38,10 +56,6 @@ files:
38
56
  - features/step_definitions/publish_subscribe_steps.rb
39
57
  - features/support/env.rb
40
58
  - features/support/sample_consumers.rb
41
- - features/support/tmp/barconsumer.log
42
- - features/support/tmp/fooconsumer.log
43
- - features/support/tmp/point-to-point.log
44
- - features/support/tmp/pub-sub.log
45
59
  - lib/rosetta_queue.rb
46
60
  - lib/rosetta_queue/adapter.rb
47
61
  - lib/rosetta_queue/adapters/amqp.rb
@@ -65,6 +79,7 @@ files:
65
79
  - lib/rosetta_queue/logger.rb
66
80
  - lib/rosetta_queue/message_handler.rb
67
81
  - lib/rosetta_queue/producer.rb
82
+ - lib/rosetta_queue/railtie.rb
68
83
  - lib/rosetta_queue/spec_helpers.rb
69
84
  - lib/rosetta_queue/spec_helpers/hash.rb
70
85
  - lib/rosetta_queue/spec_helpers/helpers.rb
@@ -90,56 +105,38 @@ files:
90
105
  - spec/rosetta_queue/producer_spec.rb
91
106
  - spec/spec.opts
92
107
  - spec/spec_helper.rb
93
- has_rdoc: true
94
108
  homepage: http://github.com/cwyckoff/rosetta_queue
95
109
  licenses: []
96
110
 
97
111
  post_install_message:
98
- rdoc_options:
99
- - --charset=UTF-8
112
+ rdoc_options: []
113
+
100
114
  require_paths:
101
115
  - lib
102
116
  required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
103
118
  requirements:
104
119
  - - ">="
105
120
  - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
106
124
  version: "0"
107
- version:
108
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
109
127
  requirements:
110
128
  - - ">="
111
129
  - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
112
133
  version: "0"
113
- version:
114
134
  requirements: []
115
135
 
116
136
  rubyforge_project: rosetta-queue
117
- rubygems_version: 1.3.5
137
+ rubygems_version: 1.8.24
118
138
  signing_key:
119
139
  specification_version: 3
120
140
  summary: Messaging gateway API with adapters for many messaging systems available in Ruby.
121
- test_files:
122
- - spec/rosetta_queue/adapter_spec.rb
123
- - spec/rosetta_queue/adapters/amqp_synchronous_spec.rb
124
- - spec/rosetta_queue/adapters/beanstalk_spec.rb
125
- - spec/rosetta_queue/adapters/fake_spec.rb
126
- - spec/rosetta_queue/adapters/null_spec.rb
127
- - spec/rosetta_queue/adapters/shared_adapter_behavior.rb
128
- - spec/rosetta_queue/adapters/shared_fanout_behavior.rb
129
- - spec/rosetta_queue/adapters/stomp_spec.rb
130
- - spec/rosetta_queue/consumer_managers/base_spec.rb
131
- - spec/rosetta_queue/consumer_managers/evented_spec.rb
132
- - spec/rosetta_queue/consumer_managers/shared_manager_behavior.rb
133
- - spec/rosetta_queue/consumer_managers/threaded_spec.rb
134
- - spec/rosetta_queue/consumer_spec.rb
135
- - spec/rosetta_queue/core_ext/string_spec.rb
136
- - spec/rosetta_queue/destinations_spec.rb
137
- - spec/rosetta_queue/exception_handler_spec.rb
138
- - spec/rosetta_queue/filters_spec.rb
139
- - spec/rosetta_queue/message_handler_spec.rb
140
- - spec/rosetta_queue/producer_spec.rb
141
- - spec/spec_helper.rb
142
- - examples/sample_amqp_consumer.rb
143
- - examples/sample_amqp_fanout_consumer.rb
144
- - examples/sample_amqp_fanout_producer.rb
145
- - examples/sample_amqp_producer.rb
141
+ test_files: []
142
+
@@ -1,45 +0,0 @@
1
- require 'rubygems'
2
- require File.dirname(__FILE__) + '/../init.rb'
3
- require File.expand_path(File.dirname(__FILE__) + '/../lib/rosetta_queue/consumer_managers/threaded')
4
- RosettaQueue.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + '/../../log/rosetta_queue.log'))
5
-
6
- module RosettaQueue
7
-
8
- Adapter.define do |a|
9
- a.user = "rosetta"
10
- a.password = "password"
11
- a.host = "localhost"
12
- a.type = 'amqp_synch'
13
- end
14
-
15
- Destinations.define do |dest|
16
- dest.map :foo, "queue.foo"
17
- end
18
-
19
- class MessageHandlerFoo
20
- include RosettaQueue::MessageHandler
21
- subscribes_to :foo
22
- options :ack => true
23
- attr_reader :msg
24
-
25
- def on_message(msg)
26
- puts "FOO received message: #{msg}"
27
- end
28
-
29
- end
30
-
31
- # consumer = RosettaQueue::Consumer.new(MessageHandlerFoo.new)
32
- # # Thread.new(consumer) do |cons|
33
- # consumer.receive
34
- # # end
35
- # puts "sleeping for 10"
36
- # sleep 10
37
- # puts "shutting consumer down"
38
- # consumer.disconnect
39
-
40
- ThreadedManager.create do |m|
41
- m.add MessageHandlerFoo.new
42
- m.start
43
- end
44
-
45
- end
@@ -1,52 +0,0 @@
1
- require 'rubygems'
2
- require File.dirname(__FILE__) + '/../init.rb'
3
- require File.expand_path(File.dirname(__FILE__) + '/../lib/rosetta_queue/consumer_managers/threaded.rb')
4
- RosettaQueue.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + '/../../log/rosetta_queue.log'))
5
-
6
- module RosettaQueue
7
-
8
- Adapter.define do |a|
9
- a.user = "rosetta"
10
- a.password = "password"
11
- a.host = "localhost"
12
- a.type = 'amqp_synch'
13
- end
14
-
15
- Destinations.define do |dest|
16
- dest.map :foo, "fanout.foo"
17
- end
18
-
19
- class MessageHandlerFoo
20
- include RosettaQueue::MessageHandler
21
- subscribes_to :foo
22
- options :ack => true
23
- attr_reader :msg
24
-
25
- def on_message(msg)
26
- puts "FOO received message: #{msg}"
27
- ack
28
- end
29
-
30
- end
31
-
32
- class MessageHandlerBar
33
- include RosettaQueue::MessageHandler
34
- subscribes_to :foo
35
- options :ack => true
36
- attr_reader :msg
37
-
38
- def on_message(msg)
39
- puts "BAR received message: #{msg}"
40
- ack
41
- end
42
- end
43
-
44
-
45
- # threaded version
46
- ThreadedManager.create do |m|
47
- m.add MessageHandlerFoo.new
48
- m.add MessageHandlerBar.new
49
- m.start
50
- end
51
-
52
- end
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require File.dirname(__FILE__) + '/../init.rb'
3
- RosettaQueue.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + '/../../log/rosetta_queue.log'))
4
-
5
- RosettaQueue::Adapter.define do |a|
6
- a.user = "rosetta"
7
- a.password = "password"
8
- a.host = "localhost"
9
- a.type = "amqp_synch"
10
- end
11
-
12
- RosettaQueue::Destinations.define do |dest|
13
- dest.map :foo, "fanout.foo"
14
- end
15
-
16
-
17
- RosettaQueue::Producer.publish(:foo, "hello there")
18
-
@@ -1,16 +0,0 @@
1
- require 'rubygems'
2
- require File.dirname(__FILE__) + '/../init.rb'
3
- RosettaQueue.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + '/../../log/rosetta_queue.log'))
4
-
5
- RosettaQueue::Adapter.define do |a|
6
- a.user = "rosetta"
7
- a.password = "password"
8
- a.host = "localhost"
9
- a.type = "amqp_synch"
10
- end
11
-
12
- RosettaQueue::Destinations.define do |dest|
13
- dest.map :foo, "queue.foo"
14
- end
15
-
16
- RosettaQueue::Producer.publish(:foo, "hello there")
File without changes
File without changes
File without changes
File without changes