rabbit_feed 2.1.2 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a254021c58185a15c29214a7361fca851d51ae4e
4
- data.tar.gz: 63bddce1a50ec017cf59c61d21d77b5b36910242
3
+ metadata.gz: 58c69d09c8fed13331610e7015a5dcbe19e282cd
4
+ data.tar.gz: fd29cc489c1bb251ab1e16bf35eda04728cc839e
5
5
  SHA512:
6
- metadata.gz: b68e75c49e38da3619904f7144509705d659d97627e3f9b57b4e106023e8ed635c60aaab19dd1496e78321379288c4bae9681ae1be68dacf3842ee72e9c72fe7
7
- data.tar.gz: 58a49087c1cdda30bff123501fb5c8bb3a12f3bf68b9df3f316feb12bb8d67b1fd508a5a147b08e1d5fc26761c6edc4883974ed0f4911fb9b1a1150d431eb996
6
+ metadata.gz: 5389a17aa4bffe0bacbf21f170a86fad67dc23349082502e11fff40b5bb404c405d92c6cfad9e2039bf1d1e00f83c0ccac7d12bf72bd02c2b102520199468511
7
+ data.tar.gz: 458a801d1631ee4be89aa3a5c59f2fd861e810a93117d536b64b2a1d725f0cc5c4162b5c4648601b81a70c03a1ae341b2926715d4865f1e1dc639ed46ac8831f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbit_feed (2.1.2)
4
+ rabbit_feed (2.1.5)
5
5
  activemodel (>= 3.2.0, < 5.0.0)
6
6
  activesupport (>= 3.2.0, < 5.0.0)
7
7
  avro (>= 1.5.4, < 1.8.0)
@@ -12,10 +12,10 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (4.2.0)
16
- activesupport (= 4.2.0)
15
+ activemodel (4.2.3)
16
+ activesupport (= 4.2.3)
17
17
  builder (~> 3.1)
18
- activesupport (4.2.0)
18
+ activesupport (4.2.3)
19
19
  i18n (~> 0.7)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
@@ -34,7 +34,7 @@ GEM
34
34
  simplecov (>= 0.7.1, < 1.0.0)
35
35
  coderay (1.1.0)
36
36
  columnize (0.9.0)
37
- connection_pool (2.1.2)
37
+ connection_pool (2.1.3)
38
38
  debug_inspector (0.0.2)
39
39
  debugger (1.6.8)
40
40
  columnize (>= 0.3.1)
@@ -52,7 +52,7 @@ GEM
52
52
  json
53
53
  json (1.8.2)
54
54
  method_source (0.8.2)
55
- minitest (5.5.1)
55
+ minitest (5.7.0)
56
56
  multi_json (1.10.1)
57
57
  pidfile (0.3.0)
58
58
  pry (0.10.1)
@@ -107,7 +107,7 @@ GEM
107
107
  simplecov-html (~> 0.9.0)
108
108
  simplecov-html (0.9.0)
109
109
  slop (3.6.0)
110
- thread_safe (0.3.4)
110
+ thread_safe (0.3.5)
111
111
  timecop (0.7.3)
112
112
  turnip (1.2.4)
113
113
  gherkin (>= 2.5)
@@ -128,3 +128,6 @@ DEPENDENCIES
128
128
  rspec-its
129
129
  rutabaga
130
130
  timecop
131
+
132
+ BUNDLED WITH
133
+ 1.10.5
data/README.md CHANGED
@@ -20,7 +20,7 @@ Add this line to your application's Gemfile:
20
20
 
21
21
  ### Configuration
22
22
 
23
- Create a `config/rabbit_feed.yml` file. The following options can be specified:
23
+ Create a `config/rabbit_feed.yml` file. The following options should be specified:
24
24
 
25
25
  environment:
26
26
  host: RabbitMQ host
@@ -36,6 +36,24 @@ Sample:
36
36
  password: guest
37
37
  application: beavers
38
38
 
39
+ Configuration options that can be specified are:
40
+
41
+ | Name | Use |
42
+ | ---- | --- |
43
+ | `host` | Hostname or IP of the RabbitMQ server |
44
+ | `hosts` | Array of hostnames or IPs of a RabbitMQ cluster |
45
+ | `port` | The port to use on the RabbitMQ server |
46
+ | `user` | The user to authenticate with the RabbitMQ server |
47
+ | `password` | The password to authenticate with the RabbitMQ server |
48
+ | `application` | The name of the application - used for routing events to the specified consumers |
49
+ | `environment` | The environment of the application - used for routing events to the specified consumers |
50
+ | `exchange` | The name of the RabbitMQ exchange to which events are published |
51
+ | `heartbeat` | The interval at which to send heartbeats to the RabbitMQ server (in seconds) |
52
+ | `connect_timeout` | The timeout (in seconds) for connecting to the RabbitMQ server |
53
+ | `network_recovery_interval` | Recovery interval (in seconds) periodic network recovery will use |
54
+ | `auto_delete_queue` | If true, any queues created will auto-delete upon disconnect |
55
+ | `auto_delete_exchange` | If true, any exchanges created will auto-delete upon disconnect |
56
+
39
57
  ### Initialisation
40
58
 
41
59
  If installing in a rails application, the following should be defined in `config/initializers/rabbit_feed.rb`:
@@ -219,6 +237,7 @@ Publishes an event. Note: until you've specified the [event definitions](https:/
219
237
  Starts a consumer. Note: until you've specified the [event routing](https://github.com/simplybusiness/rabbit_feed#event-routing-dsl), this will not receive any events. Options are as follows:
220
238
 
221
239
  --environment The environment to run in
240
+ --application The name of the application (used for routing events)
222
241
  --config The location of the rabbit_feed configuration file
223
242
  --logfile The location of the log file
224
243
  --require The project file containing the dependancies (only necessary if running with non-rails application)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.1.1)
4
+ rabbit_feed (2.1.5)
5
5
  activemodel (>= 3.2.0, < 5.0.0)
6
6
  activesupport (>= 3.2.0, < 5.0.0)
7
7
  avro (>= 1.5.4, < 1.8.0)
@@ -12,10 +12,10 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (4.2.0)
16
- activesupport (= 4.2.0)
15
+ activemodel (4.2.3)
16
+ activesupport (= 4.2.3)
17
17
  builder (~> 3.1)
18
- activesupport (4.2.0)
18
+ activesupport (4.2.3)
19
19
  i18n (~> 0.7)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
@@ -27,12 +27,12 @@ GEM
27
27
  builder (3.2.2)
28
28
  bunny (1.7.0)
29
29
  amq-protocol (>= 1.9.2)
30
- connection_pool (2.1.2)
30
+ connection_pool (2.1.3)
31
31
  diff-lcs (1.2.5)
32
32
  i18n (0.7.0)
33
- json (1.8.2)
34
- minitest (5.5.1)
35
- multi_json (1.11.0)
33
+ json (1.8.3)
34
+ minitest (5.7.0)
35
+ multi_json (1.11.1)
36
36
  pidfile (0.3.0)
37
37
  rake (10.4.2)
38
38
  rspec (3.2.0)
@@ -48,7 +48,7 @@ GEM
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.2.0)
50
50
  rspec-support (3.2.1)
51
- thread_safe (0.3.4)
51
+ thread_safe (0.3.5)
52
52
  tzinfo (1.2.2)
53
53
  thread_safe (~> 0.1)
54
54
 
@@ -59,3 +59,6 @@ DEPENDENCIES
59
59
  rabbit_feed!
60
60
  rake
61
61
  rspec
62
+
63
+ BUNDLED WITH
64
+ 1.10.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.1.1)
4
+ rabbit_feed (2.1.5)
5
5
  activemodel (>= 3.2.0, < 5.0.0)
6
6
  activesupport (>= 3.2.0, < 5.0.0)
7
7
  avro (>= 1.5.4, < 1.8.0)
@@ -61,7 +61,7 @@ GEM
61
61
  coffee-script-source
62
62
  execjs
63
63
  coffee-script-source (1.9.1)
64
- connection_pool (2.1.2)
64
+ connection_pool (2.1.3)
65
65
  diff-lcs (1.2.5)
66
66
  erubis (2.7.0)
67
67
  execjs (2.3.0)
@@ -189,3 +189,6 @@ DEPENDENCIES
189
189
  turbolinks
190
190
  uglifier (>= 1.3.0)
191
191
  unicorn
192
+
193
+ BUNDLED WITH
194
+ 1.10.5
@@ -92,6 +92,7 @@ module RabbitFeed
92
92
 
93
93
  def set_configuration
94
94
  RabbitFeed.environment = environment
95
+ RabbitFeed.application = options[:application]
95
96
  RabbitFeed.configuration_file_path = options[:config_file]
96
97
  ENV['RACK_ENV'] ||= RabbitFeed.environment
97
98
  ENV['RAILS_ENV'] ||= RabbitFeed.environment
@@ -138,6 +139,10 @@ module RabbitFeed
138
139
 
139
140
  parser = OptionParser.new do |o|
140
141
 
142
+ o.on '-a', '--application VAL', 'Name of the application' do |arg|
143
+ opts[:application] = arg
144
+ end
145
+
141
146
  o.on '-m', '--payload VAL', 'Payload of event to produce' do |arg|
142
147
  opts[:payload] = arg
143
148
  end
@@ -2,13 +2,14 @@ module RabbitFeed
2
2
  class Configuration
3
3
  include ActiveModel::Validations
4
4
 
5
- attr_reader :host, :port, :user, :password, :application, :environment, :exchange, :pool_size, :pool_timeout, :heartbeat, :connect_timeout, :network_recovery_interval, :auto_delete_queue, :auto_delete_exchange
5
+ attr_reader :host, :hosts, :port, :user, :password, :application, :environment, :exchange, :pool_size, :pool_timeout, :heartbeat, :connect_timeout, :network_recovery_interval, :auto_delete_queue, :auto_delete_exchange
6
6
  validates_presence_of :application, :environment, :exchange, :pool_timeout
7
7
 
8
8
  def initialize options
9
9
  RabbitFeed.log.debug "RabbitFeed initialising with options: #{options}..."
10
10
 
11
11
  @host = options[:host]
12
+ @hosts = options[:hosts]
12
13
  @port = options[:port]
13
14
  @user = options[:user]
14
15
  @password = options[:password]
@@ -24,13 +25,15 @@ module RabbitFeed
24
25
  validate!
25
26
  end
26
27
 
27
- def self.load file_path, environment
28
- RabbitFeed.log.debug "Reading configurations from #{file_path} in #{environment}..."
28
+ def self.load file_path, environment, application
29
+ RabbitFeed.log.debug "Reading configurations from #{file_path} in #{environment} for application #{application}..."
29
30
 
30
31
  raise ConfigurationError.new "The RabbitFeed configuration file path specified does not exist: #{file_path}" unless (File.exist? file_path)
31
32
 
32
33
  options = read_configuration_file file_path, environment
33
- new options.merge(environment: environment)
34
+ options[:environment] = environment
35
+ options[:application] ||= application
36
+ new options
34
37
  end
35
38
 
36
39
  def queue
@@ -42,6 +45,7 @@ module RabbitFeed
42
45
  options[:heartbeat] = heartbeat if heartbeat
43
46
  options[:connect_timeout] = connect_timeout if connect_timeout
44
47
  options[:host] = host if host
48
+ options[:hosts] = hosts if hosts
45
49
  options[:user] = user if user
46
50
  options[:password] = password if password
47
51
  options[:port] = port if port
@@ -42,9 +42,10 @@ module RabbitFeed
42
42
  end
43
43
 
44
44
  sleep # Sleep indefinitely, as the consumer runs in its own thread
45
- rescue
45
+ rescue SystemExit, Interrupt
46
+ RabbitFeed.log.info "Consumer #{self.to_s} received exit request, exiting..."
47
+ ensure
46
48
  (cancel_consumer consumer) if consumer.present?
47
- raise
48
49
  end
49
50
 
50
51
  private
@@ -1,3 +1,3 @@
1
1
  module RabbitFeed
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.5'
3
3
  end
data/lib/rabbit_feed.rb CHANGED
@@ -26,13 +26,13 @@ module RabbitFeed
26
26
  class RoutingError < Error; end
27
27
  class ReturnedMessageError < Error; end
28
28
 
29
- attr_accessor :log, :environment, :configuration_file_path
29
+ attr_accessor :log, :environment, :configuration_file_path, :application
30
30
 
31
31
  def configuration
32
32
  RabbitFeed.log ||= (Logger.new STDOUT)
33
33
  RabbitFeed.configuration_file_path ||= 'config/rabbit_feed.yml'
34
34
  RabbitFeed.environment ||= ENV['RAILS_ENV'] || ENV['RACK_ENV']
35
- @configuration ||= (Configuration.load RabbitFeed.configuration_file_path, RabbitFeed.environment)
35
+ @configuration ||= (Configuration.load RabbitFeed.configuration_file_path, RabbitFeed.environment, application)
36
36
  end
37
37
 
38
38
  def exception_notify exception
@@ -11,3 +11,4 @@ test:
11
11
  network_recovery_interval: 0.1
12
12
  auto_delete_queue: true
13
13
  auto_delete_exchange: true
14
+ test_blank:
@@ -8,6 +8,7 @@ module RabbitFeed
8
8
  let(:config_file) { 'spec/fixtures/configuration.yml' }
9
9
  let(:environment) { 'test' }
10
10
  let(:require_file){ 'rabbit_feed.rb' }
11
+ let(:application) { 'rabbit_feed_test' }
11
12
  let(:arguments) do
12
13
  [
13
14
  command,
@@ -21,11 +22,14 @@ module RabbitFeed
21
22
  pidfile,
22
23
  '--require',
23
24
  require_file,
25
+ '--application',
26
+ application,
24
27
  '--daemon'
25
28
  ]
26
29
  end
27
30
  before do
28
31
  RabbitFeed.environment = nil
32
+ RabbitFeed.application = nil
29
33
  RabbitFeed.log = nil
30
34
  RabbitFeed.configuration_file_path = nil
31
35
  end
@@ -40,6 +44,11 @@ module RabbitFeed
40
44
  expect(RabbitFeed.environment).to eq 'test'
41
45
  end
42
46
 
47
+ it 'sets the application' do
48
+ subject
49
+ expect(RabbitFeed.application).to eq 'rabbit_feed_test'
50
+ end
51
+
43
52
  it 'sets the logger' do
44
53
  subject
45
54
  expect(RabbitFeed.log).to be_a Logger
@@ -69,7 +69,8 @@ module RabbitFeed
69
69
  describe '.load' do
70
70
  let(:file_path) { 'spec/fixtures/configuration.yml' }
71
71
  let(:environment) { 'test' }
72
- subject { described_class.load file_path, environment }
72
+ let(:application) { }
73
+ subject { described_class.load file_path, environment, application }
73
74
 
74
75
  context 'with missing configuration' do
75
76
  let(:environment) { 'production' }
@@ -104,6 +105,21 @@ module RabbitFeed
104
105
  its(:auto_delete_exchange) { should be_truthy }
105
106
  end
106
107
 
108
+ context 'with application provided' do
109
+ let(:application) { 'new_application' }
110
+
111
+ it 'prefers the application specified in the config file' do
112
+ expect(subject.application).to eq 'rabbit_feed'
113
+ end
114
+
115
+ context 'with an empty config file' do
116
+ let(:environment) { 'test_blank' }
117
+
118
+ it 'prefers the application provided' do
119
+ expect(subject.application).to eq 'new_application'
120
+ end
121
+ end
122
+ end
107
123
  end
108
124
 
109
125
  describe '.new' do
@@ -119,6 +135,7 @@ module RabbitFeed
119
135
  end
120
136
 
121
137
  its(:host) { should be_nil }
138
+ its(:hosts) { should be_nil }
122
139
  its(:port) { should be_nil }
123
140
  its(:user) { should be_nil }
124
141
  its(:password) { should be_nil }
@@ -135,6 +152,7 @@ module RabbitFeed
135
152
  let(:options) do
136
153
  {
137
154
  host: 'host_name',
155
+ hosts: ['host_name0', 'host_name1'],
138
156
  port: 12345,
139
157
  user: 'user_name',
140
158
  password: 'password',
@@ -151,6 +169,7 @@ module RabbitFeed
151
169
  end
152
170
 
153
171
  its(:host) { should eq 'host_name' }
172
+ its(:hosts) { should eq ['host_name0', 'host_name1'] }
154
173
  its(:port) { should eq 12345 }
155
174
  its(:user) { should eq 'user_name' }
156
175
  its(:password) { should eq 'password' }
@@ -46,6 +46,7 @@ module RabbitFeed
46
46
  before do
47
47
  allow(bunny_queue).to receive(:subscribe).and_yield(double(:delivery_info, delivery_tag: :tag), 'properties', 'payload')
48
48
  allow_any_instance_of(described_class).to receive(:sleep)
49
+ allow_any_instance_of(described_class).to receive(:cancel_consumer)
49
50
  end
50
51
 
51
52
  it 'yields the payload' do
@@ -57,6 +58,11 @@ module RabbitFeed
57
58
  subject.consume { }
58
59
  end
59
60
 
61
+ it 'cancels the consumer' do
62
+ expect_any_instance_of(described_class).to receive(:cancel_consumer)
63
+ subject.consume { }
64
+ end
65
+
60
66
  context 'when an exception is raised' do
61
67
 
62
68
  context 'when Airbrake is defined' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  version: '0'
313
313
  requirements: []
314
314
  rubyforge_project:
315
- rubygems_version: 2.4.6
315
+ rubygems_version: 2.4.7
316
316
  signing_key:
317
317
  specification_version: 4
318
318
  summary: Enables your Ruby applications to perform centralized event logging with