msgr 0.2.1 → 0.3.0

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: 1b95de3e709c9032c20b8b63b90b83cd07ce8581
4
- data.tar.gz: e16b2af077347d2e2ffb864f610018ef5269b378
3
+ metadata.gz: 8948601f4dd6d56c3d502ec2c9898e7b0d6bd6d7
4
+ data.tar.gz: 4f4bf4567945427f5296f5d9e38f064ed54b8769
5
5
  SHA512:
6
- metadata.gz: 5325d0a5774c9409507c7f9b19652ba91b83ccba80e1d710d87b2df1d49a83de3d456078ab360849dfbe9f5691ee661104124fcd55f197ae3092da4378350a83
7
- data.tar.gz: 891458be94a172ed4c9a724ca90d905d861eb77e84823f8240c309bcd76027d43c60d87657b8a1f2d759e6d92e55f9bd032104f3a196e9d109464a7724ec1b50
6
+ metadata.gz: 70a9b7e8ed8a3e94dbb6fde5401954661911450f8ffadf7a19135d682f6088d81565151b5fcfe933bbb7b08392f35126c53aab957a1019ec9535d227fdfa06c9
7
+ data.tar.gz: d8761f0ec024977fce524b91127f7728a302734ad88dfcaa6a40cd77df1aaf2168ea187007df33d9e9ac436c392a09add8bb709beac203dfe77c54064109c949
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ * Support for forking web servers like unicorn
6
+
7
+ ## 0.2.1
8
+
9
+ * Fix wrong rails initializer code - was not use the config file
10
+
11
+ ## 0.2.0
12
+
13
+ * Improve rails initializer code
data/README.md CHANGED
@@ -84,6 +84,20 @@ class TestController < ApplicationController
84
84
  end
85
85
  ```
86
86
 
87
+ ## Msgr and fork web server like unicorn
88
+
89
+ Per default msgr opens the rabbitmq connect when rails is loaded. If you use a multi-process web server that preloads the application (like unicorn) will lead to unexpected behavior. In this case adjust `config/rabbitmq.yml` and adjust `autostart = false`:
90
+
91
+
92
+ ```yaml
93
+ common: &common
94
+ uri: amqp://localhost/
95
+ autostart: false
96
+ ```
97
+
98
+ And call inside each worker `Msgr.client.start` - e.g. in an after-fork block
99
+
100
+
87
101
  ## Contributing
88
102
 
89
103
  1. Fork it
data/lib/msgr/client.rb CHANGED
@@ -19,9 +19,7 @@ module Msgr
19
19
  @uri.path = config[:vhost] ||= @uri.path.present? ? @uri.path : '/'
20
20
  config.reject! { |_,v| v.nil? }
21
21
 
22
- @config = config
23
- @bunny = Bunny.new config
24
- @pool = Pool.new Dispatcher, size: config[:size]
22
+ @config = config
25
23
  end
26
24
 
27
25
  def running?; @running end
@@ -51,10 +49,8 @@ module Msgr
51
49
  def start
52
50
  log(:info) { "Start client to #{uri}" }
53
51
 
54
- @bunny.start
55
- @pool.start
56
- @running = true
57
- new_connection
52
+ init
53
+ launch
58
54
 
59
55
  log(:info) { 'Client started.' }
60
56
  end
@@ -109,5 +105,17 @@ module Msgr
109
105
  rescue TimeoutError
110
106
  log(:warn) { "Could not shutdown pool within #{timeout} seconds." }
111
107
  end
108
+
109
+ def init
110
+ @bunny = Bunny.new @config
111
+ @pool = Pool.new Dispatcher, size: @config[:size]
112
+ end
113
+
114
+ def launch
115
+ @bunny.start
116
+ @pool.start
117
+ @running = true
118
+ new_connection
119
+ end
112
120
  end
113
121
  end
data/lib/msgr/railtie.rb CHANGED
@@ -48,7 +48,7 @@ module Msgr
48
48
  end
49
49
 
50
50
  Msgr.client = client
51
- client.start
51
+ client.start unless cfg[:autostart] and cfg[:autostart] == 'false'
52
52
  else
53
53
  raise ArgumentError, 'Could not load rabbitmq environment config: URI missing.'
54
54
  end
data/lib/msgr/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Msgr
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
8
8
 
@@ -2,23 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe Msgr::Client do
4
4
 
5
- describe '#initialize' do
5
+ describe '#start' do
6
6
  let(:params) { [] }
7
7
  let(:client) { Msgr::Client.new *params }
8
+ before { allow_any_instance_of(Msgr::Client).to receive(:launch) }
8
9
 
9
10
  context 'with URI' do
10
11
  it 'should pass URI options to bunny (I)' do
11
12
  expect(Bunny).to receive(:new)
12
13
  .with(pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/')
13
14
 
14
- Msgr::Client.new uri: 'amqp://guest:guest@localhost/'
15
+ Msgr::Client.new(uri: 'amqp://guest:guest@localhost/').start
15
16
  end
16
17
 
17
18
  it 'should pass URI options to bunny (II)' do
18
19
  expect(Bunny).to receive(:new)
19
20
  .with(pass: 'msgr', user: 'abc', ssl: true, host: 'bogus.example.org', vhost: '/rabbit')
20
21
 
21
- Msgr::Client.new uri: 'amqps://abc:msgr@bogus.example.org/rabbit'
22
+ Msgr::Client.new(uri: 'amqps://abc:msgr@bogus.example.org/rabbit').start
22
23
  end
23
24
  end
24
25
 
@@ -27,7 +28,7 @@ describe Msgr::Client do
27
28
  expect(Bunny).to receive(:new)
28
29
  .with(pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/')
29
30
 
30
- Msgr::Client.new pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/'
31
+ Msgr::Client.new(pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/').start
31
32
  end
32
33
  end
33
34
 
@@ -36,14 +37,14 @@ describe Msgr::Client do
36
37
  expect(Bunny).to receive(:new)
37
38
  .with(pass: 'msgr', user: 'abc', ssl: false, host: 'localhost', vhost: '/joghurt')
38
39
 
39
- Msgr::Client.new uri: 'ampq://abc@localhost', pass: 'msgr', vhost: '/joghurt'
40
+ Msgr::Client.new(uri: 'ampq://abc@localhost', pass: 'msgr', vhost: '/joghurt').start
40
41
  end
41
42
 
42
43
  it 'should pass prefer hash option' do
43
44
  expect(Bunny).to receive(:new)
44
45
  .with(ssl: true, host: 'a.example.org', vhost: '/', user: 'guest')
45
46
 
46
- Msgr::Client.new uri: 'ampq://localhost', ssl: true, host: 'a.example.org'
47
+ Msgr::Client.new(uri: 'ampq://localhost', ssl: true, host: 'a.example.org').start
47
48
  end
48
49
  end
49
50
  end
@@ -7,45 +7,6 @@ describe Msgr::Connection do
7
7
  let(:routes) { Msgr::Routes.new }
8
8
  let(:connection) { Msgr::Connection.new conn, routes, dispatcher }
9
9
 
10
- context 'with URI' do
11
- it 'should pass URI options to bunny (I)' do
12
- expect(Bunny).to receive(:new)
13
- .with(pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/')
14
-
15
- Msgr::Client.new uri: 'amqp://guest:guest@localhost/'
16
- end
17
-
18
- it 'should pass URI options to bunny (II)' do
19
- expect(Bunny).to receive(:new)
20
- .with(pass: 'msgr', user: 'abc', ssl: true, host: 'bogus.example.org', vhost: '/rabbit')
21
-
22
- Msgr::Client.new uri: 'amqps://abc:msgr@bogus.example.org/rabbit'
23
- end
24
- end
25
-
26
- context 'with options' do
27
- it 'should pass options to bunny' do
28
- expect(Bunny).to receive(:new)
29
- .with(pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/')
30
-
31
- Msgr::Client.new pass: 'guest', user: 'guest', ssl: false, host: 'localhost', vhost: '/'
32
- end
33
- end
34
-
35
- context 'with URI and options' do
36
- it 'should pass merged options to bunny' do
37
- expect(Bunny).to receive(:new)
38
- .with(pass: 'msgr', user: 'abc', ssl: false, host: 'localhost', vhost: '/joghurt')
39
-
40
- Msgr::Client.new uri: 'ampq://abc@localhost', pass: 'msgr', vhost: '/joghurt'
41
- end
42
-
43
- it 'should pass prefer hash option' do
44
- expect(Bunny).to receive(:new)
45
- .with(ssl: true, host: 'a.example.org', vhost: '/', user: 'guest')
46
-
47
- Msgr::Client.new uri: 'ampq://localhost', ssl: true, host: 'a.example.org'
48
- end
49
- end
10
+ pending 'some tests missing -> only lets written'
50
11
  end
51
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - CHANGELOG.md
78
79
  - Gemfile
79
80
  - Guardfile
80
81
  - LICENSE.txt