cottontail 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,13 +27,13 @@ require 'bunny'
27
27
  class Worker < Cottontail::Base
28
28
  # configure the Bunny client with the default connection (host: "localhost", port: 5672)
29
29
  # and with logging.
30
- set :client, { :logging => true }
30
+ client :logging => true
31
31
 
32
- # Declare default direct exchange which is bound to all queues of the type `topic`
33
- set :exchange, [ "", { :type => :topic } ]
32
+ # Declare `test` direct exchange which is bound to all queues of the type `topic`
33
+ exchange "test", :type => :topic
34
34
 
35
- # Declare the `test` queue
36
- set :queue, "test"
35
+ # Declare a durable `test` queue
36
+ queue "test", :durable => true
37
37
 
38
38
 
39
39
  # Consume messages on the routing key: `message.received`.Within the provided block
@@ -37,6 +37,21 @@ module Cottontail
37
37
  class << self
38
38
  attr_reader :routes
39
39
 
40
+ # Conveniently set the client
41
+ def client( *args, &block )
42
+ set :client, args, &block
43
+ end
44
+
45
+ # Conveniently set the exchange
46
+ def exchange( *args, &block )
47
+ set :exchange, args, &block
48
+ end
49
+
50
+ # Conveniently set the queue
51
+ def queue( *args, &block )
52
+ set :queue, args, &block
53
+ end
54
+
40
55
  # Set runtime configuration
41
56
  #
42
57
  # @example
@@ -134,9 +149,9 @@ module Cottontail
134
149
  set :subscribe, [{}, proc { |m| route! m }]
135
150
 
136
151
  # default bunny options
137
- set :client, {}
138
- set :exchange, ["default", {:type => :topic}]
139
- set :queue, "default"
152
+ client
153
+ exchange "default"
154
+ queue "default"
140
155
  end
141
156
 
142
157
 
@@ -166,18 +181,18 @@ module Cottontail
166
181
  # Starts the consumer service and enters the subscribe loop.
167
182
  def run
168
183
  # establish connection and bind routing keys
169
- logger.debug "[Cottontail] Connecting to client"
170
- @client = Bunny.new( settings(:client) )
184
+ logger.debug "[Cottontail] Connecting to client: #{settings(:client).inspect}"
185
+ @client = Bunny.new( *settings(:client) )
171
186
  @client.start
172
187
 
173
- logger.debug "[Cottontail] Declaring exchange"
188
+ logger.debug "[Cottontail] Declaring exchange: #{settings(:exchange).inspect}"
174
189
  exchange = @client.exchange( *settings(:exchange) )
175
190
 
176
- logger.debug "[Cottontail] Declaring queue"
177
- queue = @client.queue( settings(:queue) )
191
+ logger.debug "[Cottontail] Declaring queue: #{settings(:queue).inspect}"
192
+ queue = @client.queue( *settings(:queue) )
178
193
 
179
194
  routes.keys.each do |key|
180
- logger.debug "[Cottontail] Binding #{key.inspect} to exchange"
195
+ logger.debug "[Cottontail] Binding #{key.inspect}"
181
196
  queue.bind( exchange, :key => key )
182
197
  end
183
198
 
@@ -261,7 +276,7 @@ module Cottontail
261
276
  #
262
277
  # You may pass :hosts as option when settings the client in order to cycle through them in case a connection was lost.
263
278
  def prepare_client_settings!
264
- return {} unless options = settings(:client)
279
+ return {} unless options = settings(:client).first
265
280
 
266
281
  if hosts = options[:hosts]
267
282
  host, port = hosts.shift
@@ -1,3 +1,3 @@
1
1
  module Cottontail
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cottontail
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rudolf Schmidt
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-06 00:00:00 Z
13
+ date: 2012-03-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bunny