title: Consuming messages from RabbitMQ: [amqp] Detected TCP connection failure
body: <p>The following Rails rake task works on my Rails development system. But after deploying to
  the Rails production environment it fails.</p>
  
  <pre><code>rake pform_queue:receive RAILS_ENV=production
  Stop with Ctrl+c
  Waiting for application forms ...
  [amqp] Detected TCP connection failure
  </code></pre>
  
  <p>Telnet shows that RabbitMQ is listening on the default port:</p>
  
  <pre><code>telnet localhost 5672
  Trying 127.0.0.1...
  Connected to localhost.
  Escape character is '^]'.
  rtyr
  fghtryr
  AMQP    Connection closed by foreign host.
  </code></pre>
  
  <p>Below the code of the rake task.</p>
  
  <pre><code> desc "Wait for application forms from pform"
    task :receive  =&gt; :environment do
      require "amqp"
  
      EventMachine.run do
        connection = AMQP.connect(:host =&gt; 'localhost')
        channel  = AMQP::Channel.new(connection)
        queue    = channel.queue("pform.applicationforms", :durable =&gt; true)
  
        puts "Stop with Ctrl+c"
        puts "Waiting for application forms ..."
  
        queue.subscribe do |payload|
          puts "#{Time.now} Received a message"
        end
      end
    end
  </code></pre>
  
  <p>We use apache/passenger in production, but I thought that this is of no consequence for rake tasks.</p>
  
  <pre><code>amq-protocol (1.8.0)
  amqp (1.1.0)
  "RabbitMQ","2.5.0"
  </code></pre>
  
  <p>I have now upgraded to:</p>
  
  <pre><code>amq-protocol (1.9.2
  amqp (1.3.0)
  "RabbitMQ","3.2.4"
  </code></pre>
  
  <p>which has not solved my problem</p>
  
  <p>1026 is the pid of RabbitMQ</p>
  
  <pre><code>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  
  </code></pre>
  
  <p>Logging details:</p>
  
  <pre><code>bundle exec rake pform_queue:receive RAILS_ENV=production
  [amqp] Detected TCP connection failure
  Failed to connect {:host=&gt;"127.0.0.1", :port=&gt;5672, :user=&gt;"guest", :pass=&gt;"guest",   :auth_mechanism=&gt;"PLAIN", :vhost=&gt;"/", :timeout=&gt;0.3, :logging=&gt;false, :ssl=&gt;false, :frame_max=&gt;131072, :heartbeat=&gt;0, :on_tcp_connection_failure=&gt;# &lt;Proc:0x00000005c3c968@/home/calm/wwwshare/registration/releases/20140310035559/lib/tasks /pform_receive_mq.rake:15&gt;, :on_possible_authentication_failure=&gt;# &lt;Proc:0x00000005c3c940@/home/calm/wwwshare/registration/releases/20140310035559/lib/tasks/pform_receive_mq.rake:23&gt;}
  
  
  /var/log/rabbitmq# tail -f rabbit@Calm-Integration.log
  =INFO REPORT==== 10-Mar-2014::08:56:32 ===
  accepting AMQP connection &lt;0.2293.0&gt; (127.0.0.1:56421 -&gt; 127.0.0.1:5672)
  
  =INFO REPORT==== 10-Mar-2014::08:56:35 ===
  accepting AMQP connection &lt;0.2304.0&gt; (127.0.0.1:56422 -&gt; 127.0.0.1:5672)
  
  =WARNING REPORT==== 10-Mar-2014::08:56:35 ===
  closing AMQP connection &lt;0.2304.0&gt; (127.0.0.1:56422 -&gt; 127.0.0.1:5672):
  connection_closed_abruptly
  
  =WARNING REPORT==== 10-Mar-2014::08:56:35 ===
  closing AMQP connection &lt;0.2293.0&gt; (127.0.0.1:56421 -&gt; 127.0.0.1:5672):
  connection_closed_abruptly
  </code></pre>
  
  <p>To repeat again: The problem occurs only on the production system, not in development!
  I am quite stuck with this.</p>