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 +11 -13
- data/lib/cottontail/version.rb +1 -1
- metadata +1 -1
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
|
166
|
+
exchange = @client.exchange( *settings(:exchange) )
|
163
167
|
|
164
168
|
logger.debug "[Cottontail] Declaring queue"
|
165
|
-
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
|
246
|
-
def
|
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
|
data/lib/cottontail/version.rb
CHANGED