watership 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watership/consumer.rb +11 -4
- data/lib/watership/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f34462d07d21cabc6ed72315b700aea62faba2c6
|
4
|
+
data.tar.gz: 690a5c5d300ac0568378184d442df18bc5c53a11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ec9f80a2f1bd1b6462c8d2edc6e7ff4770f1b978b8ae1506ee6e124d5d86cb88cbfac1858174e6f7f408879d6d3cbbbb7c73b39e18b0563be3ca3399cc8eb5
|
7
|
+
data.tar.gz: 54e57a65d3ec490a72f04ac1a14ce841f35aa947fb817f64ae211715df46a6db9d000a717f40036615d5f43eff31079f2bd3c1cc0ebbaf98d6c3202c8451631f
|
data/lib/watership/consumer.rb
CHANGED
@@ -2,15 +2,18 @@ require "json"
|
|
2
2
|
|
3
3
|
module Watership
|
4
4
|
class Consumer
|
5
|
-
def initialize(consumer, url)
|
5
|
+
def initialize(consumer, url, channel_options = {}, queue_options = {})
|
6
6
|
@consumer = consumer
|
7
7
|
@url = url
|
8
|
+
@prefetch = channel_options.delete(:prefetch) || 0
|
9
|
+
@channel_opts = {durable: true}.merge(channel_options)
|
10
|
+
@queue_opts = {block: true, ack: true}.merge(queue_options)
|
8
11
|
end
|
9
12
|
|
10
13
|
def consume
|
11
14
|
Thread.abort_on_exception = true
|
12
15
|
begin
|
13
|
-
queue.subscribe(
|
16
|
+
queue.subscribe(@queue_opts) do |delivery_info, properties, payload|
|
14
17
|
success = false
|
15
18
|
begin
|
16
19
|
@consumer.call(JSON.parse(payload))
|
@@ -45,7 +48,7 @@ module Watership
|
|
45
48
|
private
|
46
49
|
|
47
50
|
def queue
|
48
|
-
@queue ||= channel.queue(@consumer.class::QUEUE,
|
51
|
+
@queue ||= channel.queue(@consumer.class::QUEUE, @channel_options)
|
49
52
|
end
|
50
53
|
|
51
54
|
def connection
|
@@ -53,7 +56,11 @@ module Watership
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def channel
|
56
|
-
@
|
59
|
+
@channel ||= begin
|
60
|
+
c = connection.create_channel
|
61
|
+
c.prefetch(@prefetch)
|
62
|
+
c
|
63
|
+
end
|
57
64
|
end
|
58
65
|
end
|
59
66
|
end
|
data/lib/watership/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Scofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|