message-driver 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rbenv-version +1 -0
- data/.relish +2 -0
- data/.rspec +2 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +20 -0
- data/Guardfile +39 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +23 -0
- data/features/.nav +12 -0
- data/features/CHANGELOG.md +17 -0
- data/features/README.md +1 -0
- data/features/Rails.md +1 -0
- data/features/amqp_specific_features/README.md +3 -0
- data/features/amqp_specific_features/binding_amqp_destinations.feature +50 -0
- data/features/amqp_specific_features/declaring_amqp_exchanges.feature +22 -0
- data/features/amqp_specific_features/server_named_destinations.feature +35 -0
- data/features/destination_metadata.feature +33 -0
- data/features/dynamic_destinations.feature +41 -0
- data/features/error_handling.feature +47 -0
- data/features/getting_started.md +1 -0
- data/features/publishing_a_message.feature +19 -0
- data/features/publishing_with_transactions.feature +36 -0
- data/features/step_definitions/dynamic_destinations_steps.rb +12 -0
- data/features/step_definitions/error_handling_steps.rb +11 -0
- data/features/step_definitions/steps.rb +41 -0
- data/features/support/env.rb +7 -0
- data/features/support/firewall_helper.rb +59 -0
- data/features/support/message_table_matcher.rb +11 -0
- data/features/support/no_error_matcher.rb +13 -0
- data/features/support/test_runner.rb +50 -0
- data/features/support/transforms.rb +17 -0
- data/lib/message-driver.rb +1 -0
- data/lib/message_driver/adapters/base.rb +29 -0
- data/lib/message_driver/adapters/bunny_adapter.rb +270 -0
- data/lib/message_driver/adapters/in_memory_adapter.rb +58 -0
- data/lib/message_driver/broker.rb +95 -0
- data/lib/message_driver/destination.rb +31 -0
- data/lib/message_driver/exceptions.rb +18 -0
- data/lib/message_driver/message.rb +13 -0
- data/lib/message_driver/message_publisher.rb +15 -0
- data/lib/message_driver/version.rb +5 -0
- data/lib/message_driver.rb +18 -0
- data/message-driver.gemspec +27 -0
- data/spec/integration/amqp_integration_spec.rb +146 -0
- data/spec/integration/message_driver/adapters/bunny_adapter_spec.rb +301 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/shared/destination_examples.rb +41 -0
- data/spec/units/message_driver/adapters/base_spec.rb +44 -0
- data/spec/units/message_driver/adapters/in_memory_adapter_spec.rb +43 -0
- data/spec/units/message_driver/broker_spec.rb +98 -0
- data/spec/units/message_driver/destination_spec.rb +11 -0
- data/spec/units/message_driver/message_publisher_spec.rb +65 -0
- data/spec/units/message_driver/message_spec.rb +19 -0
- data/test_lib/broker_config.rb +25 -0
- metadata +203 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'message_driver/adapters/in_memory_adapter'
|
3
|
+
|
4
|
+
module MessageDriver
|
5
|
+
describe Broker do
|
6
|
+
subject(:broker) { described_class.new(adapter: :in_memory) }
|
7
|
+
|
8
|
+
describe ".configure" do
|
9
|
+
it "calls new, passing in the options and saves the instance" do
|
10
|
+
options = {foo: :bar}
|
11
|
+
result = stub(described_class)
|
12
|
+
described_class.should_receive(:new).with(options).and_return(result)
|
13
|
+
|
14
|
+
described_class.configure(options)
|
15
|
+
|
16
|
+
expect(described_class.instance).to be result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
it "raises an error if you don't specify an adapter" do
|
22
|
+
expect {
|
23
|
+
described_class.new({})
|
24
|
+
}.to raise_error(/must specify an adapter/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "if you provide an adapter instance, it uses that one" do
|
28
|
+
adapter = Adapters::InMemoryAdapter.new({})
|
29
|
+
|
30
|
+
instance = described_class.new(adapter: adapter)
|
31
|
+
expect(instance.adapter).to be adapter
|
32
|
+
end
|
33
|
+
|
34
|
+
it "if you provide an adapter class, it will instansiate it" do
|
35
|
+
adapter = Adapters::InMemoryAdapter
|
36
|
+
|
37
|
+
instance = described_class.new(adapter: adapter)
|
38
|
+
expect(instance.adapter).to be_a adapter
|
39
|
+
end
|
40
|
+
|
41
|
+
it "if you provide a symbol, it will try to look up the adapter class" do
|
42
|
+
adapter = :in_memory
|
43
|
+
|
44
|
+
instance = described_class.new(adapter: adapter)
|
45
|
+
expect(instance.adapter).to be_a Adapters::InMemoryAdapter
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises and error if you don't provide a MessageDriver::Adapters::Base" do
|
49
|
+
adapter = Hash.new
|
50
|
+
|
51
|
+
expect {
|
52
|
+
described_class.new(adapter: adapter)
|
53
|
+
}.to raise_error(/adapter must be a MessageDriver::Adapters::Base/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#configuration" do
|
58
|
+
it "returns the configuration hash you passed to .configure" do
|
59
|
+
config = {adapter: :in_memory, foo: :bar, baz: :boz}
|
60
|
+
instance = described_class.new(config)
|
61
|
+
expect(instance.configuration).to be config
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#publish" do
|
66
|
+
it "needs some real tests"
|
67
|
+
|
68
|
+
context "when the destination can't be found" do
|
69
|
+
it "raises an error"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
describe "#pop_message" do
|
73
|
+
it "needs some real tests"
|
74
|
+
|
75
|
+
context "when the destination can't be found" do
|
76
|
+
it "raises an error"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#destination" do
|
81
|
+
it "needs some real tests"
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#dynamic_destination" do
|
85
|
+
it "returns the destination" do
|
86
|
+
destination = broker.dynamic_destination("my_queue", exclusive: true)
|
87
|
+
expect(destination).to be_a MessageDriver::Destination::Base
|
88
|
+
end
|
89
|
+
it "doesn't save the destination" do
|
90
|
+
destination = nil
|
91
|
+
expect {
|
92
|
+
destination = broker.dynamic_destination("my_queue", exclusive: true)
|
93
|
+
}.to_not change{broker.destinations.size}
|
94
|
+
expect(broker.destinations.values).to_not include(destination)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'message_driver/adapters/in_memory_adapter'
|
4
|
+
|
5
|
+
module MessageDriver
|
6
|
+
describe MessageDriver::MessagePublisher do
|
7
|
+
class TestPublisher
|
8
|
+
include MessageDriver::MessagePublisher
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:adapter) { Adapters::InMemoryAdapter.new }
|
12
|
+
before do
|
13
|
+
MessageDriver.configure(adapter: adapter)
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { TestPublisher.new }
|
17
|
+
|
18
|
+
describe "#publish" do
|
19
|
+
let(:destination) { "my_queue" }
|
20
|
+
let(:body) { "my message body" }
|
21
|
+
|
22
|
+
it "only requires destination and body" do
|
23
|
+
Broker.instance.should_receive(:publish).with(destination, body, {}, {})
|
24
|
+
|
25
|
+
subject.publish(destination, body)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:headers) { {foo: :bar} }
|
29
|
+
let(:properties) { {bar: :baz} }
|
30
|
+
|
31
|
+
it "also passes through the headers and properties" do
|
32
|
+
Broker.instance.should_receive(:publish).with(destination, body, headers, properties)
|
33
|
+
|
34
|
+
subject.publish(destination, body, headers, properties)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#pop_message" do
|
39
|
+
let(:destination) { "my_queue" }
|
40
|
+
let(:expected) { stub(MessageDriver::Message) }
|
41
|
+
|
42
|
+
it "requires the destination and returns the message" do
|
43
|
+
Broker.instance.should_receive(:pop_message).with(destination, {}).and_return(expected)
|
44
|
+
|
45
|
+
actual = subject.pop_message(destination)
|
46
|
+
|
47
|
+
expect(actual).to be expected
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:options) { {foo: :bar} }
|
51
|
+
|
52
|
+
it "passes the options through and returns the message" do
|
53
|
+
Broker.instance.should_receive(:pop_message).with(destination, options).and_return(expected)
|
54
|
+
|
55
|
+
actual = subject.pop_message(destination, options)
|
56
|
+
|
57
|
+
expect(actual).to be expected
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#with_message_transaction" do
|
62
|
+
it "needs some real tests"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MessageDriver::Message
|
4
|
+
describe Base do
|
5
|
+
describe "#initialize" do
|
6
|
+
let(:body) { "The message body" }
|
7
|
+
let(:headers) { { foo: :bar, bar: :baz} }
|
8
|
+
let(:properties) { {persistent: true, client_ack: true} }
|
9
|
+
|
10
|
+
context "sets the body, header and properites on initialization" do
|
11
|
+
subject { described_class.new(body, headers, properties) }
|
12
|
+
|
13
|
+
its(:body) { should eq(body) }
|
14
|
+
its(:headers) { should eq(headers) }
|
15
|
+
its(:properties) { should eq(properties) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BrokerConfig
|
2
|
+
def self.config
|
3
|
+
adapter_file = File.expand_path("../../.adapter_under_test", __FILE__)
|
4
|
+
adapter = ENV['ADAPTER'] || (File.exist?(adapter_file) && File.read(adapter_file).chomp)
|
5
|
+
case adapter
|
6
|
+
when 'bunny'
|
7
|
+
{
|
8
|
+
adapter: :bunny,
|
9
|
+
vhost: 'message-driver-test'
|
10
|
+
}
|
11
|
+
when 'in_memory'
|
12
|
+
{adapter: :in_memory}
|
13
|
+
else
|
14
|
+
{adapter: :in_memory}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.current_adapter
|
19
|
+
config[:adapter]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.unconfigured_adapters
|
23
|
+
%w(bunny in_memory) - current_adapter
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: message-driver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Campbell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.13.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.13.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cucumber
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bunny
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.0.pre7
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.9.0.pre7
|
78
|
+
description: Easy message queues for ruby using AMQ, STOMP and others
|
79
|
+
email:
|
80
|
+
- matt@soupmatt.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rbenv-version
|
87
|
+
- .relish
|
88
|
+
- .rspec
|
89
|
+
- .travis.yml
|
90
|
+
- CHANGELOG.md
|
91
|
+
- Gemfile
|
92
|
+
- Guardfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- features/.nav
|
97
|
+
- features/CHANGELOG.md
|
98
|
+
- features/README.md
|
99
|
+
- features/Rails.md
|
100
|
+
- features/amqp_specific_features/README.md
|
101
|
+
- features/amqp_specific_features/binding_amqp_destinations.feature
|
102
|
+
- features/amqp_specific_features/declaring_amqp_exchanges.feature
|
103
|
+
- features/amqp_specific_features/server_named_destinations.feature
|
104
|
+
- features/destination_metadata.feature
|
105
|
+
- features/dynamic_destinations.feature
|
106
|
+
- features/error_handling.feature
|
107
|
+
- features/getting_started.md
|
108
|
+
- features/publishing_a_message.feature
|
109
|
+
- features/publishing_with_transactions.feature
|
110
|
+
- features/step_definitions/dynamic_destinations_steps.rb
|
111
|
+
- features/step_definitions/error_handling_steps.rb
|
112
|
+
- features/step_definitions/steps.rb
|
113
|
+
- features/support/env.rb
|
114
|
+
- features/support/firewall_helper.rb
|
115
|
+
- features/support/message_table_matcher.rb
|
116
|
+
- features/support/no_error_matcher.rb
|
117
|
+
- features/support/test_runner.rb
|
118
|
+
- features/support/transforms.rb
|
119
|
+
- lib/message-driver.rb
|
120
|
+
- lib/message_driver.rb
|
121
|
+
- lib/message_driver/adapters/base.rb
|
122
|
+
- lib/message_driver/adapters/bunny_adapter.rb
|
123
|
+
- lib/message_driver/adapters/in_memory_adapter.rb
|
124
|
+
- lib/message_driver/broker.rb
|
125
|
+
- lib/message_driver/destination.rb
|
126
|
+
- lib/message_driver/exceptions.rb
|
127
|
+
- lib/message_driver/message.rb
|
128
|
+
- lib/message_driver/message_publisher.rb
|
129
|
+
- lib/message_driver/version.rb
|
130
|
+
- message-driver.gemspec
|
131
|
+
- spec/integration/amqp_integration_spec.rb
|
132
|
+
- spec/integration/message_driver/adapters/bunny_adapter_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/support/shared/destination_examples.rb
|
135
|
+
- spec/units/message_driver/adapters/base_spec.rb
|
136
|
+
- spec/units/message_driver/adapters/in_memory_adapter_spec.rb
|
137
|
+
- spec/units/message_driver/broker_spec.rb
|
138
|
+
- spec/units/message_driver/destination_spec.rb
|
139
|
+
- spec/units/message_driver/message_publisher_spec.rb
|
140
|
+
- spec/units/message_driver/message_spec.rb
|
141
|
+
- test_lib/broker_config.rb
|
142
|
+
homepage: https://github.com/soupmatt/message_driver
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 1.9.2
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
hash: 1747639069992114351
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.8.23
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Easy message queues for ruby
|
170
|
+
test_files:
|
171
|
+
- features/.nav
|
172
|
+
- features/CHANGELOG.md
|
173
|
+
- features/README.md
|
174
|
+
- features/Rails.md
|
175
|
+
- features/amqp_specific_features/README.md
|
176
|
+
- features/amqp_specific_features/binding_amqp_destinations.feature
|
177
|
+
- features/amqp_specific_features/declaring_amqp_exchanges.feature
|
178
|
+
- features/amqp_specific_features/server_named_destinations.feature
|
179
|
+
- features/destination_metadata.feature
|
180
|
+
- features/dynamic_destinations.feature
|
181
|
+
- features/error_handling.feature
|
182
|
+
- features/getting_started.md
|
183
|
+
- features/publishing_a_message.feature
|
184
|
+
- features/publishing_with_transactions.feature
|
185
|
+
- features/step_definitions/dynamic_destinations_steps.rb
|
186
|
+
- features/step_definitions/error_handling_steps.rb
|
187
|
+
- features/step_definitions/steps.rb
|
188
|
+
- features/support/env.rb
|
189
|
+
- features/support/firewall_helper.rb
|
190
|
+
- features/support/message_table_matcher.rb
|
191
|
+
- features/support/no_error_matcher.rb
|
192
|
+
- features/support/test_runner.rb
|
193
|
+
- features/support/transforms.rb
|
194
|
+
- spec/integration/amqp_integration_spec.rb
|
195
|
+
- spec/integration/message_driver/adapters/bunny_adapter_spec.rb
|
196
|
+
- spec/spec_helper.rb
|
197
|
+
- spec/support/shared/destination_examples.rb
|
198
|
+
- spec/units/message_driver/adapters/base_spec.rb
|
199
|
+
- spec/units/message_driver/adapters/in_memory_adapter_spec.rb
|
200
|
+
- spec/units/message_driver/broker_spec.rb
|
201
|
+
- spec/units/message_driver/destination_spec.rb
|
202
|
+
- spec/units/message_driver/message_publisher_spec.rb
|
203
|
+
- spec/units/message_driver/message_spec.rb
|