action_subscriber 2.1.0.pre1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_subscriber.rb +1 -0
- data/lib/action_subscriber/configuration.rb +15 -2
- data/lib/action_subscriber/rabbit_connection.rb +4 -1
- data/lib/action_subscriber/uri.rb +28 -0
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/configuration_spec.rb +12 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31b26344944773ea0c63f2ba81c2b9d2d9e3c8b
|
4
|
+
data.tar.gz: f8f231f821d5b33937abfff11ce996033d810f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f095a28d75908af71ef2bbf5d75638b434663248bef1b728818ff566c5b21cbd411a4dc17bd5ffa89964516636d38ffd506d781df4b53411bf5d3a3769bfa5c
|
7
|
+
data.tar.gz: e20052f487628bd2bd7a4af42c399db06c4257f17b3adaaf3aafeff272f4031816899ef4a30053d871aa9313790b4cf591fbd70445117baed92734785d710d87
|
data/lib/action_subscriber.rb
CHANGED
@@ -12,14 +12,17 @@ module ActionSubscriber
|
|
12
12
|
:host,
|
13
13
|
:hosts,
|
14
14
|
:mode,
|
15
|
+
:password,
|
15
16
|
:pop_interval,
|
16
17
|
:port,
|
17
18
|
:prefetch,
|
18
19
|
:publisher_confirms,
|
19
20
|
:seconds_to_wait_for_graceful_shutdown,
|
21
|
+
:username,
|
20
22
|
:threadpool_size,
|
21
23
|
:timeout,
|
22
|
-
:times_to_pop
|
24
|
+
:times_to_pop,
|
25
|
+
:virtual_host
|
23
26
|
|
24
27
|
DEFAULTS = {
|
25
28
|
:allow_low_priority_methods => false,
|
@@ -39,7 +42,10 @@ module ActionSubscriber
|
|
39
42
|
:seconds_to_wait_for_graceful_shutdown => 30,
|
40
43
|
:threadpool_size => 8,
|
41
44
|
:timeout => 1,
|
42
|
-
:times_to_pop => 8
|
45
|
+
:times_to_pop => 8,
|
46
|
+
:username => "guest",
|
47
|
+
:password => "guest",
|
48
|
+
:virtual_host => "/"
|
43
49
|
}
|
44
50
|
|
45
51
|
##
|
@@ -89,6 +95,13 @@ module ActionSubscriber
|
|
89
95
|
self.decoder.merge!(decoders)
|
90
96
|
end
|
91
97
|
|
98
|
+
def connection_string=(url)
|
99
|
+
settings = ::ActionSubscriber::URI.parse_amqp_url(url)
|
100
|
+
settings.each do |key, value|
|
101
|
+
send("#{key}=", value)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
92
105
|
def hosts
|
93
106
|
return @hosts if @hosts.size > 0
|
94
107
|
[ host ]
|
@@ -62,10 +62,13 @@ module ActionSubscriber
|
|
62
62
|
|
63
63
|
def self.connection_options
|
64
64
|
{
|
65
|
+
:continuation_timeout => ::ActionSubscriber.configuration.timeout * 1_000.0, #convert sec to ms
|
65
66
|
:heartbeat => ::ActionSubscriber.configuration.heartbeat,
|
66
67
|
:hosts => ::ActionSubscriber.configuration.hosts,
|
68
|
+
:pass => ::ActionSubscriber.configuration.password,
|
67
69
|
:port => ::ActionSubscriber.configuration.port,
|
68
|
-
:
|
70
|
+
:user => ::ActionSubscriber.configuration.username,
|
71
|
+
:vhost => ::ActionSubscriber.configuration.virtual_host,
|
69
72
|
:automatically_recover => true,
|
70
73
|
:network_recovery_interval => NETWORK_RECOVERY_INTERVAL,
|
71
74
|
:recover_from_connection_close => true,
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Taken and adapted from https://github.com/ruby-amqp/amq-protocol/blob/master/lib/amq/uri.rb
|
2
|
+
require "cgi"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module ActionSubscriber
|
6
|
+
class URI
|
7
|
+
AMQP_PORTS = {"amqp" => 5672, "amqps" => 5671}.freeze
|
8
|
+
|
9
|
+
def self.parse_amqp_url(connection_string)
|
10
|
+
uri = ::URI.parse(connection_string)
|
11
|
+
raise ArgumentError.new("Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK") unless %w{amqp amqps}.include?(uri.scheme)
|
12
|
+
|
13
|
+
opts = {}
|
14
|
+
|
15
|
+
opts[:username] = ::CGI::unescape(uri.user) if uri.user
|
16
|
+
opts[:password] = ::CGI::unescape(uri.password) if uri.password
|
17
|
+
opts[:host] = uri.host if uri.host
|
18
|
+
opts[:port] = uri.port || AMQP_PORTS[uri.scheme]
|
19
|
+
|
20
|
+
if uri.path =~ %r{^/(.*)}
|
21
|
+
raise ArgumentError.new("#{uri} has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris") if $1.index('/')
|
22
|
+
opts[:virtual_host] = ::CGI::unescape($1)
|
23
|
+
end
|
24
|
+
|
25
|
+
opts
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -5,6 +5,7 @@ describe ::ActionSubscriber::Configuration do
|
|
5
5
|
specify { expect(subject.async_publisher_drop_messages_when_queue_full).to eq(false) }
|
6
6
|
specify { expect(subject.async_publisher_max_queue_size).to eq(1_000_000) }
|
7
7
|
specify { expect(subject.async_publisher_supervisor_interval).to eq(200) }
|
8
|
+
specify { expect(subject.default_exchange).to eq("events") }
|
8
9
|
specify { expect(subject.heartbeat).to eq(5) }
|
9
10
|
specify { expect(subject.host).to eq("localhost") }
|
10
11
|
specify { expect(subject.mode).to eq('subscribe') }
|
@@ -37,4 +38,15 @@ describe ::ActionSubscriber::Configuration do
|
|
37
38
|
}.to raise_error(/The foo decoder was given with arity of 2/)
|
38
39
|
end
|
39
40
|
end
|
41
|
+
|
42
|
+
describe "connection_string" do
|
43
|
+
it "explodes the connection string into the corresponding settings" do
|
44
|
+
subject.connection_string = "amqp://user:pass@host:100/vhost"
|
45
|
+
expect(subject.username).to eq("user")
|
46
|
+
expect(subject.password).to eq("pass")
|
47
|
+
expect(subject.host).to eq("host")
|
48
|
+
expect(subject.port).to eq(100)
|
49
|
+
expect(subject.virtual_host).to eq("vhost")
|
50
|
+
end
|
51
|
+
end
|
40
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-02-
|
15
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/action_subscriber/rspec.rb
|
225
225
|
- lib/action_subscriber/subscribable.rb
|
226
226
|
- lib/action_subscriber/threadpool.rb
|
227
|
+
- lib/action_subscriber/uri.rb
|
227
228
|
- lib/action_subscriber/version.rb
|
228
229
|
- routing.md
|
229
230
|
- spec/integration/around_filters_spec.rb
|
@@ -270,9 +271,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
270
271
|
version: '0'
|
271
272
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
272
273
|
requirements:
|
273
|
-
- - "
|
274
|
+
- - ">="
|
274
275
|
- !ruby/object:Gem::Version
|
275
|
-
version:
|
276
|
+
version: '0'
|
276
277
|
requirements: []
|
277
278
|
rubyforge_project:
|
278
279
|
rubygems_version: 2.4.5
|