cotton-tail 0.1.2 → 0.2.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
- checksums.yaml.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/cotton-tail.gemspec +1 -1
- data/lib/cotton_tail/app.rb +1 -1
- data/lib/cotton_tail/configuration.rb +17 -0
- data/lib/cotton_tail/queue/bunny.rb +39 -21
- data/lib/cotton_tail/version.rb +1 -1
- data/lib/cotton_tail.rb +15 -0
- data.tar.gz.sig +2 -2
- metadata +4 -4
- metadata.gz.sig +0 -0
- data/lib/cotton_tail/queue/connection.rb +0 -37
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b08350ef7f0bcfc64c8c78ce7728a137c2d66a67b72052493c4946680f40178a
|
|
4
|
+
data.tar.gz: 32fab7c085c98cc66bbabedfcc23d9e574a7f4c5097c733813b73d30a26866c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb8aabeeb45a3c4d81a177808cfb05dea3e248edc6308ccbf19acb8e380b750144f36884931cd1c0ac67b0581353d708f23957f390db748926e868602c7393e3
|
|
7
|
+
data.tar.gz: 037abfc33e2530440cca0456e92123daf2d26f4d0ddf0f7f30659a8d61d5203e9b7b97230a52488c59864f3d0cfe653cafa8c794c3df45bbd3fae8367fbd6a67
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# CottonTail
|
|
2
2
|
|
|
3
|
-
CottonTail provides a simple DSL for consuming messages from a RabbitMQ server
|
|
3
|
+
CottonTail provides a simple DSL for consuming messages from a RabbitMQ server.
|
|
4
|
+
|
|
5
|
+
This gem is in early development. The API will be unstable until the 1.0.0
|
|
6
|
+
release.
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
data/cotton-tail.gemspec
CHANGED
data/lib/cotton_tail/app.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CottonTail
|
|
4
|
+
# Configuration options
|
|
5
|
+
class Configuration
|
|
6
|
+
attr_reader :connection_args
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@connection_args = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def connection_args=(*args, **kwargs)
|
|
13
|
+
url, = args
|
|
14
|
+
@connection_args = url ? Bunny::Session.parse_uri(url) : kwargs
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,47 +1,65 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
require 'bunny'
|
|
5
|
+
|
|
3
6
|
module CottonTail
|
|
4
7
|
module Queue
|
|
5
8
|
# A wrapper around a ::Bunny::Queue that makes it interchangeable with a
|
|
6
|
-
# standard Ruby
|
|
7
|
-
class Bunny
|
|
9
|
+
# standard Ruby Queue
|
|
10
|
+
class Bunny < SimpleDelegator
|
|
11
|
+
extend Forwardable
|
|
12
|
+
|
|
8
13
|
def self.call(name:, **opts)
|
|
9
14
|
new(name, **opts)
|
|
10
15
|
end
|
|
11
16
|
|
|
12
|
-
def initialize(name,
|
|
17
|
+
def initialize(name, manual_ack: false, **opts)
|
|
18
|
+
super ::Queue.new
|
|
19
|
+
|
|
13
20
|
@name = name
|
|
14
|
-
@
|
|
15
|
-
@conn = conn
|
|
16
|
-
@queue = conn.queue(@name, **opts)
|
|
17
|
-
@messages = ::Queue.new
|
|
18
|
-
@queue.subscribe(manual_ack: manual_ack) { |*args| @messages << args }
|
|
19
|
-
end
|
|
21
|
+
@source_opts = opts
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
@queue.bind('amq.topic', routing_key: routing_key)
|
|
23
|
+
watch_source manual_ack
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def push(args)
|
|
26
27
|
routing_key, message = args
|
|
27
|
-
|
|
28
|
+
bind routing_key
|
|
29
|
+
exchange.publish message, routing_key: routing_key
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def pop
|
|
33
|
+
delivery_info, *tail = super
|
|
34
|
+
[delivery_info[:routing_key], delivery_info, *tail]
|
|
28
35
|
end
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def_delegator :'CottonTail.configuration', :connection_args
|
|
40
|
+
|
|
41
|
+
def bind(routing_key)
|
|
42
|
+
source.bind('amq.topic', routing_key: routing_key)
|
|
32
43
|
end
|
|
33
44
|
|
|
34
|
-
def
|
|
35
|
-
|
|
45
|
+
def watch_source(manual_ack)
|
|
46
|
+
source.subscribe(manual_ack: manual_ack) { |*args| self << args }
|
|
36
47
|
end
|
|
37
48
|
|
|
38
|
-
def
|
|
39
|
-
@
|
|
49
|
+
def connection
|
|
50
|
+
@connection ||= ::Bunny.new(*connection_args).start
|
|
40
51
|
end
|
|
41
52
|
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
def source
|
|
54
|
+
@source ||= channel.queue(@name, **@source_opts)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def channel
|
|
58
|
+
@channel ||= connection.create_channel
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def exchange
|
|
62
|
+
@exchange ||= channel.exchange('amq.topic')
|
|
45
63
|
end
|
|
46
64
|
end
|
|
47
65
|
end
|
data/lib/cotton_tail/version.rb
CHANGED
data/lib/cotton_tail.rb
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'bunny'
|
|
4
|
+
|
|
3
5
|
# Top level namespace for CottonTail
|
|
4
6
|
module CottonTail
|
|
5
7
|
autoload :App, 'cotton_tail/app'
|
|
8
|
+
autoload :Configuration, 'cotton_tail/configuration'
|
|
6
9
|
autoload :DSL, 'cotton_tail/dsl'
|
|
7
10
|
autoload :Queue, 'cotton_tail/queue'
|
|
8
11
|
autoload :Router, 'cotton_tail/router'
|
|
9
12
|
autoload :Version, 'cotton_tail/version'
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def configure
|
|
16
|
+
return configuration unless block_given?
|
|
17
|
+
|
|
18
|
+
yield configuration
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def configuration
|
|
22
|
+
@configuration ||= Configuration.new
|
|
23
|
+
end
|
|
24
|
+
end
|
|
10
25
|
end
|
data.tar.gz.sig
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
�
|
|
1
|
+
|*/B�eE��;#����AD��Y*��RnA�j����q��4yo�9Oc�*Aң.&�n��N�4��կ���Lo�����R���LW�Q�^���dq����J$�n��q�?B����Hk���
|
|
2
|
+
�4U�������+�]�m~j��H
|
metadata
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cotton-tail
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Brennan
|
|
8
8
|
autorequire:
|
|
9
|
-
bindir:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain:
|
|
11
11
|
- |
|
|
12
12
|
-----BEGIN CERTIFICATE-----
|
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
|
30
30
|
fXe/xr/Sc+2wCjHPVE2J+auN5hk3KCp1I4s2fKqyLIwyhTEF3shuYfCpC8rt/YdN
|
|
31
31
|
cy9/lg5LCI3OvakzxL4Xt1Sq4h/xJZ06ydTVJ1wxfk6BXHrg
|
|
32
32
|
-----END CERTIFICATE-----
|
|
33
|
-
date: 2018-11-
|
|
33
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
|
34
34
|
dependencies:
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
36
|
name: bunny
|
|
@@ -176,13 +176,13 @@ files:
|
|
|
176
176
|
- examples/messages/say.hello
|
|
177
177
|
- lib/cotton_tail.rb
|
|
178
178
|
- lib/cotton_tail/app.rb
|
|
179
|
+
- lib/cotton_tail/configuration.rb
|
|
179
180
|
- lib/cotton_tail/dsl.rb
|
|
180
181
|
- lib/cotton_tail/dsl/app.rb
|
|
181
182
|
- lib/cotton_tail/dsl/queue.rb
|
|
182
183
|
- lib/cotton_tail/dsl/topic.rb
|
|
183
184
|
- lib/cotton_tail/queue.rb
|
|
184
185
|
- lib/cotton_tail/queue/bunny.rb
|
|
185
|
-
- lib/cotton_tail/queue/connection.rb
|
|
186
186
|
- lib/cotton_tail/queue/memory.rb
|
|
187
187
|
- lib/cotton_tail/queue/reader.rb
|
|
188
188
|
- lib/cotton_tail/queue/supervisor.rb
|
metadata.gz.sig
CHANGED
|
Binary file
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'forwardable'
|
|
4
|
-
require 'bunny'
|
|
5
|
-
|
|
6
|
-
module CottonTail
|
|
7
|
-
module Queue
|
|
8
|
-
# Wrapper for Bunny::Session
|
|
9
|
-
class Connection
|
|
10
|
-
extend Forwardable
|
|
11
|
-
|
|
12
|
-
def initialize(url = ENV.fetch('AMQP_ADDRESS', 'amqp://localhost:5672'))
|
|
13
|
-
@url = url
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def chan(prefetch = 1)
|
|
17
|
-
@channels ||= Hash.new do |h, key|
|
|
18
|
-
h[key] = session.create_channel.tap do |ch|
|
|
19
|
-
ch.prefetch(prefetch)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
@channels[prefetch]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def exchange
|
|
26
|
-
@exchange ||= chan.exchange('amq.topic')
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def session
|
|
30
|
-
@session ||= ::Bunny.new(@url).tap(&:start)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def_delegators :chan, :ack, :nack, :queue
|
|
34
|
-
def_delegators :exchange, :publish
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|