DaemonKit with RabbitMQ and Rack

43 views
Skip to first unread message

Miguel Godoy

unread,
Jan 29, 2014, 3:51:40 PM1/29/14
to daemo...@googlegroups.com
I'm working on a Daemon with DaemonKit and RabbitMQ (AMQP), here is all ok... but I need to do that this daemon work with an API server.. then I do this with Rack gem, but when execute the code where up the Rack Server.. it stop all daemon and listen the port (No listen the Rabbit) I try with Thread and Fork and doesn't work... any idea ?

DaemonKit::Application.running! do |config|

end


class ApiServer
  def call(env)
    req = Rack::Request.new(env)
    [200, {"Content-Type" => "text/html"}, ["Hello Rack!"]]
  end
end

Rack::Handler::Mongrel.run ApiServer.new, :Port => 9292

# IMPORTANT CONFIGURATION NOTE
#
# Please review and update 'config/amqp.yml' accordingly or this
# daemon won't work as advertised.

# Run an event-loop for processing
DaemonKit::AMQP.run do |connection|
  # Inside this block we're running inside the reactor setup by the
  # amqp gem. Any code in the examples (from the gem) would work just
  # fine here.

  # Uncomment this for connection keep-alive
  # connection.on_tcp_connection_loss do |client, settings|
  #   DaemonKit.logger.debug("AMQP connection status changed: #{status}")
  #   client.reconnect(false, 1)
  # end

  amq = AMQP::Channel.new
  amq.queue('test').subscribe do |msg|
    DaemonKit.logger.debug "Received message: #{msg.inspect}"
  end



end

Kenneth Kalmer

unread,
Jan 29, 2014, 4:33:55 PM1/29/14
to daemon-kit
Hi Miguel

Thanks for the great question, I've wanted to do something like this since the very early days of daemon-kit, but initially thought I was mad.

I've got a working example for you, with one caveat, Ctrl+C doesn't stop the daemon :(


Please let me know how that goes! I'm sure Thin has some signal handler that might interfere.

Kind regards


--
You received this message because you are subscribed to the Google Groups "Daemon Kit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to daemon-kit+...@googlegroups.com.
To post to this group, send email to daemo...@googlegroups.com.
Visit this group at http://groups.google.com/group/daemon-kit.
For more options, visit https://groups.google.com/groups/opt_out.



--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za
@kennethkalmer
Reply all
Reply to author
Forward
0 new messages