message-driver 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -17
  3. data/CHANGELOG.md +6 -1
  4. data/Guardfile +3 -3
  5. data/Rakefile +0 -2
  6. data/ci/reset_vhost +5 -0
  7. data/ci/travis_setup +10 -0
  8. data/features/.nav +5 -2
  9. data/features/CHANGELOG.md +6 -1
  10. data/features/amqp_specific_features/declaring_amqp_exchanges.feature +3 -3
  11. data/features/amqp_specific_features/nack_redelivered_messages.feature +2 -2
  12. data/features/amqp_specific_features/server_named_destinations.feature +3 -4
  13. data/features/connecting_to_multiple_brokers.feature +51 -0
  14. data/features/destination_metadata.feature +2 -2
  15. data/features/dynamic_destinations.feature +2 -2
  16. data/features/error_handling.feature +2 -4
  17. data/features/logging.feature +3 -2
  18. data/features/message_consumers/auto_ack_consumers.feature +4 -4
  19. data/features/{message_consumers.feature → message_consumers/basics.feature} +2 -2
  20. data/features/message_consumers/manual_ack_consumers.feature +5 -5
  21. data/features/message_consumers/prefetch_size.feature +4 -4
  22. data/features/message_consumers/transactional_ack_consumers.feature +7 -4
  23. data/features/rabbitmq_specific_features/dead_letter_queueing.feature +3 -3
  24. data/features/step_definitions/dynamic_destinations_steps.rb +2 -2
  25. data/features/step_definitions/logging_steps.rb +5 -1
  26. data/features/step_definitions/message_consumers_steps.rb +1 -1
  27. data/features/step_definitions/steps.rb +13 -4
  28. data/features/support/env.rb +1 -1
  29. data/features/support/test_runner.rb +6 -1
  30. data/lib/message_driver/adapters/base.rb +7 -1
  31. data/lib/message_driver/adapters/bunny_adapter.rb +22 -57
  32. data/lib/message_driver/adapters/in_memory_adapter.rb +3 -2
  33. data/lib/message_driver/adapters/stomp_adapter.rb +6 -6
  34. data/lib/message_driver/broker.rb +80 -19
  35. data/lib/message_driver/client.rb +50 -29
  36. data/lib/message_driver/destination.rb +2 -2
  37. data/lib/message_driver/errors.rb +2 -0
  38. data/lib/message_driver/logging.rb +7 -1
  39. data/lib/message_driver/message.rb +15 -4
  40. data/lib/message_driver/version.rb +1 -1
  41. data/lib/message_driver.rb +12 -5
  42. data/spec/integration/bunny/amqp_integration_spec.rb +15 -20
  43. data/spec/integration/bunny/bunny_adapter_spec.rb +13 -13
  44. data/spec/integration/in_memory/in_memory_adapter_spec.rb +2 -1
  45. data/spec/integration/stomp/stomp_adapter_spec.rb +6 -8
  46. data/spec/spec_helper.rb +9 -0
  47. data/spec/support/shared/adapter_examples.rb +6 -0
  48. data/spec/support/shared/context_examples.rb +2 -0
  49. data/spec/support/shared/destination_examples.rb +2 -0
  50. data/spec/units/message_driver/adapters/base_spec.rb +0 -8
  51. data/spec/units/message_driver/broker_spec.rb +240 -109
  52. data/spec/units/message_driver/client_spec.rb +69 -62
  53. data/spec/units/message_driver/message_spec.rb +59 -22
  54. data/test_lib/broker_config.rb +2 -1
  55. metadata +8 -7
  56. data/lib/bunny/session_patch.rb +0 -19
  57. data/spec/units/message_driver/logging_spec.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f6ca18a14ba62a965bc18eac1072208821266e6
4
- data.tar.gz: dbed32cf2ad5170579f1e013c85c79a94f0264e0
3
+ metadata.gz: c03ff5c533ab9ffdb8a6a3fce6b2ffe0b7239d56
4
+ data.tar.gz: 44614cda7f594028f587e7dfd79f608c7b3fb0c3
5
5
  SHA512:
6
- metadata.gz: 9aae643f4f2396e55fbb848770530832ad4729e7fe566219f2c178f22e199adda8d19e70f766b248043f9c2a496909f4b343c575c303ab87ed105162c7138688
7
- data.tar.gz: 85430c090e5667abe21e58207bcfaafc7e1d9122c260b2c2b50fc0956d8fa645c730db0ef2e678d0f1dc7d23e2a10630b978717f7051ea11dcfab5f3be9e0c93
6
+ metadata.gz: 335cc2f27f8b2a70ec0abb4523c1fee62abea0664fb80a4ea09e1936da6d66f6012087b05961bdcd6acbc3ff2a3dd396013b48021ca3f185fb1b0e2ffd56ccc2
7
+ data.tar.gz: 8ded01de5e953bf8486d2d139de8e677db11e138b6a6e221fbec35dcd12d905605c95403856f2c5da8ad922141a284b348f61093f874e17ce5177f661452e311
data/.travis.yml CHANGED
@@ -1,33 +1,23 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  bundler_args: --without tools darwin
3
4
  services:
4
5
  - rabbitmq
5
6
  before_script:
6
- - sudo rabbitmqctl add_vhost message-driver-test
7
- - sudo rabbitmqctl set_permissions -p message-driver-test guest ".*" ".*" ".*"
8
- - sudo rabbitmq-plugins enable rabbitmq_stomp
9
- - sudo service rabbitmq-server restart
10
- env:
11
- - ADAPTER=in_memory
12
- - ADAPTER=bunny:0.10.0
13
- - ADAPTER=stomp
14
- - ADAPTER=bunny:1.0.0
7
+ - ci/travis_setup
15
8
  rvm:
16
9
  - 2.1.0
17
10
  - 2.0.0
18
11
  - 1.9.3
19
- - 1.9.2
20
12
  - jruby-19mode
21
- - jruby-head
13
+ - 1.9.2
22
14
  - rbx
15
+ env:
16
+ - ADAPTER=in_memory
17
+ - ADAPTER=stomp
18
+ - ADAPTER=bunny:1.1.3
23
19
  matrix:
24
- exclude:
25
- - rvm: jruby-19mode
26
- env: ADAPTER=bunny:0.9.0
27
- - rvm: jruby-head
28
- env: ADAPTER=bunny:0.9.0
29
20
  allow_failures:
30
- - rvm: jruby-head
31
21
  - rvm: rbx
32
22
  - rvm: jruby-19mode
33
23
  env: ADAPTER=stomp
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.0.dev - master
3
+ ## 0.3.0 - 2014-02-26
4
+
5
+ * Support for handling multiple broker connections
6
+ * require bunny 1.1.3 or later
7
+ * make bunny connections as lazily initialized as possible
8
+ * bunny transaction start lazily
4
9
 
5
10
  ## 0.2.2 - 2014-02-21
6
11
 
data/Guardfile CHANGED
@@ -8,9 +8,9 @@ guard 'bundler' do
8
8
  watch(/^.+\.gemspec/)
9
9
  end
10
10
 
11
- common_rspec_opts = {keep_failed: true, all_after_pass: true}
12
- unit_spec_opts = common_rspec_opts.merge({spec_paths: ["spec/units"], cmd: 'rspec -f doc', run_all: {cmd: 'rspec'}})
13
- integration_spec_opts = common_rspec_opts.merge({spec_paths: ["spec/integration/#{BrokerConfig.current_adapter}"], cmd: 'rspec -f doc -t all_adapters', run_all: {cmd: 'rspec -t all_adapters'}})
11
+ common_rspec_opts = { all_after_pass: true }
12
+ unit_spec_opts = common_rspec_opts.merge({ spec_paths: ["spec/units"], cmd: 'bundle exec rspec -f doc', run_all: { cmd: 'bundle exec rspec' } })
13
+ integration_spec_opts = common_rspec_opts.merge({ spec_paths: ["spec/integration/#{BrokerConfig.current_adapter}"], cmd: 'bundle exec rspec -f doc -t all_adapters', run_all: { cmd: 'bundle exec rspec -t all_adapters' } })
14
14
 
15
15
  group 'specs' do
16
16
  guard 'rspec', unit_spec_opts do
data/Rakefile CHANGED
@@ -6,8 +6,6 @@ require 'bundler/gem_tasks'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'cucumber/rake/task'
8
8
 
9
- #require File.join(File.dirname(__FILE__), 'test_lib', 'broker_config')
10
-
11
9
  namespace :spec do
12
10
  desc "Run unit specs"
13
11
  RSpec::Core::RakeTask.new(:units) do |t|
data/ci/reset_vhost ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ rabbitmqctl delete_vhost message-driver-test
4
+ rabbitmqctl add_vhost message-driver-test
5
+ rabbitmqctl set_permissions -p message-driver-test guest ".*" ".*" ".*"
data/ci/travis_setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ sudo rabbitmqctl add_vhost message-driver-test
4
+ sudo rabbitmqctl set_permissions -p message-driver-test guest ".*" ".*" ".*"
5
+
6
+ if [ "$ADAPTER" = "stomp" ]; then
7
+ sudo rabbitmq-plugins enable rabbitmq_stomp
8
+ sudo service rabbitmq-server restart
9
+ sleep 3
10
+ fi
data/features/.nav CHANGED
@@ -6,15 +6,18 @@
6
6
  - destination_metadata.feature
7
7
  - client_acks.feature
8
8
  - logging.feature
9
- - message_consumers.feature
10
- - message_consumers
9
+ - message_consumers (Message Consumers)
10
+ - basics.feature
11
11
  - auto_ack_consumers.feature
12
12
  - manual_ack_consumers.feature
13
13
  - transactional_ack_consumers.feature
14
+ - prefetch_size.feature
15
+ - subscribe_with_a_block.feature
14
16
  - amqp_specific_features (AMQP-Specific Features):
15
17
  - declaring_amqp_destinations.feature
16
18
  - binding_amqp_destinations.feature
17
19
  - server_named_desitnations.feature
18
20
  - requeueing_on_nack.feature
21
+ - connecting_to_multiple_brokers.feature
19
22
  - error_handling.feature
20
23
  - Rails.md
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.0.dev - master
3
+ ## 0.3.0 - 2014-02-26
4
+
5
+ * Support for handling multiple broker connections
6
+ * require bunny 1.1.3 or later
7
+ * make bunny connections as lazily initialized as possible
8
+ * bunny transaction start lazily
4
9
 
5
10
  ## 0.2.2 - 2014-02-21
6
11
 
@@ -11,12 +11,12 @@ Feature: Declaring AMQP exchanges
11
11
  """ruby
12
12
  MessageDriver::Broker.define do |b|
13
13
  b.destination :my_exchange, "my_exchange", type: :exchange, declare: {type: :direct, auto_delete: true}
14
- b.destination :my_queue, "", exclusive: true, bindings: [{source: "my_exchange", routing_key: "my_queue"}]
14
+ b.destination :exchange_bound_queue, "", exclusive: true, bindings: [{source: "my_exchange", routing_key: "exchange_bound_queue"}]
15
15
  end
16
16
 
17
- publish(:my_exchange, "Test My New Exchange", routing_key: "my_queue")
17
+ publish(:my_exchange, "Test My New Exchange", routing_key: "exchange_bound_queue")
18
18
  """
19
19
 
20
- Then I expect to find the following message on :my_queue
20
+ Then I expect to find the following message on :exchange_bound_queue
21
21
  | body |
22
22
  | Test My New Exchange |
@@ -28,7 +28,7 @@ Feature: Nacking Redelievered Messages from a consumer
28
28
  Scenario: Raising an error in an auto_ack consumer
29
29
  Given I have a message consumer
30
30
  """ruby
31
- MessageDriver::Broker.consumer(:manual_redeliver) do |message|
31
+ MessageDriver::Client.consumer(:manual_redeliver) do |message|
32
32
  publish(:rabbit_track, "#{message.body} Attempt")
33
33
  raise "oh nos!"
34
34
  end
@@ -61,7 +61,7 @@ Feature: Nacking Redelievered Messages from a consumer
61
61
  Given I have a message consumer
62
62
  """ruby
63
63
  @attempts = 0
64
- MessageDriver::Broker.consumer(:transactional_redeliver) do |message|
64
+ MessageDriver::Client.consumer(:transactional_redeliver) do |message|
65
65
  publish(:rabbit_track, "#{message.body} Attempt")
66
66
  @attempts += 1
67
67
  raise "oh nos!"
@@ -3,15 +3,14 @@ Feature: Server-Named Destinations
3
3
  AMQP brokers allow you to create queues that are named by the server. Here's
4
4
  how you do it with message_driver.
5
5
 
6
- Background:
7
- Given I am connected to the broker
8
-
9
6
  Scenario: Creating a server-named queue
10
7
  I expect my destination to have the queue name given to it by the server
11
8
 
9
+ Given I am connected to the broker
10
+
12
11
  When I execute the following code
13
12
  """ruby
14
- destination = MessageDriver::Broker.dynamic_destination("", exclusive: true)
13
+ destination = MessageDriver::Client.dynamic_destination("", exclusive: true)
15
14
  expect(destination.name).to_not be_empty
16
15
  """
17
16
 
@@ -0,0 +1,51 @@
1
+ Feature: Connecting to Multiple Brokers
2
+
3
+ Background:
4
+ Given I am connected to a broker named :my_broker
5
+
6
+ @all_adapters
7
+ Scenario: Declaring Destinations and Publishing on a secondary broker
8
+ Given I configure my broker as follows
9
+ """ruby
10
+ MessageDriver::Broker.define(:my_broker) do |b|
11
+ b.destination(:multi_broker_destination, "multi.broker.queue")
12
+ end
13
+ """
14
+ And I have no messages on :multi_broker_destination
15
+
16
+ When I execute the following code
17
+ """ruby
18
+ MessageDriver::Client[:my_broker].publish(:multi_broker_destination, "Test Message")
19
+ """
20
+
21
+ Then I expect to find the following message on :multi_broker_destination
22
+ | body |
23
+ | Test Message |
24
+
25
+ @bunny
26
+ @in_memory
27
+ Scenario: Declaring Consumers and Subscriptions on a secondary broker
28
+ Given I have a destination :dest_queue with no messages on it
29
+ And I have a destination :source_queue with no messages on it
30
+ And I have a message consumer
31
+ """ruby
32
+ MessageDriver::Client[:my_broker].consumer(:my_consumer) do |message|
33
+ MessageDriver::Client[:my_broker].publish(:dest_queue, message.body)
34
+ end
35
+ """
36
+ And I create a subscription
37
+ """ruby
38
+ MessageDriver::Client[:my_broker].subscribe(:source_queue, :my_consumer)
39
+ """
40
+
41
+ When I send the following messages to :source_queue
42
+ | body |
43
+ | Test Message 1 |
44
+ | Test Message 2 |
45
+ And I let the subscription process
46
+
47
+ Then I expect to find no messages on :source_queue
48
+ And I expect to find the following 2 messages on :dest_queue
49
+ | body |
50
+ | Test Message 1 |
51
+ | Test Message 2 |
@@ -8,7 +8,7 @@ Feature: Destination Metadata
8
8
  Scenario: Checking the message count when the queue is empty
9
9
  When I execute the following code
10
10
  """ruby
11
- destination = MessageDriver::Broker.find_destination(:my_queue)
11
+ destination = MessageDriver::Client.find_destination(:my_queue)
12
12
  expect(destination.message_count).to eq(0)
13
13
  """
14
14
 
@@ -23,7 +23,7 @@ Feature: Destination Metadata
23
23
  And I allow for processing
24
24
  And I execute the following code
25
25
  """ruby
26
- destination = MessageDriver::Broker.find_destination(:my_queue)
26
+ destination = MessageDriver::Client.find_destination(:my_queue)
27
27
  expect(destination.message_count).to eq(2)
28
28
  """
29
29
 
@@ -10,7 +10,7 @@ Feature: Dynamic Destinations
10
10
  Scenario: Sending to a dynamic destination
11
11
  When I execute the following code
12
12
  """ruby
13
- my_new_destination = MessageDriver::Broker.dynamic_destination("temp_queue")
13
+ my_new_destination = MessageDriver::Client.dynamic_destination("temp_queue")
14
14
  my_new_destination.publish("Test Message")
15
15
  """
16
16
 
@@ -26,7 +26,7 @@ Feature: Dynamic Destinations
26
26
 
27
27
  When I execute the following code
28
28
  """ruby
29
- my_new_destination = MessageDriver::Broker.dynamic_destination("temp_queue")
29
+ my_new_destination = MessageDriver::Client.dynamic_destination("temp_queue")
30
30
 
31
31
  msg1 = my_new_destination.pop_message
32
32
  expect(msg1.body).to eq("Test Message 1")
@@ -1,13 +1,11 @@
1
1
  Feature: Error Handling
2
2
 
3
- Background:
4
- Given I am connected to the broker
5
-
6
3
  @bunny
7
4
  Scenario: Queue isn't found on the broker
5
+ Given I am connected to the broker
8
6
  When I execute the following code
9
7
  """ruby
10
- MessageDriver::Broker.dynamic_destination("missing_queue", passive: true)
8
+ MessageDriver::Client.dynamic_destination("missing_queue", passive: true)
11
9
  """
12
10
 
13
11
  Then I expect it to raise a MessageDriver::QueueNotFound error
@@ -1,8 +1,9 @@
1
1
  @all_adapters
2
2
  Feature: Stuff gets logged if you set a logger
3
3
 
4
- You can configure the logger by add a logger to the hash passed to `MessageDriver::Broker.configure`.
5
- If you don't provide a logger, then an info level logger will be created and sent to `STDOUT`.
4
+ You can configure the logger by setting it on `MessageDriver.logger`.
5
+ If you don't provide a logger, then an info level logger will be created
6
+ and sent to `STDOUT`.
6
7
 
7
8
  Scenario: Starting the broker
8
9
  Given I am logging to a log file at the debug level
@@ -1,5 +1,5 @@
1
1
  @bunny
2
- Feature: Message Consumers auto-acknowledgement
2
+ Feature: Automatic Message Acknowledgement
3
3
  This mode will ack the message if the consumer completes successfully.
4
4
  It will nack the message if the consumer raises an error.
5
5
 
@@ -11,7 +11,7 @@ Feature: Message Consumers auto-acknowledgement
11
11
  Scenario: Consuming Messages
12
12
  Given I have a message consumer
13
13
  """ruby
14
- MessageDriver::Broker.consumer(:my_consumer) do |message|
14
+ MessageDriver::Client.consumer(:my_consumer) do |message|
15
15
  MessageDriver::Client.publish(:dest_queue, message.body)
16
16
  end
17
17
  """
@@ -36,7 +36,7 @@ Feature: Message Consumers auto-acknowledgement
36
36
  Scenario: An error occurs during processing
37
37
  Given I have a message consumer
38
38
  """ruby
39
- MessageDriver::Broker.consumer(:my_consumer) do |message|
39
+ MessageDriver::Client.consumer(:my_consumer) do |message|
40
40
  raise "oh nos!"
41
41
  end
42
42
  """
@@ -60,7 +60,7 @@ Feature: Message Consumers auto-acknowledgement
60
60
  Scenario: A DontRequeue error occurs during processing
61
61
  Given I have a message consumer
62
62
  """ruby
63
- MessageDriver::Broker.consumer(:my_consumer) do |message|
63
+ MessageDriver::Client.consumer(:my_consumer) do |message|
64
64
  raise MessageDriver::DontRequeueError, "don't requeue me"
65
65
  end
66
66
  """
@@ -1,13 +1,13 @@
1
1
  @in_memory
2
2
  @bunny
3
- Feature: Message Consumers
3
+ Feature: Basics of Message Consumers
4
4
  Background:
5
5
  Given I am connected to the broker
6
6
  And I have a destination :dest_queue with no messages on it
7
7
  And I have a destination :source_queue with no messages on it
8
8
  And I have a message consumer
9
9
  """ruby
10
- MessageDriver::Broker.consumer(:my_consumer) do |message|
10
+ MessageDriver::Client.consumer(:my_consumer) do |message|
11
11
  MessageDriver::Client.publish(:dest_queue, message.body)
12
12
  end
13
13
  """
@@ -1,5 +1,5 @@
1
1
  @bunny
2
- Feature: Message Consumers with manual acknowledgement
2
+ Feature: Manual Message Acknowledgement
3
3
  This mode requires the consumer to call ack on the message in order to acknowledge it
4
4
 
5
5
  Background:
@@ -9,7 +9,7 @@ Feature: Message Consumers with manual acknowledgement
9
9
  Scenario: Consuming Messages
10
10
  Given I have a message consumer
11
11
  """ruby
12
- MessageDriver::Broker.consumer(:my_consumer) do |message|
12
+ MessageDriver::Client.consumer(:my_consumer) do |message|
13
13
  message.ack
14
14
  end
15
15
  """
@@ -29,7 +29,7 @@ Feature: Message Consumers with manual acknowledgement
29
29
  Scenario: When a message is nack'ed
30
30
  Given I have a message consumer
31
31
  """ruby
32
- MessageDriver::Broker.consumer(:my_consumer) do |message|
32
+ MessageDriver::Client.consumer(:my_consumer) do |message|
33
33
  message.nack(requeue: true)
34
34
  end
35
35
  """
@@ -52,7 +52,7 @@ Feature: Message Consumers with manual acknowledgement
52
52
  Scenario: When an occurs before the message is ack'ed
53
53
  Given I have a message consumer
54
54
  """ruby
55
- MessageDriver::Broker.consumer(:my_consumer) do |message|
55
+ MessageDriver::Client.consumer(:my_consumer) do |message|
56
56
  raise "oh nos!"
57
57
  message.ack
58
58
  end
@@ -76,7 +76,7 @@ Feature: Message Consumers with manual acknowledgement
76
76
  Scenario: When an error occurs after the message is ack'ed
77
77
  Given I have a message consumer
78
78
  """ruby
79
- MessageDriver::Broker.consumer(:my_consumer) do |message|
79
+ MessageDriver::Client.consumer(:my_consumer) do |message|
80
80
  message.ack
81
81
  raise "oh nos!"
82
82
  end
@@ -1,7 +1,7 @@
1
1
  @bunny
2
2
  @wip
3
- Feature: Message Consumers prefetch size
4
- You can set the prefetch size for your message consumers
3
+ Feature: Controlling Prefetch Size
4
+ You can set the prefetch size for your message consumers.
5
5
 
6
6
  Background:
7
7
  Given I am connected to the broker
@@ -12,13 +12,13 @@ Feature: Message Consumers prefetch size
12
12
  Scenario: Consuming Messages
13
13
  Given I have a message consumer
14
14
  """ruby
15
- MessageDriver::Broker.consumer(:my_consumer_1) do |message|
15
+ MessageDriver::Client.consumer(:my_consumer_1) do |message|
16
16
  MessageDriver::Client.publish(:dest_queue_1, message.body)
17
17
  end
18
18
  """
19
19
  And I have a message consumer
20
20
  """ruby
21
- MessageDriver::Broker.consumer(:my_consumer_2) do |message|
21
+ MessageDriver::Client.consumer(:my_consumer_2) do |message|
22
22
  MessageDriver::Client.publish(:dest_queue_2, message.body)
23
23
  end
24
24
  """
@@ -1,5 +1,8 @@
1
1
  @bunny
2
- Feature: Transactional Message Consumers
2
+ Feature: Transactional Consumers
3
+ These consumers will wrap the acknowledgement of the consumed message
4
+ as well as any publishes in a native broker transaction.
5
+
3
6
  Background:
4
7
  Given I am connected to the broker
5
8
  And I have a destination :dest_queue with no messages on it
@@ -8,7 +11,7 @@ Feature: Transactional Message Consumers
8
11
  Scenario: Consuming Messages within a transaction
9
12
  Given I have a message consumer
10
13
  """ruby
11
- MessageDriver::Broker.consumer(:my_consumer) do |message|
14
+ MessageDriver::Client.consumer(:my_consumer) do |message|
12
15
  MessageDriver::Client.publish(:dest_queue, message.body)
13
16
  end
14
17
  """
@@ -32,7 +35,7 @@ Feature: Transactional Message Consumers
32
35
  Scenario: When an error occurs
33
36
  Given I have a message consumer
34
37
  """ruby
35
- MessageDriver::Broker.consumer(:my_consumer) do |message|
38
+ MessageDriver::Client.consumer(:my_consumer) do |message|
36
39
  MessageDriver::Client.publish(:dest_queue, message.body)
37
40
  raise "oh nos!"
38
41
  end
@@ -57,7 +60,7 @@ Feature: Transactional Message Consumers
57
60
  Scenario: When a DontRequeue error occurs
58
61
  Given I have a message consumer
59
62
  """ruby
60
- MessageDriver::Broker.consumer(:my_consumer) do |message|
63
+ MessageDriver::Client.consumer(:my_consumer) do |message|
61
64
  MessageDriver::Client.publish(:dest_queue, message.body)
62
65
  raise MessageDriver::DontRequeueError, "don't requeue me"
63
66
  end
@@ -43,7 +43,7 @@ Feature: DLQ-ing messages with nacks and consumers
43
43
  Scenario: Nacking a message on a manual_ack consumer
44
44
  Given I have a message consumer
45
45
  """ruby
46
- MessageDriver::Broker.consumer(:manual_dql) do |message|
46
+ MessageDriver::Client.consumer(:manual_dql) do |message|
47
47
  message.nack(requeue: false)
48
48
  end
49
49
  """
@@ -68,7 +68,7 @@ Feature: DLQ-ing messages with nacks and consumers
68
68
  Scenario: Raising a DontRequeueError in an auto_ack consumer
69
69
  Given I have a message consumer
70
70
  """ruby
71
- MessageDriver::Broker.consumer(:manual_dql) do |message|
71
+ MessageDriver::Client.consumer(:manual_dql) do |message|
72
72
  raise MessageDriver::DontRequeueError
73
73
  end
74
74
  """
@@ -93,7 +93,7 @@ Feature: DLQ-ing messages with nacks and consumers
93
93
  Scenario: Raising a DontRequeueError in a transactional consumer
94
94
  Given I have a message consumer
95
95
  """ruby
96
- MessageDriver::Broker.consumer(:transactional_dql) do |message|
96
+ MessageDriver::Client.consumer(:transactional_dql) do |message|
97
97
  publish(:rabbit_work, "I get rolled back")
98
98
  raise MessageDriver::DontRequeueError
99
99
  end
@@ -1,11 +1,11 @@
1
1
  Given(/^I have a dynamic destination "(#{STRING_OR_SYM})" with the following messages on it$/) do |destination, table|
2
- dest = MessageDriver::Broker.dynamic_destination(destination)
2
+ dest = MessageDriver::Client[test_runner.broker_name].dynamic_destination(destination)
3
3
  test_runner.publish_table_to_destination(dest, table)
4
4
  end
5
5
 
6
6
  Then(/^I expect to find (#{NUMBER}) messages? on the dynamic destination "(#{STRING_OR_SYM})" with$/) do |count, destination, table|
7
7
  expect(test_runner).to have_no_errors
8
- dest = MessageDriver::Broker.dynamic_destination(destination, passive: true)
8
+ dest = MessageDriver::Client[test_runner.broker_name].dynamic_destination(destination, passive: true)
9
9
  messages = test_runner.fetch_messages(dest)
10
10
  expect(messages).to have(count).items
11
11
  expect(messages).to match_message_table(table)
@@ -8,7 +8,7 @@ Given(/^I am logging to a log file(?: at the (#{STRING_OR_SYM}) level)?$/) do |l
8
8
  @logger = Logger.new(LOG_FILE_NAME)
9
9
  end
10
10
  step "I set the log level to #{level || "info"}"
11
- scenario_config[:logger] = @logger
11
+ @orig_logger, MessageDriver.logger = MessageDriver.logger, @logger
12
12
  end
13
13
 
14
14
  Given(/^I set the log level to (#{STRING_OR_SYM})$/) do |level|
@@ -25,4 +25,8 @@ After do
25
25
  @logger.close
26
26
  @logger = nil
27
27
  end
28
+ if @orig_logger
29
+ MessageDriver.logger = @orig_logger
30
+ @orig_logger = nil
31
+ end
28
32
  end
@@ -4,7 +4,7 @@ Given "I have a message consumer" do |src|
4
4
  end
5
5
 
6
6
  Given(/^I subscribe to (#{STRING_OR_SYM}) with (#{STRING_OR_SYM})$/) do |destination, consumer|
7
- MessageDriver::Client.subscribe(destination, consumer)
7
+ MessageDriver::Client[test_runner.broker_name].subscribe(destination, consumer)
8
8
  end
9
9
 
10
10
  Given "I create a subscription" do |src|
@@ -1,5 +1,10 @@
1
1
  Given "I am connected to the broker" do
2
- MessageDriver.configure(broker_config)
2
+ MessageDriver::Broker.configure(test_runner.broker_name, broker_config)
3
+ end
4
+
5
+ Given(/^I am connected to a broker named (#{STRING_OR_SYM})$/) do |broker_name|
6
+ test_runner.broker_name = broker_name
7
+ step "I am connected to the broker"
3
8
  end
4
9
 
5
10
  Given "the following broker configuration" do |src|
@@ -7,8 +12,12 @@ Given "the following broker configuration" do |src|
7
12
  test_runner.run_config_code(src)
8
13
  end
9
14
 
15
+ Given "I configure my broker as follows" do |src|
16
+ test_runner.run_config_code(src)
17
+ end
18
+
10
19
  Given(/^I have a destination (#{STRING_OR_SYM})$/) do |destination|
11
- MessageDriver::Broker.define do |b|
20
+ MessageDriver::Broker.define(test_runner.broker_name) do |b|
12
21
  b.destination(destination, destination.to_s)
13
22
  end
14
23
  end
@@ -31,7 +40,7 @@ end
31
40
 
32
41
  When(/^I send the following messages? to (#{STRING_OR_SYM})$/) do |destination, table|
33
42
  table.hashes.each do |msg|
34
- MessageDriver::Client.publish(destination, msg[:body])
43
+ MessageDriver::Client[test_runner.broker_name].publish(destination, msg[:body])
35
44
  end
36
45
  end
37
46
 
@@ -40,7 +49,7 @@ When "I execute the following code" do |src|
40
49
  end
41
50
 
42
51
  When "I reset the context" do
43
- MessageDriver::Client.current_adapter_context.invalidate
52
+ MessageDriver::Client[test_runner.broker_name].current_adapter_context.invalidate
44
53
  end
45
54
 
46
55
  When "I allow for processing" do
@@ -4,5 +4,5 @@ require 'aruba/cucumber'
4
4
  require 'message_driver'
5
5
 
6
6
  After do
7
- MessageDriver.stop
7
+ MessageDriver::Broker.reset
8
8
  end
@@ -4,6 +4,11 @@ class TestRunner
4
4
 
5
5
  attr_accessor :raised_error
6
6
  attr_accessor :current_feature_file
7
+ attr_accessor :broker_name
8
+
9
+ def broker_name
10
+ @broker_name ||= MessageDriver::Broker::DEFAULT_BROKER_NAME
11
+ end
7
12
 
8
13
  def run_config_code(src)
9
14
  instance_eval(src, current_feature_file)
@@ -40,7 +45,7 @@ class TestRunner
40
45
  def fetch_destination(destination)
41
46
  case destination
42
47
  when String, Symbol
43
- MessageDriver::Broker.find_destination(destination)
48
+ MessageDriver::Client[self.broker_name].find_destination(destination)
44
49
  when MessageDriver::Destination::Base
45
50
  destination
46
51
  else
@@ -3,11 +3,13 @@ module MessageDriver
3
3
  class Base
4
4
  include Logging
5
5
 
6
+ attr_reader :broker
7
+
6
8
  def contexts
7
9
  @contexts ||= []
8
10
  end
9
11
 
10
- def initialize(configuration)
12
+ def initialize(broker, configuration)
11
13
  raise "Must be implemented in subclass"
12
14
  end
13
15
 
@@ -21,6 +23,10 @@ module MessageDriver
21
23
  raise "Must be implemented in subclass"
22
24
  end
23
25
 
26
+ def reset_after_tests
27
+ #does nothing, can be overridden by adapters that want to support testing scenarios
28
+ end
29
+
24
30
  def stop
25
31
  if @contexts
26
32
  ctxs = @contexts