开发者

Ruby SMPP with RabbitMQ and Eventmachine, problems after AMQP.stop

I have a little problem with rabbitmq which I don't understand. I am using:

  • Ruby Version 1.8.7
  • AMQP GEM Version 0.7.0
  • RabbitMQ v2.3.1
  • ruby-smpp v0.4.0

My code looks like this:

  loop do
    AMQP.start do
      EventMachine::run do             
        @@tx = EventMachine::connect(
          config[:host], 
          config[:port], 
          Smpp::Transceiver, 
          config, 
          self    # delegate that will receive callbacks on MOs and DRs and other events
        )
        EM.add_timer(10) do
          puts "AMQP New"
          amq = MQ.new
          amq.queue("#{provider}").subscribe(:ack => true) do |header, msg|
            puts "Provider #{provider} consumer #{Process.pid} processed #{msg}"
            header.ack
          end
        end
        EM.add_timer(30) {EventMachine::stop_event_loop}
      end
    end
    AMQP.stop
    puts "#{config[:host]} Disconnected. Reconnecting in 35 seconds.."
    sleep 35
  end

I added this line for testing. EM.add_timer(30) {EventMachine::stop_event_loop}

so after 30 sec. I stop the event loop, it sleeps 35 seconds and the restarts everything. The problem is that amq = MQ.new seems to do something and it doesn't give me an error, but the subscribe doesn't seem to work. Also no error. Only after stopping the process and starting it again it sub开发者_JAVA百科scribes again and processes messages. I don't understand why


AMQP.start does it's own EM magic - this might be what is biting you.

Here's an example on how to do AMQP inside an EM run (or so it seems)


You can try this simple library: https://github.com/sck-v/communications

Nothing except simple communications between two applications

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜