twingly-amqp 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/twingly/amqp/session.rb +25 -10
- data/lib/twingly/amqp/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73b12f7ad3443cc1515288abad101ab00b0f987
|
4
|
+
data.tar.gz: b6394cd5f3b16025d196f4c67e579f59bf01867c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a921f4a6a8f95184d00a08a33e7947aff1b9996619417f5f689553c7137026833b2a47ee301b1fd65ebe270582f3522f2c0c5aa498931276e2fe882952543b
|
7
|
+
data.tar.gz: 4221dee81f1da5e7237098506dbfeed96d5d5925908651c1becef5983ebada7d6e34d914df7234a579b4da19b0d672bb6d49b4ae629bc0979cb8790e95d8ad0b
|
data/README.md
CHANGED
@@ -28,14 +28,23 @@ Environment variables:
|
|
28
28
|
|
29
29
|
### Customize options
|
30
30
|
|
31
|
-
If you don't have the RabbitMQ hosts in your ENV you can set them with `Twingly::AMQP::Connection.options=` before you create an instance of `Subscription` or `Ping`.
|
31
|
+
If you don't have the RabbitMQ hosts, user or password in your ENV you can set them with `Twingly::AMQP::Connection.options=` before you create an instance of `Subscription` or `Ping`.
|
32
|
+
|
33
|
+
*Options set in `Connection.options=` take precedence over the options defined in `ENV`.*
|
34
|
+
|
35
|
+
All options are sent to `Bunny.new`, see the [documentation][ruby-bunny] for all available options.
|
32
36
|
|
33
37
|
```ruby
|
34
38
|
Twingly::AMQP::Connection.options = {
|
35
|
-
hosts:
|
39
|
+
hosts: %w(localhost),
|
40
|
+
user: "a-user",
|
41
|
+
pass: "1234",
|
42
|
+
# ...
|
36
43
|
}
|
37
44
|
```
|
38
45
|
|
46
|
+
[ruby-bunny]: http://rubybunny.info/articles/connecting.html
|
47
|
+
|
39
48
|
### Subscribe to a queue
|
40
49
|
|
41
50
|
```ruby
|
data/lib/twingly/amqp/session.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Twingly
|
2
2
|
module AMQP
|
3
3
|
class Session
|
4
|
-
attr_reader :connection, :
|
4
|
+
attr_reader :connection, :options
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options
|
8
8
|
@connection = create_connection
|
9
9
|
end
|
10
10
|
|
@@ -14,19 +14,26 @@ module Twingly
|
|
14
14
|
if ruby_env == "development"
|
15
15
|
connection = Bunny.new
|
16
16
|
else
|
17
|
-
connection_options = {
|
18
|
-
hosts: hosts,
|
19
|
-
user: ENV.fetch("AMQP_USERNAME"),
|
20
|
-
pass: ENV.fetch("AMQP_PASSWORD"),
|
21
|
-
recover_from_connection_close: true,
|
22
|
-
tls: tls?,
|
23
|
-
}
|
24
17
|
connection = Bunny.new(connection_options)
|
25
18
|
end
|
26
19
|
connection.start
|
27
20
|
connection
|
28
21
|
end
|
29
22
|
|
23
|
+
def connection_options
|
24
|
+
options[:user] ||= user_from_env
|
25
|
+
options[:pass] ||= password_from_env
|
26
|
+
options[:hosts] ||= hosts_from_env
|
27
|
+
|
28
|
+
default_connection_options.merge(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_connection_options
|
32
|
+
{
|
33
|
+
tls: tls?,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
30
37
|
def ruby_env
|
31
38
|
ENV.fetch("RUBY_ENV")
|
32
39
|
end
|
@@ -35,6 +42,14 @@ module Twingly
|
|
35
42
|
ENV.has_key?("AMQP_TLS")
|
36
43
|
end
|
37
44
|
|
45
|
+
def user_from_env
|
46
|
+
ENV.fetch("AMQP_USERNAME")
|
47
|
+
end
|
48
|
+
|
49
|
+
def password_from_env
|
50
|
+
ENV.fetch("AMQP_PASSWORD")
|
51
|
+
end
|
52
|
+
|
38
53
|
def hosts_from_env
|
39
54
|
# Matches env keys like `RABBITMQ_01_HOST`
|
40
55
|
environment_keys_with_host = ENV.keys.select { |key| key =~ /^rabbitmq_\d+_host$/i }
|
data/lib/twingly/amqp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2'
|
19
|
+
version: '2.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2'
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|