lib/msgr/client.rb in msgr-0.2.1 vs lib/msgr/client.rb in msgr-0.3.0

- old
+ new

@@ -17,13 +17,11 @@ @uri.host = config[:host] ||= @uri.host || '127.0.0.1' @uri.port = config[:port] ||= @uri.port @uri.path = config[:vhost] ||= @uri.path.present? ? @uri.path : '/' config.reject! { |_,v| v.nil? } - @config = config - @bunny = Bunny.new config - @pool = Pool.new Dispatcher, size: config[:size] + @config = config end def running?; @running end def log_name; self.class.name end @@ -49,14 +47,12 @@ end def start log(:info) { "Start client to #{uri}" } - @bunny.start - @pool.start - @running = true - new_connection + init + launch log(:info) { 'Client started.' } end def stop(opts = {}) @@ -106,8 +102,20 @@ log(:info) { "Attempting graceful shutdown within #{timeout} seconds..." } @pool.future(:stop).value timeout rescue TimeoutError log(:warn) { "Could not shutdown pool within #{timeout} seconds." } + end + + def init + @bunny = Bunny.new @config + @pool = Pool.new Dispatcher, size: @config[:size] + end + + def launch + @bunny.start + @pool.start + @running = true + new_connection end end end