message-driver 0.1.0 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +18 -7
  4. data/CHANGELOG.md +12 -2
  5. data/Gemfile +17 -0
  6. data/Guardfile +8 -4
  7. data/README.md +14 -5
  8. data/Rakefile +44 -11
  9. data/examples/basic_producer_and_consumer/Gemfile +5 -0
  10. data/examples/basic_producer_and_consumer/common.rb +17 -0
  11. data/examples/basic_producer_and_consumer/consumer.rb +24 -0
  12. data/examples/basic_producer_and_consumer/producer.rb +33 -0
  13. data/features/.nav +8 -0
  14. data/features/CHANGELOG.md +12 -2
  15. data/features/amqp_specific_features/binding_amqp_destinations.feature +7 -7
  16. data/features/amqp_specific_features/declaring_amqp_exchanges.feature +3 -3
  17. data/features/amqp_specific_features/nack_redelivered_messages.feature +92 -0
  18. data/features/amqp_specific_features/requeueing_on_nack.feature +44 -0
  19. data/features/amqp_specific_features/server_named_destinations.feature +5 -5
  20. data/features/client_acks.feature +92 -0
  21. data/features/destination_metadata.feature +9 -11
  22. data/features/dynamic_destinations.feature +7 -7
  23. data/features/error_handling.feature +11 -9
  24. data/features/logging.feature +14 -0
  25. data/features/message_consumers/auto_ack_consumers.feature +79 -0
  26. data/features/message_consumers/manual_ack_consumers.feature +95 -0
  27. data/features/message_consumers/transactional_ack_consumers.feature +77 -0
  28. data/features/message_consumers.feature +54 -0
  29. data/features/publishing_a_message.feature +6 -10
  30. data/features/publishing_with_transactions.feature +10 -14
  31. data/features/rabbitmq_specific_features/dead_letter_queueing.feature +116 -0
  32. data/features/step_definitions/dynamic_destinations_steps.rb +3 -3
  33. data/features/step_definitions/error_handling_steps.rb +4 -2
  34. data/features/step_definitions/logging_steps.rb +28 -0
  35. data/features/step_definitions/message_consumers_steps.rb +29 -0
  36. data/features/step_definitions/steps.rb +60 -9
  37. data/features/support/broker_config_helper.rb +19 -0
  38. data/features/support/env.rb +1 -0
  39. data/features/support/firewall_helper.rb +8 -11
  40. data/features/support/message_table_matcher.rb +21 -5
  41. data/features/support/test_runner.rb +39 -16
  42. data/lib/message_driver/adapters/base.rb +51 -4
  43. data/lib/message_driver/adapters/bunny_adapter.rb +251 -127
  44. data/lib/message_driver/adapters/in_memory_adapter.rb +97 -18
  45. data/lib/message_driver/adapters/stomp_adapter.rb +127 -0
  46. data/lib/message_driver/broker.rb +23 -24
  47. data/lib/message_driver/client.rb +157 -0
  48. data/lib/message_driver/destination.rb +7 -4
  49. data/lib/message_driver/errors.rb +27 -0
  50. data/lib/message_driver/logging.rb +11 -0
  51. data/lib/message_driver/message.rb +8 -0
  52. data/lib/message_driver/subscription.rb +18 -0
  53. data/lib/message_driver/vendor/.document +0 -0
  54. data/lib/message_driver/vendor/nesty/nested_error.rb +26 -0
  55. data/lib/message_driver/vendor/nesty.rb +1 -0
  56. data/lib/message_driver/version.rb +1 -1
  57. data/lib/message_driver.rb +4 -2
  58. data/message-driver.gemspec +4 -4
  59. data/spec/integration/{amqp_integration_spec.rb → bunny/amqp_integration_spec.rb} +29 -28
  60. data/spec/integration/bunny/bunny_adapter_spec.rb +339 -0
  61. data/spec/integration/in_memory/in_memory_adapter_spec.rb +126 -0
  62. data/spec/integration/stomp/stomp_adapter_spec.rb +142 -0
  63. data/spec/spec_helper.rb +5 -2
  64. data/spec/support/shared/adapter_examples.rb +17 -0
  65. data/spec/support/shared/client_ack_examples.rb +18 -0
  66. data/spec/support/shared/context_examples.rb +14 -0
  67. data/spec/support/shared/destination_examples.rb +4 -5
  68. data/spec/support/shared/subscription_examples.rb +146 -0
  69. data/spec/support/shared/transaction_examples.rb +43 -0
  70. data/spec/support/utils.rb +14 -0
  71. data/spec/units/message_driver/adapters/base_spec.rb +38 -19
  72. data/spec/units/message_driver/broker_spec.rb +71 -18
  73. data/spec/units/message_driver/client_spec.rb +375 -0
  74. data/spec/units/message_driver/destination_spec.rb +9 -0
  75. data/spec/units/message_driver/logging_spec.rb +18 -0
  76. data/spec/units/message_driver/message_spec.rb +36 -0
  77. data/spec/units/message_driver/subscription_spec.rb +24 -0
  78. data/test_lib/broker_config.rb +50 -20
  79. metadata +83 -45
  80. data/.rbenv-version +0 -1
  81. data/lib/message_driver/exceptions.rb +0 -18
  82. data/lib/message_driver/message_publisher.rb +0 -15
  83. data/spec/integration/message_driver/adapters/bunny_adapter_spec.rb +0 -301
  84. data/spec/units/message_driver/adapters/in_memory_adapter_spec.rb +0 -43
  85. data/spec/units/message_driver/message_publisher_spec.rb +0 -65
metadata CHANGED
@@ -1,89 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0.rc1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Campbell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 2.13.0
33
+ version: 2.14.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 2.13.0
40
+ version: 2.14.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: cucumber
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
- name: bunny
56
+ name: aruba
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
- version: 0.9.0.pre7
61
+ version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
- version: 0.9.0.pre7
68
+ version: '0'
78
69
  description: Easy message queues for ruby using AMQ, STOMP and others
79
70
  email:
80
- - matt@soupmatt.com
71
+ - message-driver@soupmatt.com
81
72
  executables: []
82
73
  extensions: []
83
74
  extra_rdoc_files: []
84
75
  files:
85
76
  - .gitignore
86
- - .rbenv-version
87
77
  - .relish
88
78
  - .rspec
89
79
  - .travis.yml
@@ -93,6 +83,10 @@ files:
93
83
  - LICENSE.txt
94
84
  - README.md
95
85
  - Rakefile
86
+ - examples/basic_producer_and_consumer/Gemfile
87
+ - examples/basic_producer_and_consumer/common.rb
88
+ - examples/basic_producer_and_consumer/consumer.rb
89
+ - examples/basic_producer_and_consumer/producer.rb
96
90
  - features/.nav
97
91
  - features/CHANGELOG.md
98
92
  - features/README.md
@@ -100,16 +94,28 @@ files:
100
94
  - features/amqp_specific_features/README.md
101
95
  - features/amqp_specific_features/binding_amqp_destinations.feature
102
96
  - features/amqp_specific_features/declaring_amqp_exchanges.feature
97
+ - features/amqp_specific_features/nack_redelivered_messages.feature
98
+ - features/amqp_specific_features/requeueing_on_nack.feature
103
99
  - features/amqp_specific_features/server_named_destinations.feature
100
+ - features/client_acks.feature
104
101
  - features/destination_metadata.feature
105
102
  - features/dynamic_destinations.feature
106
103
  - features/error_handling.feature
107
104
  - features/getting_started.md
105
+ - features/logging.feature
106
+ - features/message_consumers.feature
107
+ - features/message_consumers/auto_ack_consumers.feature
108
+ - features/message_consumers/manual_ack_consumers.feature
109
+ - features/message_consumers/transactional_ack_consumers.feature
108
110
  - features/publishing_a_message.feature
109
111
  - features/publishing_with_transactions.feature
112
+ - features/rabbitmq_specific_features/dead_letter_queueing.feature
110
113
  - features/step_definitions/dynamic_destinations_steps.rb
111
114
  - features/step_definitions/error_handling_steps.rb
115
+ - features/step_definitions/logging_steps.rb
116
+ - features/step_definitions/message_consumers_steps.rb
112
117
  - features/step_definitions/steps.rb
118
+ - features/support/broker_config_helper.rb
113
119
  - features/support/env.rb
114
120
  - features/support/firewall_helper.rb
115
121
  - features/support/message_table_matcher.rb
@@ -121,51 +127,62 @@ files:
121
127
  - lib/message_driver/adapters/base.rb
122
128
  - lib/message_driver/adapters/bunny_adapter.rb
123
129
  - lib/message_driver/adapters/in_memory_adapter.rb
130
+ - lib/message_driver/adapters/stomp_adapter.rb
124
131
  - lib/message_driver/broker.rb
132
+ - lib/message_driver/client.rb
125
133
  - lib/message_driver/destination.rb
126
- - lib/message_driver/exceptions.rb
134
+ - lib/message_driver/errors.rb
135
+ - lib/message_driver/logging.rb
127
136
  - lib/message_driver/message.rb
128
- - lib/message_driver/message_publisher.rb
137
+ - lib/message_driver/subscription.rb
138
+ - lib/message_driver/vendor/.document
139
+ - lib/message_driver/vendor/nesty.rb
140
+ - lib/message_driver/vendor/nesty/nested_error.rb
129
141
  - lib/message_driver/version.rb
130
142
  - message-driver.gemspec
131
- - spec/integration/amqp_integration_spec.rb
132
- - spec/integration/message_driver/adapters/bunny_adapter_spec.rb
143
+ - spec/integration/bunny/amqp_integration_spec.rb
144
+ - spec/integration/bunny/bunny_adapter_spec.rb
145
+ - spec/integration/in_memory/in_memory_adapter_spec.rb
146
+ - spec/integration/stomp/stomp_adapter_spec.rb
133
147
  - spec/spec_helper.rb
148
+ - spec/support/shared/adapter_examples.rb
149
+ - spec/support/shared/client_ack_examples.rb
150
+ - spec/support/shared/context_examples.rb
134
151
  - spec/support/shared/destination_examples.rb
152
+ - spec/support/shared/subscription_examples.rb
153
+ - spec/support/shared/transaction_examples.rb
154
+ - spec/support/utils.rb
135
155
  - spec/units/message_driver/adapters/base_spec.rb
136
- - spec/units/message_driver/adapters/in_memory_adapter_spec.rb
137
156
  - spec/units/message_driver/broker_spec.rb
157
+ - spec/units/message_driver/client_spec.rb
138
158
  - spec/units/message_driver/destination_spec.rb
139
- - spec/units/message_driver/message_publisher_spec.rb
159
+ - spec/units/message_driver/logging_spec.rb
140
160
  - spec/units/message_driver/message_spec.rb
161
+ - spec/units/message_driver/subscription_spec.rb
141
162
  - test_lib/broker_config.rb
142
- homepage: https://github.com/soupmatt/message_driver
163
+ homepage: https://github.com/message-driver/message-driver
143
164
  licenses:
144
165
  - MIT
166
+ metadata: {}
145
167
  post_install_message:
146
168
  rdoc_options: []
147
169
  require_paths:
148
170
  - lib
149
171
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
172
  requirements:
152
- - - ! '>='
173
+ - - '>='
153
174
  - !ruby/object:Gem::Version
154
175
  version: 1.9.2
155
176
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
177
  requirements:
158
- - - ! '>='
178
+ - - '>'
159
179
  - !ruby/object:Gem::Version
160
- version: '0'
161
- segments:
162
- - 0
163
- hash: 1747639069992114351
180
+ version: 1.3.1
164
181
  requirements: []
165
182
  rubyforge_project:
166
- rubygems_version: 1.8.23
183
+ rubygems_version: 2.0.3
167
184
  signing_key:
168
- specification_version: 3
185
+ specification_version: 4
169
186
  summary: Easy message queues for ruby
170
187
  test_files:
171
188
  - features/.nav
@@ -175,29 +192,50 @@ test_files:
175
192
  - features/amqp_specific_features/README.md
176
193
  - features/amqp_specific_features/binding_amqp_destinations.feature
177
194
  - features/amqp_specific_features/declaring_amqp_exchanges.feature
195
+ - features/amqp_specific_features/nack_redelivered_messages.feature
196
+ - features/amqp_specific_features/requeueing_on_nack.feature
178
197
  - features/amqp_specific_features/server_named_destinations.feature
198
+ - features/client_acks.feature
179
199
  - features/destination_metadata.feature
180
200
  - features/dynamic_destinations.feature
181
201
  - features/error_handling.feature
182
202
  - features/getting_started.md
203
+ - features/logging.feature
204
+ - features/message_consumers.feature
205
+ - features/message_consumers/auto_ack_consumers.feature
206
+ - features/message_consumers/manual_ack_consumers.feature
207
+ - features/message_consumers/transactional_ack_consumers.feature
183
208
  - features/publishing_a_message.feature
184
209
  - features/publishing_with_transactions.feature
210
+ - features/rabbitmq_specific_features/dead_letter_queueing.feature
185
211
  - features/step_definitions/dynamic_destinations_steps.rb
186
212
  - features/step_definitions/error_handling_steps.rb
213
+ - features/step_definitions/logging_steps.rb
214
+ - features/step_definitions/message_consumers_steps.rb
187
215
  - features/step_definitions/steps.rb
216
+ - features/support/broker_config_helper.rb
188
217
  - features/support/env.rb
189
218
  - features/support/firewall_helper.rb
190
219
  - features/support/message_table_matcher.rb
191
220
  - features/support/no_error_matcher.rb
192
221
  - features/support/test_runner.rb
193
222
  - features/support/transforms.rb
194
- - spec/integration/amqp_integration_spec.rb
195
- - spec/integration/message_driver/adapters/bunny_adapter_spec.rb
223
+ - spec/integration/bunny/amqp_integration_spec.rb
224
+ - spec/integration/bunny/bunny_adapter_spec.rb
225
+ - spec/integration/in_memory/in_memory_adapter_spec.rb
226
+ - spec/integration/stomp/stomp_adapter_spec.rb
196
227
  - spec/spec_helper.rb
228
+ - spec/support/shared/adapter_examples.rb
229
+ - spec/support/shared/client_ack_examples.rb
230
+ - spec/support/shared/context_examples.rb
197
231
  - spec/support/shared/destination_examples.rb
232
+ - spec/support/shared/subscription_examples.rb
233
+ - spec/support/shared/transaction_examples.rb
234
+ - spec/support/utils.rb
198
235
  - spec/units/message_driver/adapters/base_spec.rb
199
- - spec/units/message_driver/adapters/in_memory_adapter_spec.rb
200
236
  - spec/units/message_driver/broker_spec.rb
237
+ - spec/units/message_driver/client_spec.rb
201
238
  - spec/units/message_driver/destination_spec.rb
202
- - spec/units/message_driver/message_publisher_spec.rb
239
+ - spec/units/message_driver/logging_spec.rb
203
240
  - spec/units/message_driver/message_spec.rb
241
+ - spec/units/message_driver/subscription_spec.rb
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p327
@@ -1,18 +0,0 @@
1
- module MessageDriver
2
- class Exception < ::Exception; end
3
-
4
- class WrappedException < Exception
5
- attr_reader :other
6
-
7
- def initialize(other, msg=nil)
8
- super(msg || other.to_s)
9
- @other = other
10
- end
11
- end
12
-
13
- class QueueNotFound < WrappedException; end
14
-
15
- class ConnectionException < WrappedException; end
16
-
17
- class TransactionRollbackOnly < Exception; end
18
- end
@@ -1,15 +0,0 @@
1
- module MessageDriver
2
- module MessagePublisher
3
- def publish(destination, body, headers={}, properties={})
4
- Broker.publish(destination, body, headers, properties)
5
- end
6
-
7
- def pop_message(destination, options={})
8
- Broker.pop_message(destination, options)
9
- end
10
-
11
- def with_message_transaction(options={}, &block)
12
- Broker.with_transaction(options, &block)
13
- end
14
- end
15
- end
@@ -1,301 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'message_driver/adapters/bunny_adapter'
4
-
5
- module MessageDriver::Adapters
6
- describe BunnyAdapter, :bunny, type: :integration do
7
-
8
- let(:valid_connection_attrs) { BrokerConfig.config }
9
-
10
- describe "#initialize" do
11
- context "differing bunny versions" do
12
- shared_examples "raises an error" do
13
- it "raises an error" do
14
- stub_const("Bunny::VERSION", version)
15
- expect {
16
- described_class.new(valid_connection_attrs)
17
- }.to raise_error MessageDriver::Exception, "bunny 0.9.0.pre7 or later is required for the bunny adapter"
18
- end
19
- end
20
- shared_examples "doesn't raise an error" do
21
- it "doesn't raise an an error" do
22
- stub_const("Bunny::VERSION", version)
23
- adapter = nil
24
- expect {
25
- adapter = described_class.new(valid_connection_attrs)
26
- }.to_not raise_error
27
- end
28
- end
29
- %w(0.8.0 0.9.0.pre6).each do |v|
30
- context "bunny version #{v}" do
31
- let(:version) { v }
32
- include_examples "raises an error"
33
- end
34
- end
35
- %w(0.9.0.pre7 0.9.0.rc1 0.9.0 0.9.1).each do |v|
36
- context "bunny version #{v}" do
37
- let(:version) { v }
38
- include_examples "doesn't raise an error"
39
- end
40
- end
41
- end
42
-
43
- it "connects to the rabbit broker" do
44
- adapter = described_class.new(valid_connection_attrs)
45
-
46
- expect(adapter.connection).to be_a Bunny::Session
47
- expect(adapter.connection).to be_open
48
- end
49
-
50
- it "connects to the rabbit broker lazily" do
51
- adapter = described_class.new(valid_connection_attrs)
52
-
53
- expect(adapter.connection(false)).to_not be_open
54
- end
55
-
56
- it "forces bunny into non-threaded mode" do
57
- #FIXME can be changed once ruby-amqp/bunny#112 is fixed
58
- adapter = described_class.new(valid_connection_attrs)
59
- expect(adapter.connection(false).threaded).to be_false
60
-
61
- adapter = described_class.new(valid_connection_attrs.merge(threaded: true))
62
- expect(adapter.connection(false).threaded).to be_false
63
- end
64
- end
65
-
66
- shared_context "a connected adapter" do
67
- let(:adapter) { described_class.new(valid_connection_attrs) }
68
- let(:connection) { adapter.connection }
69
-
70
- after do
71
- connection.close
72
- end
73
- end
74
-
75
- shared_context "with a queue" do
76
- include_context "a connected adapter"
77
-
78
- let(:channel) { connection.create_channel }
79
- let(:tmp_queue_name) { "my_temp_queue" }
80
- let(:tmp_queue) { channel.queue(tmp_queue_name, exclusive: true) }
81
- end
82
-
83
- describe "#pop_message" do
84
- include_context "with a queue"
85
- it "needs some real tests"
86
- end
87
-
88
- describe "#create_destination" do
89
- include_context "a connected adapter"
90
-
91
- context "with defaults" do
92
- context "the resulting destination" do
93
- let(:dest_name) { "my_dest" }
94
- subject(:result) { adapter.create_destination(dest_name, exclusive: true) }
95
-
96
- it { should be_a BunnyAdapter::QueueDestination }
97
- end
98
- end
99
-
100
- context "the type is queue" do
101
- context "and there is no destination name given" do
102
- subject(:destination) { adapter.create_destination("", type: :queue, exclusive: true) }
103
- it { should be_a BunnyAdapter::QueueDestination }
104
- its(:name) { should be_a String }
105
- its(:name) { should_not be_empty }
106
- end
107
- context "the resulting destination" do
108
- let(:dest_name) { "my_dest" }
109
- subject(:destination) { adapter.create_destination(dest_name, type: :queue, exclusive: true) }
110
- before do
111
- destination
112
- end
113
-
114
- it { should be_a BunnyAdapter::QueueDestination }
115
- its(:name) { should be_a String }
116
- its(:name) { should eq(dest_name) }
117
-
118
- include_examples "supports #message_count"
119
-
120
- it "strips off the type so it isn't set on the destination" do
121
- expect(subject.dest_options).to_not have_key :type
122
- end
123
- it "ensures the queue is declared" do
124
- expect {
125
- connection.with_channel do |ch|
126
- ch.queue(dest_name, passive: true)
127
- end
128
- }.to_not raise_error
129
- end
130
- context "publishing a message" do
131
- let(:body) { "Testing the QueueDestination" }
132
- let(:headers) { {"foo" => "bar"} }
133
- let(:properties) { {persistent: false} }
134
- before do
135
- subject.publish(body, headers, properties)
136
- end
137
- it "publishes via the default exchange" do
138
- msg = subject.pop_message
139
- expect(msg.body).to eq(body)
140
- expect(msg.headers).to eq(headers)
141
- expect(msg.properties[:delivery_mode]).to eq(1)
142
- expect(msg.delivery_info.exchange).to eq("")
143
- expect(msg.delivery_info.routing_key).to eq(subject.name)
144
- end
145
- end
146
- it_behaves_like "a destination"
147
- end
148
- context "and bindings are provided" do
149
- let(:dest_name) { "binding_test_queue" }
150
- let(:exchange) { adapter.create_destination("amq.direct", type: :exchange) }
151
-
152
- it "raises an exception if you don't provide a source" do
153
- expect {
154
- adapter.create_destination("bad_bind_queue", type: :queue, exclusive: true, bindings: [{args: {routing_key: "test_exchange_bind"}}])
155
- }.to raise_error MessageDriver::Exception, /must provide a source/
156
- end
157
-
158
- it "routes message to the queue through the exchange" do
159
- destination = adapter.create_destination(dest_name, type: :queue, exclusive: true, bindings: [{source: "amq.direct", args: {routing_key: "test_queue_bind"}}])
160
- exchange.publish("test queue bindings", {}, {routing_key: "test_queue_bind"})
161
- message = destination.pop_message
162
- expect(message).to_not be_nil
163
- expect(message.body).to eq("test queue bindings")
164
- end
165
- end
166
-
167
- context "we are not yet connected to the broker and :no_declare is provided" do
168
- it "doesn't cause a connection to the broker" do
169
- connection.stop
170
- adapter.create_destination("test_queue", no_declare: true, type: :queue, exclusive: true)
171
- expect(adapter.connection(false)).to_not be_open
172
- end
173
-
174
- context "with a server-named queue" do
175
- it "raises an error" do
176
- expect {
177
- adapter.create_destination("", no_declare: true, type: :queue, exclusive: true)
178
- }.to raise_error MessageDriver::Exception, "server-named queues must be declared, but you provided :no_declare => true"
179
- end
180
- end
181
-
182
- context "with bindings" do
183
- it "raises an error" do
184
- expect {
185
- adapter.create_destination("tmp_queue", no_declare: true, bindings: [{source: "amq.fanout"}], type: :queue, exclusive: true)
186
- }.to raise_error MessageDriver::Exception, "queues with bindings must be declared, but you provided :no_declare => true"
187
- end
188
- end
189
- end
190
- end
191
-
192
- context "the type is exchange" do
193
- context "the resulting destination" do
194
- let(:dest_name) { "my_dest" }
195
- subject(:destination) { adapter.create_destination(dest_name, type: :exchange) }
196
-
197
- it { should be_a BunnyAdapter::ExchangeDestination }
198
- include_examples "doesn't support #message_count"
199
-
200
- it "strips off the type so it isn't set on the destination" do
201
- expect(subject.dest_options).to_not have_key :type
202
- end
203
-
204
- it "raises an error when pop_message is called" do
205
- expect {
206
- subject.pop_message(dest_name)
207
- }.to raise_error MessageDriver::Exception, "You can't pop a message off an exchange"
208
- end
209
-
210
- context "publishing a message" do
211
- let(:body) { "Testing the ExchangeDestination" }
212
- let(:headers) { {"foo" => "bar"} }
213
- let(:properties) { {persistent: false} }
214
- before { connection.with_channel { |ch| ch.fanout(dest_name, auto_delete: true) } }
215
- let!(:queue) do
216
- q = nil
217
- connection.with_channel do |ch|
218
- q = ch.queue("", exclusive: true)
219
- q.bind(dest_name)
220
- end
221
- q
222
- end
223
- before do
224
- subject.publish(body, headers, properties)
225
- end
226
-
227
- it "publishes to the specified exchange" do
228
- connection.with_channel do |ch|
229
- q = ch.queue(queue.name, passive: true)
230
- msg = q.pop
231
- expect(msg[2]).to eq(body)
232
- expect(msg[0].exchange).to eq(dest_name)
233
- expect(msg[1][:headers]).to eq(headers)
234
- expect(msg[1][:delivery_mode]).to eq(1)
235
- end
236
- end
237
- end
238
- end
239
-
240
- context "declaring an exchange on the broker" do
241
- let(:dest_name) { "my.cool.exchange" }
242
-
243
- it "creates the exchange if you include 'declare' in the options" do
244
- exchange = adapter.create_destination(dest_name, type: :exchange, declare: {type: :fanout, auto_delete: true})
245
- queue = adapter.create_destination("", type: :queue, exclusive: true, bindings: [{source: dest_name}])
246
- exchange.publish("test declaring exchange")
247
- message = queue.pop_message
248
- expect(message).to_not be_nil
249
- expect(message.body).to eq("test declaring exchange")
250
- end
251
-
252
- it "raises an error if you don't provide a type" do
253
- expect {
254
- adapter.create_destination(dest_name, type: :exchange, declare: {auto_delete: true})
255
- }.to raise_error MessageDriver::Exception, /you must provide a valid exchange type/
256
- end
257
-
258
- end
259
-
260
- context "and bindings are provided" do
261
- let(:dest_name) { "binding_exchange_queue" }
262
- let(:exchange) { adapter.create_destination("amq.direct", type: :exchange) }
263
-
264
- it "raises an exception if you don't provide a source" do
265
- expect {
266
- adapter.create_destination("amq.fanout", type: :exchange, bindings: [{args: {routing_key: "test_exchange_bind"}}])
267
- }.to raise_error MessageDriver::Exception, /must provide a source/
268
- end
269
-
270
- it "routes message to the queue through the exchange" do
271
- adapter.create_destination("amq.fanout", type: :exchange, bindings: [{source: "amq.direct", args: {routing_key: "test_exchange_bind"}}])
272
- destination = adapter.create_destination(dest_name, type: :queue, exclusive: true, bindings: [{source: "amq.fanout"}])
273
- exchange.publish("test exchange bindings", {}, {routing_key: "test_exchange_bind"})
274
- message = destination.pop_message
275
- expect(message).to_not be_nil
276
- expect(message.body).to eq("test exchange bindings")
277
- end
278
- end
279
-
280
- context "we are not yet connected to the broker" do
281
- before do
282
- connection.stop
283
- end
284
-
285
- it "doesn't cause a connection to the broker" do
286
- adapter.create_destination("amq.fanout", type: :exchange)
287
- expect(adapter.connection(false)).to_not be_open
288
- end
289
- end
290
- end
291
-
292
- context "the type is invalid" do
293
- it "raises in an error" do
294
- expect {
295
- adapter.create_destination("my_dest", type: :foo_bar)
296
- }.to raise_error MessageDriver::Exception, "invalid destination type #{:foo_bar}"
297
- end
298
- end
299
- end
300
- end
301
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'message_driver/adapters/in_memory_adapter'
4
-
5
- module MessageDriver::Adapters
6
- describe InMemoryAdapter do
7
- let(:adapter) { described_class.new }
8
-
9
- describe "#create_destination" do
10
- describe "the resulting destination" do
11
- let!(:destination) { adapter.create_destination("my_test_dest") }
12
- it_behaves_like "a destination"
13
-
14
- subject { destination }
15
-
16
- it { should be_a InMemoryAdapter::Destination }
17
-
18
- include_examples "supports #message_count"
19
- end
20
- end
21
-
22
- describe "#reset_after_tests" do
23
- #make some destinations
24
- # throw some messages on it
25
- # assert the messages are in the destinations
26
- # empty the queues on each destination via method
27
- # assert destinations are empty
28
-
29
- it "empties all the destination queues" do
30
- destinations = (1..3).map(&adapter.method(:create_destination))
31
- destinations.each do |destination|
32
- destination.publish("There's always money in the banana stand!", {}, {})
33
- end
34
-
35
- adapter.reset_after_tests
36
-
37
- destinations.each do |destination|
38
- expect(destination.pop_message).to be_nil
39
- end
40
- end
41
- end
42
- end
43
- end