cotton-tail 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c184ea6b32368cff0639ab825a050dc42e3f8f88d0f56a66d2196deb0585ff0
4
- data.tar.gz: e92242ed3918475fbd3de0b15a05978b5c5f3eefe31f8661b51bfc8c70271193
3
+ metadata.gz: b08350ef7f0bcfc64c8c78ce7728a137c2d66a67b72052493c4946680f40178a
4
+ data.tar.gz: 32fab7c085c98cc66bbabedfcc23d9e574a7f4c5097c733813b73d30a26866c0
5
5
  SHA512:
6
- metadata.gz: 59773b7a58f66520f4ce9214e19e9f6ac2ba68cec669b589d77c4c1731bc6fe528bbfab62adf8eed3ef74b64dff9e829747bfbd35da511d5bf605b6e082d0d2e
7
- data.tar.gz: 4836be3bef0422446e297b24c7c6643aeeb0e979995b5a06609f7e28b01ff0cc67b51b4fbf65e6b94559d8f379630f8f6ae01b2eed8518903f8103bd9bcc2252
6
+ metadata.gz: eb8aabeeb45a3c4d81a177808cfb05dea3e248edc6308ccbf19acb8e380b750144f36884931cd1c0ac67b0581353d708f23957f390db748926e868602c7393e3
7
+ data.tar.gz: 037abfc33e2530440cca0456e92123daf2d26f4d0ddf0f7f30659a8d61d5203e9b7b97230a52488c59864f3d0cfe653cafa8c794c3df45bbd3fae8367fbd6a67
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cotton-tail (0.1.2)
4
+ cotton-tail (0.2.0)
5
5
  bunny (~> 2.12)
6
6
 
7
7
  GEM
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
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  f.match(%r{^(test|spec|features|integration)/})
25
25
  end
26
26
 
27
- spec.bindir = 'exe'
27
+ spec.bindir = 'bin'
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
@@ -35,7 +35,7 @@ module CottonTail
35
35
  supervisors.map(&:start)
36
36
  puts 'Waiting for messages ...'
37
37
 
38
- sleep 0.005 while running?
38
+ sleep 0.01 while running?
39
39
  end
40
40
 
41
41
  private
@@ -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::Queue
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, conn: Connection.new, prefetch: 1, manual_ack: false, **opts)
17
+ def initialize(name, manual_ack: false, **opts)
18
+ super ::Queue.new
19
+
13
20
  @name = name
14
- @prefetch = prefetch
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
- def bind(routing_key)
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
- @conn.publish message, routing_key: routing_key
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
- def close
31
- @messages.close
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 closed?
35
- @messages.closed?
45
+ def watch_source(manual_ack)
46
+ source.subscribe(manual_ack: manual_ack) { |*args| self << args }
36
47
  end
37
48
 
38
- def empty?
39
- @messages.empty?
49
+ def connection
50
+ @connection ||= ::Bunny.new(*connection_args).start
40
51
  end
41
52
 
42
- def pop
43
- delivery_info, *tail = @messages.pop
44
- [delivery_info[:routing_key], delivery_info, *tail, conn: @conn]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CottonTail
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
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
- �`�HI���pK�2���B�}��Q]�AZLL����a��:e�҃ڛ��� ��;"8d�$�e0��\Gvv
2
- (bG��׏c�"��:my7�#��K��#v+��nZ�ԛ�O6�F��{RXc��8�iz*�W ��8���j��!�C�l�8h��%��M�g6�y���ʯ�Q��|���
1
+ |*/B�eE��;#����AD��Y*��RnAj����q��4yo9Oc�*Aң. &�n��N4��կ���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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Brennan
8
8
  autorequire:
9
- bindir: exe
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-15 00:00:00.000000000 Z
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