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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +14 -0
- data/lib/msgr/client.rb +15 -7
- data/lib/msgr/railtie.rb +1 -1
- data/lib/msgr/version.rb +2 -2
- data/spec/msgr/msgr/client_spec.rb +7 -6
- data/spec/msgr/msgr/connection_spec.rb +1 -40
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8948601f4dd6d56c3d502ec2c9898e7b0d6bd6d7
|
4
|
+
data.tar.gz: 4f4bf4567945427f5296f5d9e38f064ed54b8769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a9b7e8ed8a3e94dbb6fde5401954661911450f8ffadf7a19135d682f6088d81565151b5fcfe933bbb7b08392f35126c53aab957a1019ec9535d227fdfa06c9
|
7
|
+
data.tar.gz: d8761f0ec024977fce524b91127f7728a302734ad88dfcaa6a40cd77df1aaf2168ea187007df33d9e9ac436c392a09add8bb709beac203dfe77c54064109c949
|
data/CHANGELOG.md
ADDED
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
|
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
|
-
|
55
|
-
|
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
data/lib/msgr/version.rb
CHANGED
@@ -2,23 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Msgr::Client do
|
4
4
|
|
5
|
-
describe '#
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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.
|
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-
|
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
|