How to get a scheduler and AMQP to work together properly in Ruby? -


what want start recurring process every hour publishes batch of messages rmq exchange on our server.

i have class, let's call rmqprocess, fires amqp event loop. thought use rufus-scheduler this:

scheduler.every '10s', :times=>6   process = rmqprocess.new   process.start end  scheduler.join 

this works...except each time through loop, amqp channel increases (from 2 4 6 etc...). think means channels not being closed properly, present problem.

i guess summarize question, proper (or @ least proper) way sort of thing? should amqp process fired before entering scheduler process or doing right way? have roll own scheduling logic inside amqp event loop? fear, because seems there must better way. advice appreciated.

for reference, here start method (in case i'm publishing nonsense sentences using randomtext gem):

def start     begin       puts @rmq_params       amqp.start(@rmq_params)          |connection|          connection.on_error           |ch, connection_close|           puts "#{connection_close.reply_text}"         end          connection.on_tcp_connection_loss           |conn, settings|           puts "[network failure] trying reconnect..."           conn.reconnect(false, 2)         end          channel = amqp::channel.new(connection, :auto_recovery => true)         puts "channel id = #{channel.id}"         exchange = channel.direct(@exchangename,:durable => true)         exchange.publish(lorem.words)          em.add_timer(@duration)             connection.close                 em.stop_event_loop             end         end           signal.trap("int")           connection.close             em.stop_event_loop           end         end        end     rescue exception => e       puts "#{e.message} #{e.backtrace.join("\n")}"     end end 

does

6.times   process = rmqprocess.new   process.start   sleep(10) end 

behave differently?

if i'd "start" amqp outside of rmqprocess#start , re-use resulting connection.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -