ruby on rails - Consuming messages from RabbitMQ: [amqp] Detected TCP connection failure -
the following rails rake task works on rails development system. after deploying rails production environment fails.
rake pform_queue:receive rails_env=production stop ctrl+c waiting application forms ... [amqp] detected tcp connection failure
telnet shows rabbitmq listening on default port:
telnet localhost 5672 trying 127.0.0.1... connected localhost. escape character '^]'. rtyr fghtryr amqp connection closed foreign host.
below code of rake task.
desc "wait application forms pform" task :receive => :environment require "amqp" eventmachine.run connection = amqp.connect(:host => 'localhost') channel = amqp::channel.new(connection) queue = channel.queue("pform.applicationforms", :durable => true) puts "stop ctrl+c" puts "waiting application forms ..." queue.subscribe |payload| puts "#{time.now} received message" end end end
we use apache/passenger in production, thought of no consequence rake tasks.
amq-protocol (1.8.0) amqp (1.1.0) "rabbitmq","2.5.0"
i have upgraded to:
amq-protocol (1.9.2 amqp (1.3.0) "rabbitmq","3.2.4"
which has not solved problem
1026 pid of rabbitmq
netstat -plane | grep 1026 tcp 0 0 0.0.0.0:42325 0.0.0.0:* listen 107 6881 1026/beam.smp tcp 0 0 127.0.0.1:34438 127.0.0.1:4369 established 107 6883 1026/beam.smp tcp6 0 0 :::5672 :::* listen 107 6912 1026/beam.smp
logging details:
bundle exec rake pform_queue:receive rails_env=production [amqp] detected tcp connection failure failed connect {:host=>"127.0.0.1", :port=>5672, :user=>"guest", :pass=>"guest", :auth_mechanism=>"plain", :vhost=>"/", :timeout=>0.3, :logging=>false, :ssl=>false, :frame_max=>131072, :heartbeat=>0, :on_tcp_connection_failure=># <proc:0x00000005c3c968@/home/calm/wwwshare/registration/releases/20140310035559/lib/tasks /pform_receive_mq.rake:15>, :on_possible_authentication_failure=># <proc:0x00000005c3c940@/home/calm/wwwshare/registration/releases/20140310035559/lib/tasks/pform_receive_mq.rake:23>} /var/log/rabbitmq# tail -f rabbit@calm-integration.log =info report==== 10-mar-2014::08:56:32 === accepting amqp connection <0.2293.0> (127.0.0.1:56421 -> 127.0.0.1:5672) =info report==== 10-mar-2014::08:56:35 === accepting amqp connection <0.2304.0> (127.0.0.1:56422 -> 127.0.0.1:5672) =warning report==== 10-mar-2014::08:56:35 === closing amqp connection <0.2304.0> (127.0.0.1:56422 -> 127.0.0.1:5672): connection_closed_abruptly =warning report==== 10-mar-2014::08:56:35 === closing amqp connection <0.2293.0> (127.0.0.1:56421 -> 127.0.0.1:5672): connection_closed_abruptly
to repeat again: problem occurs on production system, not in development! quite stuck this.
in end have switched 'amqp' gem 'bunny' gem. bunny not depend on eventmachine. seems easier use, @ least working.
config/initializers/amqp.rb
# http://rubybunny.info/articles/connecting.html#connecting_in_web_applications_ruby_on_rails_sinatra_etc if defined?(phusionpassenger) # otherwise breaks rake commands if put in initializer phusionpassenger.on_event(:starting_worker_process) |forked| if forked # we’re in smart spawning mode # time connect rabbitmq $rabbitmq_connection = bunny.new $rabbitmq_connection.start $rabbitmq_channel = $rabbitmq_connection.create_channel end end else $rabbitmq_connection = bunny.new $rabbitmq_connection.start $rabbitmq_channel = $rabbitmq_connection.create_channel end
Comments
Post a Comment