cottontail 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cottontail.rb CHANGED
@@ -158,11 +158,15 @@ module Cottontail
158
158
 
159
159
  # Starts the consumer service and enters the subscribe loop.
160
160
  def run
161
+ logger.debug "[Cottontail] Connecting to client"
162
+ @client = Bunny.new( *settings(:client) )
163
+ @client.start
164
+
161
165
  logger.debug "[Cottontail] Declaring exchange"
162
- exchange = client.exchange( *settings(:exchange) )
166
+ exchange = @client.exchange( *settings(:exchange) )
163
167
 
164
168
  logger.debug "[Cottontail] Declaring queue"
165
- queue = client.queue( *settings(:queue) )
169
+ queue = @client.queue( *settings(:queue) )
166
170
 
167
171
  routes.keys.each do |key|
168
172
  logger.debug "[Cottontail] Binding #{key.inspect} to exchange"
@@ -223,6 +227,8 @@ module Cottontail
223
227
  # Reset the instance
224
228
  def reset!
225
229
  @client = nil
230
+
231
+ prepare_client_settings!
226
232
  end
227
233
 
228
234
  def subscribe!( queue )
@@ -231,19 +237,10 @@ module Cottontail
231
237
  queue.subscribe( options ) { |m| block.call(self, m) }
232
238
  end
233
239
 
234
- def client
235
- return @client if @client
236
-
237
- @client = Bunny.new( bunny_options )
238
- @client.start
239
-
240
- @client
241
- end
242
-
243
240
  # The bunny gem itself is not able to handle multiple hosts - although multiple RabbitMQ instances may run in parralel.
244
241
  #
245
- # You may pass :hosts as option whensettings the client in order to cycle through them when a connection was lost.
246
- def bunny_options
242
+ # You may pass :hosts as option when settings the client in order to cycle through them in case a connection was lost.
243
+ def prepare_client_settings!
247
244
  return {} unless options = settings(:client) and options = options.first
248
245
 
249
246
  if hosts = options[:hosts]
@@ -256,6 +253,7 @@ module Cottontail
256
253
  options
257
254
  end
258
255
 
256
+
259
257
  public
260
258
 
261
259
  # === Perform the initial setup
@@ -1,3 +1,3 @@
1
1
  module Cottontail
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rudolf Schmidt